Re: [PATCH v2 1/2] drivers: core: platform: Add platform_get_match_data() helper
From: Andy Shevchenko
Date: Mon Nov 30 2026 - 06:33:41 EST
On Sat, Nov 28, 2026 at 12:22:09AM +0100, Fabio Forni via B4 Relay wrote:
>
> device_get_match_data() retrieves driver data through the device's
> fwnode. However, software nodes don't implement
> fwnode->device_get_match_data(), so for a platform device that is
> dynamically instantiated, device_get_match_data() is of no use.
> platform_get_device_id() can be used instead, but this doesn't make the
> driver code abstract enough.
>
> Add the platform_get_match_data() helper, so that driver data can be
> retrieved from platform_device's fwnode *or* device_id as a fallback.
> +/**
> + * platform_get_match_data - get match data from fwnode or device ID
> + * @pdev: platform device to get data of
> + *
> + * Get match data from fwnode if available, otherwise get match data
> + * from pdev's platform_device_id->driver_data. driver_data is
> + * cast into a void* pointer.
> + *
> + * Return: -ENODATA if no match data is available.
And otherwise?
> + */
> +const void *platform_get_match_data(const struct platform_device *pdev)
> +{
> + const struct platform_device_id *id;
struct device *dev = &pdev->dev;
> + const void *ret;
> +
> + ret = device_get_match_data(&pdev->dev);
ret = device_get_match_data(dev);
> + if (ret)
> + return ret;
> +
> + id = platform_get_device_id(pdev);
> + if (id && id->driver_data)
> + return (const void *)id->driver_data;
> +
> + return ERR_PTR(dev_err_probe(&pdev->dev, -ENODATA,
> + "no match data available"));
return ERR_PTR(dev_err_probe(dev, -ENODATA, "no match data available"));
> +}
--
With Best Regards,
Andy Shevchenko