linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: sun4i-gpadc: use of_device_get_match_data
@ 2017-10-20  5:37 Corentin Labbe
  2017-10-21 17:49 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Corentin Labbe @ 2017-10-20  5:37 UTC (permalink / raw)
  To: jic23, knaack.h, lars, maxime.ripard, wens, pmeerw, quentin.schulz
  Cc: linux-iio, linux-arm-kernel, linux-kernel, Corentin Labbe

The usage of of_device_get_match_data reduce the code size a bit.
Furthermore, it prevents an improbable dereference when
of_match_device() return NULL.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
---
 drivers/iio/adc/sun4i-gpadc-iio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
index c4e70f1cad79..04d7147e0110 100644
--- a/drivers/iio/adc/sun4i-gpadc-iio.c
+++ b/drivers/iio/adc/sun4i-gpadc-iio.c
@@ -501,17 +501,15 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev,
 				struct iio_dev *indio_dev)
 {
 	struct sun4i_gpadc_iio *info = iio_priv(indio_dev);
-	const struct of_device_id *of_dev;
 	struct resource *mem;
 	void __iomem *base;
 	int ret;
 
-	of_dev = of_match_device(sun4i_gpadc_of_id, &pdev->dev);
-	if (!of_dev)
+	info->data = of_device_get_match_data(&pdev->dev);
+	if (!info->data)
 		return -ENODEV;
 
 	info->no_irq = true;
-	info->data = (struct gpadc_data *)of_dev->data;
 	indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels);
 	indio_dev->channels = sun8i_a33_gpadc_channels;
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: adc: sun4i-gpadc: use of_device_get_match_data
  2017-10-20  5:37 [PATCH] iio: adc: sun4i-gpadc: use of_device_get_match_data Corentin Labbe
@ 2017-10-21 17:49 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2017-10-21 17:49 UTC (permalink / raw)
  To: Corentin Labbe
  Cc: knaack.h, lars, maxime.ripard, wens, pmeerw, quentin.schulz,
	linux-iio, linux-arm-kernel, linux-kernel

On Fri, 20 Oct 2017 07:37:29 +0200
Corentin Labbe <clabbe.montjoie@gmail.com> wrote:

> The usage of of_device_get_match_data reduce the code size a bit.
> Furthermore, it prevents an improbable dereference when
> of_match_device() return NULL.
> 
> Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Nice little tidy up - thanks.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/adc/sun4i-gpadc-iio.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
> index c4e70f1cad79..04d7147e0110 100644
> --- a/drivers/iio/adc/sun4i-gpadc-iio.c
> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c
> @@ -501,17 +501,15 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev,
>  				struct iio_dev *indio_dev)
>  {
>  	struct sun4i_gpadc_iio *info = iio_priv(indio_dev);
> -	const struct of_device_id *of_dev;
>  	struct resource *mem;
>  	void __iomem *base;
>  	int ret;
>  
> -	of_dev = of_match_device(sun4i_gpadc_of_id, &pdev->dev);
> -	if (!of_dev)
> +	info->data = of_device_get_match_data(&pdev->dev);
> +	if (!info->data)
>  		return -ENODEV;
>  
>  	info->no_irq = true;
> -	info->data = (struct gpadc_data *)of_dev->data;
>  	indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels);
>  	indio_dev->channels = sun8i_a33_gpadc_channels;
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-21 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-20  5:37 [PATCH] iio: adc: sun4i-gpadc: use of_device_get_match_data Corentin Labbe
2017-10-21 17:49 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).