@@ -51,22 +51,20 @@ static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
51
51
52
52
static int imx8mq_soc_revision (u32 * socrev , u64 * socuid )
53
53
{
54
- struct device_node * np ;
54
+ struct device_node * np __free (device_node ) =
55
+ of_find_compatible_node (NULL , NULL , "fsl,imx8mq-ocotp" );
55
56
void __iomem * ocotp_base ;
56
57
u32 magic ;
57
58
u32 rev ;
58
59
struct clk * clk ;
59
60
int ret ;
60
61
61
- np = of_find_compatible_node (NULL , NULL , "fsl,imx8mq-ocotp" );
62
62
if (!np )
63
63
return - EINVAL ;
64
64
65
65
ocotp_base = of_iomap (np , 0 );
66
- if (!ocotp_base ) {
67
- ret = - EINVAL ;
68
- goto err_iomap ;
69
- }
66
+ if (!ocotp_base )
67
+ return - EINVAL ;
70
68
71
69
clk = of_clk_get_by_name (np , NULL );
72
70
if (IS_ERR (clk )) {
@@ -96,35 +94,30 @@ static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
96
94
clk_disable_unprepare (clk );
97
95
clk_put (clk );
98
96
iounmap (ocotp_base );
99
- of_node_put (np );
100
97
101
98
return 0 ;
102
99
103
100
err_clk :
104
101
iounmap (ocotp_base );
105
- err_iomap :
106
- of_node_put (np );
107
102
return ret ;
108
103
}
109
104
110
105
static int imx8mm_soc_uid (u64 * socuid )
111
106
{
107
+ struct device_node * np __free (device_node ) =
108
+ of_find_compatible_node (NULL , NULL , "fsl,imx8mm-ocotp" );
112
109
void __iomem * ocotp_base ;
113
- struct device_node * np ;
114
110
struct clk * clk ;
115
111
int ret = 0 ;
116
112
u32 offset = of_machine_is_compatible ("fsl,imx8mp" ) ?
117
113
IMX8MP_OCOTP_UID_OFFSET : 0 ;
118
114
119
- np = of_find_compatible_node (NULL , NULL , "fsl,imx8mm-ocotp" );
120
115
if (!np )
121
116
return - EINVAL ;
122
117
123
118
ocotp_base = of_iomap (np , 0 );
124
- if (!ocotp_base ) {
125
- ret = - EINVAL ;
126
- goto err_iomap ;
127
- }
119
+ if (!ocotp_base )
120
+ return - EINVAL ;
128
121
129
122
clk = of_clk_get_by_name (np , NULL );
130
123
if (IS_ERR (clk )) {
@@ -143,38 +136,27 @@ static int imx8mm_soc_uid(u64 *socuid)
143
136
144
137
err_clk :
145
138
iounmap (ocotp_base );
146
- err_iomap :
147
- of_node_put (np );
148
-
149
139
return ret ;
150
140
}
151
141
152
142
static int imx8mm_soc_revision (u32 * socrev , u64 * socuid )
153
143
{
154
- struct device_node * np ;
144
+ struct device_node * np __free (device_node ) =
145
+ of_find_compatible_node (NULL , NULL , "fsl,imx8mm-anatop" );
155
146
void __iomem * anatop_base ;
156
- int ret ;
157
147
158
- np = of_find_compatible_node (NULL , NULL , "fsl,imx8mm-anatop" );
159
148
if (!np )
160
149
return - EINVAL ;
161
150
162
151
anatop_base = of_iomap (np , 0 );
163
- if (!anatop_base ) {
164
- ret = - EINVAL ;
165
- goto err_iomap ;
166
- }
152
+ if (!anatop_base )
153
+ return - EINVAL ;
167
154
168
155
* socrev = readl_relaxed (anatop_base + ANADIG_DIGPROG_IMX8MM );
169
156
170
157
iounmap (anatop_base );
171
- of_node_put (np );
172
158
173
159
return imx8mm_soc_uid (socuid );
174
-
175
- err_iomap :
176
- of_node_put (np );
177
- return ret ;
178
160
}
179
161
180
162
static const struct imx8_soc_data imx8mq_soc_data = {
@@ -205,64 +187,57 @@ static __maybe_unused const struct of_device_id imx8_soc_match[] = {
205
187
{ }
206
188
};
207
189
208
- #define imx8_revision (soc_rev ) \
209
- soc_rev ? \
210
- kasprintf( GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \
190
+ #define imx8_revision (dev , soc_rev ) \
191
+ ( soc_rev) ? \
192
+ devm_kasprintf((dev), GFP_KERNEL, "%d.%d", (( soc_rev) >> 4) & 0xf, ( soc_rev) & 0xf) : \
211
193
"unknown"
212
194
213
195
static int imx8m_soc_probe (struct platform_device * pdev )
214
196
{
215
197
struct soc_device_attribute * soc_dev_attr ;
216
198
const struct imx8_soc_data * data ;
199
+ struct device * dev = & pdev -> dev ;
217
200
const struct of_device_id * id ;
218
201
struct soc_device * soc_dev ;
219
202
u32 soc_rev = 0 ;
220
203
u64 soc_uid = 0 ;
221
204
int ret ;
222
205
223
- soc_dev_attr = kzalloc ( sizeof (* soc_dev_attr ), GFP_KERNEL );
206
+ soc_dev_attr = devm_kzalloc ( dev , sizeof (* soc_dev_attr ), GFP_KERNEL );
224
207
if (!soc_dev_attr )
225
208
return - ENOMEM ;
226
209
227
210
soc_dev_attr -> family = "Freescale i.MX" ;
228
211
229
212
ret = of_property_read_string (of_root , "model" , & soc_dev_attr -> machine );
230
213
if (ret )
231
- goto free_soc ;
214
+ return ret ;
232
215
233
216
id = of_match_node (imx8_soc_match , of_root );
234
- if (!id ) {
235
- ret = - ENODEV ;
236
- goto free_soc ;
237
- }
217
+ if (!id )
218
+ return - ENODEV ;
238
219
239
220
data = id -> data ;
240
221
if (data ) {
241
222
soc_dev_attr -> soc_id = data -> name ;
242
223
if (data -> soc_revision ) {
243
224
ret = data -> soc_revision (& soc_rev , & soc_uid );
244
225
if (ret )
245
- goto free_soc ;
226
+ return ret ;
246
227
}
247
228
}
248
229
249
- soc_dev_attr -> revision = imx8_revision (soc_rev );
250
- if (!soc_dev_attr -> revision ) {
251
- ret = - ENOMEM ;
252
- goto free_soc ;
253
- }
230
+ soc_dev_attr -> revision = imx8_revision (dev , soc_rev );
231
+ if (!soc_dev_attr -> revision )
232
+ return - ENOMEM ;
254
233
255
- soc_dev_attr -> serial_number = kasprintf (GFP_KERNEL , "%016llX" , soc_uid );
256
- if (!soc_dev_attr -> serial_number ) {
257
- ret = - ENOMEM ;
258
- goto free_rev ;
259
- }
234
+ soc_dev_attr -> serial_number = devm_kasprintf (dev , GFP_KERNEL , "%016llX" , soc_uid );
235
+ if (!soc_dev_attr -> serial_number )
236
+ return - ENOMEM ;
260
237
261
238
soc_dev = soc_device_register (soc_dev_attr );
262
- if (IS_ERR (soc_dev )) {
263
- ret = PTR_ERR (soc_dev );
264
- goto free_serial_number ;
265
- }
239
+ if (IS_ERR (soc_dev ))
240
+ return PTR_ERR (soc_dev );
266
241
267
242
pr_info ("SoC: %s revision %s\n" , soc_dev_attr -> soc_id ,
268
243
soc_dev_attr -> revision );
@@ -271,15 +246,6 @@ static int imx8m_soc_probe(struct platform_device *pdev)
271
246
platform_device_register_simple ("imx-cpufreq-dt" , -1 , NULL , 0 );
272
247
273
248
return 0 ;
274
-
275
- free_serial_number :
276
- kfree (soc_dev_attr -> serial_number );
277
- free_rev :
278
- if (strcmp (soc_dev_attr -> revision , "unknown" ))
279
- kfree (soc_dev_attr -> revision );
280
- free_soc :
281
- kfree (soc_dev_attr );
282
- return ret ;
283
249
}
284
250
285
251
static struct platform_driver imx8m_soc_driver = {
0 commit comments