The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: development@redaril.me
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Johan Hovold" <johan@kernel.org>,
	"Peter Rosin" <peda@lysator.liu.se>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 1/2] drivers: core: platform: Add platform_get_match_data() helper
Date: Mon, 30 Nov 2026 13:33:31 +0200	[thread overview]
Message-ID: <aw1fC8hOnCISCeLX@ashevche-desk.local> (raw)
In-Reply-To: <20261128-iio_rescale_platform_ids-v2-1-4c35f16c4f77@redaril.me>

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



  parent reply	other threads:[~2026-11-30 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 23:22 [PATCH v2 0/2] iio: afe: rescale: Get driver data using platform_get_match_data() Fabio Forni via B4 Relay
2026-11-27 23:22 ` [PATCH v2 1/2] drivers: core: platform: Add platform_get_match_data() helper Fabio Forni via B4 Relay
2026-11-28  0:27   ` Jonathan Cameron
2026-11-28  9:04     ` Fabio Forni
2026-11-28 18:38       ` Jonathan Cameron
2026-11-30 11:33   ` Andy Shevchenko [this message]
2026-11-27 23:22 ` [PATCH v2 2/2] iio: afe: iio-rescale: Add platform IDs Fabio Forni via B4 Relay
2026-11-28  0:30   ` Jonathan Cameron
2026-11-28  9:21     ` Fabio Forni
2026-11-30 11:39       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw1fC8hOnCISCeLX@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=dakr@kernel.org \
    --cc=development@redaril.me \
    --cc=dlechner@baylibre.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=peda@lysator.liu.se \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox