Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] Incomplete migration to `platform_device_set_fwnode()` / 
`platform_device_set_of_node()` causes OF node reference and memory leaks for 
un-migrated callers.
--

commit b1122010b53f4c5f66f9be91e300a372e6dce282
Author: Bartosz Golaszewski <[email protected]>

driver core: platform: provide platform_device_set_of_node()

This commit encapsulates the reference counting logic for OF nodes assigned
to platform devices into a new helper function. It prepares the driver core
to switch to counting references of the device's firmware nodes rather than
just the OF nodes.

> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index fb9120b0bcfe0..3188d5aba5f90 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c

[ ... ]

> @@ -693,6 +693,24 @@ int platform_device_add_data(struct platform_device 
> *pdev, const void *data,
>  }
>  EXPORT_SYMBOL_GPL(platform_device_add_data);
>  
> +/**
> + * platform_device_set_of_node - assign an OF node to device
> + * @pdev: platform device to add the node for
> + * @np: new device node
> + *
> + * Assign an OF node to this platform device. Internally keep track of the
> + * reference count. Devices created with platform_device_alloc() must use 
> this
> + * function instead of assigning the node manually.
> + */
> +void platform_device_set_of_node(struct platform_device *pdev,
> +                              struct device_node *np)
> +{
> +     of_node_put(pdev->dev.of_node);
> +     pdev->dev.of_node = of_node_get(np);
> +     pdev->dev.fwnode = of_fwnode_handle(np);
> +}
> +EXPORT_SYMBOL_GPL(platform_device_set_of_node);

[Severity: High]
Will the transition to this new helper cause OF node reference leaks for
existing drivers that haven't been migrated yet?

For example, looking at max8997_battery_probe() in
drivers/power/supply/max8997_charger.c, the driver currently manually
assigns an acquired OF node without setting fwnode:

drivers/power/supply/max8997_charger.c:max8997_battery_probe() {
    ...
    np = of_get_child_by_name(iodev->dev->of_node, "charger");
    ...
    pdev->dev.of_node = np;
    ...
}

If the driver core teardown is changed later in this patch series to
only release fwnode in platform_device_release(), won't these
un-migrated callers leak their OF node references when the device is
released?

Are there other drivers that need to be migrated to use
platform_device_set_of_node() before making the core change?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=2

Reply via email to