diff mbox series

[2/2] iio: potentiometer mcp4131: use spi_get_device_id() only when needed

Message ID 20181116094722.1070-3-sst@poczta.fm (mailing list archive)
State New, archived
Headers show
Series Use OF API to get the driver data | expand

Commit Message

Slawomir Stepien Nov. 16, 2018, 9:47 a.m. UTC
There is no need to find the device id up front, since the
of_device_get_match_data() might return the correct data.

Signed-off-by: Slawomir Stepien <sst@poczta.fm>
---
 drivers/iio/potentiometer/mcp4131.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron Nov. 16, 2018, 11:53 a.m. UTC | #1
On Fri, 16 Nov 2018 10:47:22 +0100
Slawomir Stepien <sst@poczta.fm> wrote:

> There is no need to find the device id up front, since the
> of_device_get_match_data() might return the correct data.
> 
Ah. That explains it.   This should just have been merged with the previous
patch :)

Anyhow, I'll apply them both but merge them whilst doing so.

So applied as one patch to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it.

As things currently stand it's not worth going through and doing this for
every driver as I don't think the other path is being removed any
time soon.  It's a worthwhile change if people happen to be doing other
work on a particular driver though!

Thanks,

Jonathan

> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
> ---
>  drivers/iio/potentiometer/mcp4131.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/potentiometer/mcp4131.c b/drivers/iio/potentiometer/mcp4131.c
> index 55f526a59215..efe035ce010d 100644
> --- a/drivers/iio/potentiometer/mcp4131.c
> +++ b/drivers/iio/potentiometer/mcp4131.c
> @@ -244,7 +244,7 @@ static int mcp4131_probe(struct spi_device *spi)
>  {
>  	int err;
>  	struct device *dev = &spi->dev;
> -	unsigned long devid = spi_get_device_id(spi)->driver_data;
> +	unsigned long devid;
>  	struct mcp4131_data *data;
>  	struct iio_dev *indio_dev;
>  
> @@ -256,8 +256,10 @@ static int mcp4131_probe(struct spi_device *spi)
>  	spi_set_drvdata(spi, indio_dev);
>  	data->spi = spi;
>  	data->cfg = of_device_get_match_data(&spi->dev);
> -	if (!data->cfg)
> +	if (!data->cfg) {
> +		devid = spi_get_device_id(spi)->driver_data;
>  		data->cfg = &mcp4131_cfg[devid];
> +	}
>  
>  	mutex_init(&data->lock);
>
Slawomir Stepien Nov. 16, 2018, 12:19 p.m. UTC | #2
On lis 16, 2018 11:53, Jonathan Cameron wrote:
> On Fri, 16 Nov 2018 10:47:22 +0100
> Slawomir Stepien <sst@poczta.fm> wrote:
> 
> > There is no need to find the device id up front, since the
> > of_device_get_match_data() might return the correct data.
> > 
> Ah. That explains it.   This should just have been merged with the previous
> patch :)
> 
> Anyhow, I'll apply them both but merge them whilst doing so.

OK, that's fine for me.

> So applied as one patch to the togreg branch of iio.git and pushed out as
> testing for the autobuilders to play with it.
> 
> As things currently stand it's not worth going through and doing this for
> every driver as I don't think the other path is being removed any
> time soon.  It's a worthwhile change if people happen to be doing other
> work on a particular driver though!

OK.

Thank you for quick review.
diff mbox series

Patch

diff --git a/drivers/iio/potentiometer/mcp4131.c b/drivers/iio/potentiometer/mcp4131.c
index 55f526a59215..efe035ce010d 100644
--- a/drivers/iio/potentiometer/mcp4131.c
+++ b/drivers/iio/potentiometer/mcp4131.c
@@ -244,7 +244,7 @@  static int mcp4131_probe(struct spi_device *spi)
 {
 	int err;
 	struct device *dev = &spi->dev;
-	unsigned long devid = spi_get_device_id(spi)->driver_data;
+	unsigned long devid;
 	struct mcp4131_data *data;
 	struct iio_dev *indio_dev;
 
@@ -256,8 +256,10 @@  static int mcp4131_probe(struct spi_device *spi)
 	spi_set_drvdata(spi, indio_dev);
 	data->spi = spi;
 	data->cfg = of_device_get_match_data(&spi->dev);
-	if (!data->cfg)
+	if (!data->cfg) {
+		devid = spi_get_device_id(spi)->driver_data;
 		data->cfg = &mcp4131_cfg[devid];
+	}
 
 	mutex_init(&data->lock);