[v3] soc: ti: Convert allocations to devm
Commit Message
Changed the memory and resource allocations in the probe function
to devm. Also added a remove callback.
Signed-off-by: Nicolas Frayer <nfrayer@baylibre.com>
---
v2->v3:
dropped module conversion part of this series while other driver dependencies
on socinfo are worked out.
A dependency issue is introduced by changing subsys_initcall()
to module_platform_driver(). Some drivers using the socinfo information probe
before the socinfo driver itself and it makes their probe fail.
Dropped series:
https://lore.kernel.org/all/20221010131538.7333-1-nfrayer@baylibre.com/
drivers/soc/ti/k3-socinfo.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
Comments
On 20:00-20221028, Nicolas Frayer wrote:
Quick cosmetics:
linux-arm-kernel@lists.infradead.org (moderated list:TI KEYSTONE MULTICORE NAVIGATOR DRIVERS)
is part of the results of get_maintainers.pl why drop not CC it?
git log --oneline drivers/soc/ti/k3-socinfo.c
soc: ti: k3-socinfo:
Please fix the $subject
> Changed the memory and resource allocations in the probe function
> to devm. Also added a remove callback.
Yes, but why are we doing this change, what benefit do we get by doing
this change?
>
> Signed-off-by: Nicolas Frayer <nfrayer@baylibre.com>
> ---
>
> v2->v3:
> dropped module conversion part of this series while other driver dependencies
> on socinfo are worked out.
> A dependency issue is introduced by changing subsys_initcall()
> to module_platform_driver(). Some drivers using the socinfo information probe
> before the socinfo driver itself and it makes their probe fail.
>
> Dropped series:
> https://lore.kernel.org/all/20221010131538.7333-1-nfrayer@baylibre.com/
OK - if we are'nt going to convert this into modules, then is there a
reason for this patch?
>
> drivers/soc/ti/k3-socinfo.c | 36 +++++++++++++++++++-----------------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/soc/ti/k3-socinfo.c b/drivers/soc/ti/k3-socinfo.c
> index 91f441ee6175..19f3e74f5376 100644
> --- a/drivers/soc/ti/k3-socinfo.c
> +++ b/drivers/soc/ti/k3-socinfo.c
> @@ -96,21 +96,18 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
> partno_id = (jtag_id & CTRLMMR_WKUP_JTAGID_PARTNO_MASK) >>
> CTRLMMR_WKUP_JTAGID_PARTNO_SHIFT;
>
> - soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
> + soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), GFP_KERNEL);
> if (!soc_dev_attr)
> return -ENOMEM;
>
> - soc_dev_attr->revision = kasprintf(GFP_KERNEL, "SR%x.0", variant);
> - if (!soc_dev_attr->revision) {
> - ret = -ENOMEM;
> - goto err;
> - }
> + soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "SR%x.0", variant);
> + if (!soc_dev_attr->revision)
> + return -ENOMEM;
>
> ret = k3_chipinfo_partno_to_names(partno_id, soc_dev_attr);
> if (ret) {
> dev_err(dev, "Unknown SoC JTAGID[0x%08X]\n", jtag_id);
> - ret = -ENODEV;
> - goto err_free_rev;
> + return -ENODEV;
> }
>
> node = of_find_node_by_path("/");
> @@ -118,22 +115,26 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
> of_node_put(node);
>
> soc_dev = soc_device_register(soc_dev_attr);
> - if (IS_ERR(soc_dev)) {
> - ret = PTR_ERR(soc_dev);
> - goto err_free_rev;
> - }
> + if (IS_ERR(soc_dev))
> + return PTR_ERR(soc_dev);
> +
> + platform_set_drvdata(pdev, soc_dev);
>
> dev_info(dev, "Family:%s rev:%s JTAGID[0x%08x] Detected\n",
> soc_dev_attr->family,
> soc_dev_attr->revision, jtag_id);
>
> return 0;
> +}
> +
> +static int k3_chipinfo_remove(struct platform_device *pdev)
> +{
> + struct soc_device *soc_dev = platform_get_drvdata(pdev);
>
> -err_free_rev:
> - kfree(soc_dev_attr->revision);
> -err:
> - kfree(soc_dev_attr);
> - return ret;
> + if (soc_dev)
> + soc_device_unregister(soc_dev);
> +
> + return 0;
> }
>
> static const struct of_device_id k3_chipinfo_of_match[] = {
> @@ -147,6 +148,7 @@ static struct platform_driver k3_chipinfo_driver = {
> .of_match_table = k3_chipinfo_of_match,
> },
> .probe = k3_chipinfo_probe,
> + .remove = k3_chipinfo_remove,
> };
>
> static int __init k3_chipinfo_init(void)
> --
> 2.25.1
>
Nishanth Menon <nm@ti.com> writes:
> On 20:00-20221028, Nicolas Frayer wrote:
>
> Quick cosmetics:
> linux-arm-kernel@lists.infradead.org (moderated list:TI KEYSTONE MULTICORE NAVIGATOR DRIVERS)
> is part of the results of get_maintainers.pl why drop not CC it?
>
> git log --oneline drivers/soc/ti/k3-socinfo.c
> soc: ti: k3-socinfo:
>
> Please fix the $subject
>
>> Changed the memory and resource allocations in the probe function
>> to devm. Also added a remove callback.
>
> Yes, but why are we doing this change, what benefit do we get by doing
> this change?
>
>
>>
>> Signed-off-by: Nicolas Frayer <nfrayer@baylibre.com>
>> ---
>>
>> v2->v3:
>> dropped module conversion part of this series while other driver dependencies
>> on socinfo are worked out.
>> A dependency issue is introduced by changing subsys_initcall()
>> to module_platform_driver(). Some drivers using the socinfo information probe
>> before the socinfo driver itself and it makes their probe fail.
>>
>> Dropped series:
>> https://lore.kernel.org/all/20221010131538.7333-1-nfrayer@baylibre.com/
>
> OK - if we are'nt going to convert this into modules, then is there a
> reason for this patch?
Yeah, Nishanth has a good point here. Lets wait on this patch an
included it with the module conversion once we figure out the deferred
probe issues around this.
Kevin
@@ -96,21 +96,18 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
partno_id = (jtag_id & CTRLMMR_WKUP_JTAGID_PARTNO_MASK) >>
CTRLMMR_WKUP_JTAGID_PARTNO_SHIFT;
- soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+ soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr), GFP_KERNEL);
if (!soc_dev_attr)
return -ENOMEM;
- soc_dev_attr->revision = kasprintf(GFP_KERNEL, "SR%x.0", variant);
- if (!soc_dev_attr->revision) {
- ret = -ENOMEM;
- goto err;
- }
+ soc_dev_attr->revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "SR%x.0", variant);
+ if (!soc_dev_attr->revision)
+ return -ENOMEM;
ret = k3_chipinfo_partno_to_names(partno_id, soc_dev_attr);
if (ret) {
dev_err(dev, "Unknown SoC JTAGID[0x%08X]\n", jtag_id);
- ret = -ENODEV;
- goto err_free_rev;
+ return -ENODEV;
}
node = of_find_node_by_path("/");
@@ -118,22 +115,26 @@ static int k3_chipinfo_probe(struct platform_device *pdev)
of_node_put(node);
soc_dev = soc_device_register(soc_dev_attr);
- if (IS_ERR(soc_dev)) {
- ret = PTR_ERR(soc_dev);
- goto err_free_rev;
- }
+ if (IS_ERR(soc_dev))
+ return PTR_ERR(soc_dev);
+
+ platform_set_drvdata(pdev, soc_dev);
dev_info(dev, "Family:%s rev:%s JTAGID[0x%08x] Detected\n",
soc_dev_attr->family,
soc_dev_attr->revision, jtag_id);
return 0;
+}
+
+static int k3_chipinfo_remove(struct platform_device *pdev)
+{
+ struct soc_device *soc_dev = platform_get_drvdata(pdev);
-err_free_rev:
- kfree(soc_dev_attr->revision);
-err:
- kfree(soc_dev_attr);
- return ret;
+ if (soc_dev)
+ soc_device_unregister(soc_dev);
+
+ return 0;
}
static const struct of_device_id k3_chipinfo_of_match[] = {
@@ -147,6 +148,7 @@ static struct platform_driver k3_chipinfo_driver = {
.of_match_table = k3_chipinfo_of_match,
},
.probe = k3_chipinfo_probe,
+ .remove = k3_chipinfo_remove,
};
static int __init k3_chipinfo_init(void)