Skip to content

Commit 22b03a4

Browse files
Marek VasutShawn Guo
authored andcommitted
soc: imx8m: Use devm_* to simplify probe failure handling
Use device managed functions to simplify handling of failures during probe. Remove fail paths which are no longer necessary. Signed-off-by: Marek Vasut <[email protected]> Signed-off-by: Shawn Guo <[email protected]>
1 parent 9c1c02f commit 22b03a4

File tree

1 file changed

+29
-63
lines changed

1 file changed

+29
-63
lines changed

drivers/soc/imx/soc-imx8m.c

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,20 @@ static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
5151

5252
static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
5353
{
54-
struct device_node *np;
54+
struct device_node *np __free(device_node) =
55+
of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
5556
void __iomem *ocotp_base;
5657
u32 magic;
5758
u32 rev;
5859
struct clk *clk;
5960
int ret;
6061

61-
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
6262
if (!np)
6363
return -EINVAL;
6464

6565
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;
7068

7169
clk = of_clk_get_by_name(np, NULL);
7270
if (IS_ERR(clk)) {
@@ -96,35 +94,30 @@ static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
9694
clk_disable_unprepare(clk);
9795
clk_put(clk);
9896
iounmap(ocotp_base);
99-
of_node_put(np);
10097

10198
return 0;
10299

103100
err_clk:
104101
iounmap(ocotp_base);
105-
err_iomap:
106-
of_node_put(np);
107102
return ret;
108103
}
109104

110105
static int imx8mm_soc_uid(u64 *socuid)
111106
{
107+
struct device_node *np __free(device_node) =
108+
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
112109
void __iomem *ocotp_base;
113-
struct device_node *np;
114110
struct clk *clk;
115111
int ret = 0;
116112
u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
117113
IMX8MP_OCOTP_UID_OFFSET : 0;
118114

119-
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
120115
if (!np)
121116
return -EINVAL;
122117

123118
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;
128121

129122
clk = of_clk_get_by_name(np, NULL);
130123
if (IS_ERR(clk)) {
@@ -143,38 +136,27 @@ static int imx8mm_soc_uid(u64 *socuid)
143136

144137
err_clk:
145138
iounmap(ocotp_base);
146-
err_iomap:
147-
of_node_put(np);
148-
149139
return ret;
150140
}
151141

152142
static int imx8mm_soc_revision(u32 *socrev, u64 *socuid)
153143
{
154-
struct device_node *np;
144+
struct device_node *np __free(device_node) =
145+
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
155146
void __iomem *anatop_base;
156-
int ret;
157147

158-
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
159148
if (!np)
160149
return -EINVAL;
161150

162151
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;
167154

168155
*socrev = readl_relaxed(anatop_base + ANADIG_DIGPROG_IMX8MM);
169156

170157
iounmap(anatop_base);
171-
of_node_put(np);
172158

173159
return imx8mm_soc_uid(socuid);
174-
175-
err_iomap:
176-
of_node_put(np);
177-
return ret;
178160
}
179161

180162
static const struct imx8_soc_data imx8mq_soc_data = {
@@ -205,64 +187,57 @@ static __maybe_unused const struct of_device_id imx8_soc_match[] = {
205187
{ }
206188
};
207189

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) : \
211193
"unknown"
212194

213195
static int imx8m_soc_probe(struct platform_device *pdev)
214196
{
215197
struct soc_device_attribute *soc_dev_attr;
216198
const struct imx8_soc_data *data;
199+
struct device *dev = &pdev->dev;
217200
const struct of_device_id *id;
218201
struct soc_device *soc_dev;
219202
u32 soc_rev = 0;
220203
u64 soc_uid = 0;
221204
int ret;
222205

223-
soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
206+
soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), GFP_KERNEL);
224207
if (!soc_dev_attr)
225208
return -ENOMEM;
226209

227210
soc_dev_attr->family = "Freescale i.MX";
228211

229212
ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
230213
if (ret)
231-
goto free_soc;
214+
return ret;
232215

233216
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;
238219

239220
data = id->data;
240221
if (data) {
241222
soc_dev_attr->soc_id = data->name;
242223
if (data->soc_revision) {
243224
ret = data->soc_revision(&soc_rev, &soc_uid);
244225
if (ret)
245-
goto free_soc;
226+
return ret;
246227
}
247228
}
248229

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;
254233

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;
260237

261238
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);
266241

267242
pr_info("SoC: %s revision %s\n", soc_dev_attr->soc_id,
268243
soc_dev_attr->revision);
@@ -271,15 +246,6 @@ static int imx8m_soc_probe(struct platform_device *pdev)
271246
platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
272247

273248
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;
283249
}
284250

285251
static struct platform_driver imx8m_soc_driver = {

0 commit comments

Comments
 (0)