Skip to content

Commit ab382a6

Browse files
MrVanShawn Guo
authored andcommitted
soc: imx: Use device-managed APIs for i.MX9
Use device-managed APi to simplify code. Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Shawn Guo <shawnguo@kernel.org>
1 parent 80a4062 commit ab382a6

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

drivers/soc/imx/soc-imx9.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@
1818

1919
static int imx9_soc_probe(struct platform_device *pdev)
2020
{
21+
struct device *dev = &pdev->dev;
2122
struct soc_device_attribute *attr;
2223
struct arm_smccc_res res;
2324
struct soc_device *sdev;
2425
u32 soc_id, rev_major, rev_minor;
2526
u64 uid127_64, uid63_0;
2627
int err;
2728

28-
attr = kzalloc(sizeof(*attr), GFP_KERNEL);
29+
attr = devm_kzalloc(dev, sizeof(*attr), GFP_KERNEL);
2930
if (!attr)
3031
return -ENOMEM;
3132

3233
err = of_property_read_string(of_root, "model", &attr->machine);
3334
if (err) {
3435
pr_err("%s: missing model property: %d\n", __func__, err);
35-
goto attr;
36+
return err;
3637
}
3738

38-
attr->family = kasprintf(GFP_KERNEL, "Freescale i.MX");
39+
attr->family = devm_kasprintf(dev, GFP_KERNEL, "Freescale i.MX");
3940

4041
/*
4142
* Retrieve the soc id, rev & uid info:
@@ -47,39 +48,28 @@ static int imx9_soc_probe(struct platform_device *pdev)
4748
arm_smccc_smc(IMX_SIP_GET_SOC_INFO, 0, 0, 0, 0, 0, 0, 0, &res);
4849
if (res.a0 != SMCCC_RET_SUCCESS) {
4950
pr_err("%s: SMC failed: 0x%lx\n", __func__, res.a0);
50-
err = -EINVAL;
51-
goto family;
51+
return -EINVAL;
5252
}
5353

5454
soc_id = SOC_ID(res.a1);
5555
rev_major = SOC_REV_MAJOR(res.a1);
5656
rev_minor = SOC_REV_MINOR(res.a1);
5757

58-
attr->soc_id = kasprintf(GFP_KERNEL, "i.MX%2x", soc_id);
59-
attr->revision = kasprintf(GFP_KERNEL, "%d.%d", rev_major, rev_minor);
58+
attr->soc_id = devm_kasprintf(dev, GFP_KERNEL, "i.MX%2x", soc_id);
59+
attr->revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d", rev_major, rev_minor);
6060

6161
uid127_64 = res.a2;
6262
uid63_0 = res.a3;
63-
attr->serial_number = kasprintf(GFP_KERNEL, "%016llx%016llx", uid127_64, uid63_0);
63+
attr->serial_number = devm_kasprintf(dev, GFP_KERNEL, "%016llx%016llx", uid127_64, uid63_0);
6464

6565
sdev = soc_device_register(attr);
6666
if (IS_ERR(sdev)) {
6767
err = PTR_ERR(sdev);
6868
pr_err("%s failed to register SoC as a device: %d\n", __func__, err);
69-
goto serial_number;
69+
return err;
7070
}
7171

7272
return 0;
73-
74-
serial_number:
75-
kfree(attr->serial_number);
76-
kfree(attr->revision);
77-
kfree(attr->soc_id);
78-
family:
79-
kfree(attr->family);
80-
attr:
81-
kfree(attr);
82-
return err;
8373
}
8474

8575
static __maybe_unused const struct of_device_id imx9_soc_match[] = {

0 commit comments

Comments
 (0)