Re: [RFC PATCH 4/6] of: Extract alloc/add functions from of_platform_device_create_pdata()

Konrad Dybcio
2025-01-09T14:06:50Z

On 8.01.2025 2:28 AM, Stephen Boyd wrote:
> Allow drivers to modify the 'struct device' for a device node by
> splitting of_platform_device_create_pdata() into two functions. The
> first function, of_platform_device_alloc(), allocates the platform
> device and the second function, of_platform_device_add(), adds the
> platform device to the platform bus. SoC power management drivers can
> use these APIs to allocate a platform device for a node underneath the
> soc node, attach pmdomains and/or set the device as runtime PM active,
> and finally add the platform device to the platform bus.
>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Saravana Kannan <saravanak@google.com>
> Cc: <devicetree@vger.kernel.org>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: Konrad Dybcio <konradybcio@kernel.org>
> Cc: <linux-arm-msm@vger.kernel.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---

[...]

> +/**
> + * of_platform_device_add - Add an of_device to the platform bus
> + * @ofdev: of_device to add
> + *
> + * Return: 0 on success, negative errno on failure.
> + */
> +int of_platform_device_add(struct platform_device *ofdev)
> +{
> + struct device_node *np = ofdev->dev.of_node;
> + int ret;
> +
> + pr_debug("adding platform device: %pOF\n", np);
> +
> + ret = of_device_add(ofdev);
> + if (ret) {
> + platform_device_put(ofdev);
> + of_node_clear_flag(np, OF_POPULATED);
> + }
> +
> + return ret;
> +}
> +EXPORT_SYMBOL(of_platform_device_add);
> +
> /**
> * of_platform_device_create_pdata - Alloc, initialize and register an of_device
> * @np: pointer to node to create device for
> @@ -154,29 +214,19 @@ static struct platform_device *of_platform_device_create_pdata(
> void *platform_data,
> struct device *parent)
> {
> + int ret;
> struct platform_device *dev;

ultranit: you kept the reverse order above, please keep ret last too

Konrad