All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters
@ 2016-03-24 16:06 Slawomir Stepien
  2016-03-28  9:39 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Slawomir Stepien @ 2016-03-24 16:06 UTC (permalink / raw)
  To: peda; +Cc: linux-iio, jic23, knaack.h, lars, pmeerw

Use const pointer to element from model configuration array rather then array
index, as it will not change anyway.

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

diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
index a3f6687..385f568 100644
--- a/drivers/iio/potentiometer/mcp4531.c
+++ b/drivers/iio/potentiometer/mcp4531.c
@@ -79,7 +79,7 @@ static const struct mcp4531_cfg mcp4531_cfg[] = {
 
 struct mcp4531_data {
 	struct i2c_client *client;
-	unsigned long devid;
+	const struct mcp4531_cfg *cfg;
 };
 
 #define MCP4531_CHANNEL(ch) {					\
@@ -113,8 +113,8 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev,
 		*val = ret;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		*val = 1000 * mcp4531_cfg[data->devid].kohms;
-		*val2 = mcp4531_cfg[data->devid].max_pos;
+		*val = 1000 * data->cfg->kohms;
+		*val2 = data->cfg->max_pos;
 		return IIO_VAL_FRACTIONAL;
 	}
 
@@ -130,7 +130,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (val > mcp4531_cfg[data->devid].max_pos || val < 0)
+		if (val > data->cfg->max_pos || val < 0)
 			return -EINVAL;
 		break;
 	default:
@@ -152,7 +152,6 @@ static int mcp4531_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
 	struct device *dev = &client->dev;
-	unsigned long devid = id->driver_data;
 	struct mcp4531_data *data;
 	struct iio_dev *indio_dev;
 
@@ -168,12 +167,12 @@ static int mcp4531_probe(struct i2c_client *client,
 	data = iio_priv(indio_dev);
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
-	data->devid = devid;
+	data->cfg = &mcp4531_cfg[id->driver_data];
 
 	indio_dev->dev.parent = dev;
 	indio_dev->info = &mcp4531_info;
 	indio_dev->channels = mcp4531_channels;
-	indio_dev->num_channels = mcp4531_cfg[devid].wipers;
+	indio_dev->num_channels = data->cfg->wipers;
 	indio_dev->name = client->name;
 
 	return devm_iio_device_register(dev, indio_dev);
-- 
2.7.4

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

* Re: [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters
  2016-03-24 16:06 [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters Slawomir Stepien
@ 2016-03-28  9:39 ` Jonathan Cameron
  2016-04-01  5:51   ` Peter Rosin
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2016-03-28  9:39 UTC (permalink / raw)
  To: Slawomir Stepien, peda; +Cc: linux-iio, knaack.h, lars, pmeerw

On 24/03/16 16:06, Slawomir Stepien wrote:
> Use const pointer to element from model configuration array rather then array
> index, as it will not change anyway.
> 
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.  Thanks for cleaning this up.

Jonathan
> ---
>  drivers/iio/potentiometer/mcp4531.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
> index a3f6687..385f568 100644
> --- a/drivers/iio/potentiometer/mcp4531.c
> +++ b/drivers/iio/potentiometer/mcp4531.c
> @@ -79,7 +79,7 @@ static const struct mcp4531_cfg mcp4531_cfg[] = {
>  
>  struct mcp4531_data {
>  	struct i2c_client *client;
> -	unsigned long devid;
> +	const struct mcp4531_cfg *cfg;
>  };
>  
>  #define MCP4531_CHANNEL(ch) {					\
> @@ -113,8 +113,8 @@ static int mcp4531_read_raw(struct iio_dev *indio_dev,
>  		*val = ret;
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
> -		*val = 1000 * mcp4531_cfg[data->devid].kohms;
> -		*val2 = mcp4531_cfg[data->devid].max_pos;
> +		*val = 1000 * data->cfg->kohms;
> +		*val2 = data->cfg->max_pos;
>  		return IIO_VAL_FRACTIONAL;
>  	}
>  
> @@ -130,7 +130,7 @@ static int mcp4531_write_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		if (val > mcp4531_cfg[data->devid].max_pos || val < 0)
> +		if (val > data->cfg->max_pos || val < 0)
>  			return -EINVAL;
>  		break;
>  	default:
> @@ -152,7 +152,6 @@ static int mcp4531_probe(struct i2c_client *client,
>  			 const struct i2c_device_id *id)
>  {
>  	struct device *dev = &client->dev;
> -	unsigned long devid = id->driver_data;
>  	struct mcp4531_data *data;
>  	struct iio_dev *indio_dev;
>  
> @@ -168,12 +167,12 @@ static int mcp4531_probe(struct i2c_client *client,
>  	data = iio_priv(indio_dev);
>  	i2c_set_clientdata(client, indio_dev);
>  	data->client = client;
> -	data->devid = devid;
> +	data->cfg = &mcp4531_cfg[id->driver_data];
>  
>  	indio_dev->dev.parent = dev;
>  	indio_dev->info = &mcp4531_info;
>  	indio_dev->channels = mcp4531_channels;
> -	indio_dev->num_channels = mcp4531_cfg[devid].wipers;
> +	indio_dev->num_channels = data->cfg->wipers;
>  	indio_dev->name = client->name;
>  
>  	return devm_iio_device_register(dev, indio_dev);
> 


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

* RE: [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters
  2016-03-28  9:39 ` Jonathan Cameron
@ 2016-04-01  5:51   ` Peter Rosin
  2016-04-03  9:30     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Rosin @ 2016-04-01  5:51 UTC (permalink / raw)
  To: Jonathan Cameron, Slawomir Stepien; +Cc: linux-iio, knaack.h, lars, pmeerw

Jonathan Cameron wrote:
> On 24/03/16 16:06, Slawomir Stepien wrote:
> > Use const pointer to element from model configuration array rather then array
> > index, as it will not change anyway.
> > 
> > Signed-off-by: Slawomir Stepien <sst@poczta.fm>
> Applied to the togreg branch of iio.git - initially pushed out as testing
> for the autobuilders to play with it.  Thanks for cleaning this up.

I guess it's too late, but FWIW,

Signed-off-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter (mcp4531 maintainer)

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

* Re: [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters
  2016-04-01  5:51   ` Peter Rosin
@ 2016-04-03  9:30     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2016-04-03  9:30 UTC (permalink / raw)
  To: Peter Rosin, Slawomir Stepien; +Cc: linux-iio, knaack.h, lars, pmeerw

On 01/04/16 06:51, Peter Rosin wrote:
> Jonathan Cameron wrote:
>> On 24/03/16 16:06, Slawomir Stepien wrote:
>>> Use const pointer to element from model configuration array rather then array
>>> index, as it will not change anyway.
>>>
>>> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
>> Applied to the togreg branch of iio.git - initially pushed out as testing
>> for the autobuilders to play with it.  Thanks for cleaning this up.
> 
> I guess it's too late, but FWIW,
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>
I haven't yet pushed it out as togreg (rather than testing) so nope, not too late.
Added to the patch.   Thanks

Jonathan
> 
> Cheers,
> Peter (mcp4531 maintainer)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

end of thread, other threads:[~2016-04-03  9:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-24 16:06 [PATCH] iio: potentiometer: mcp4531: use pointer to access model parameters Slawomir Stepien
2016-03-28  9:39 ` Jonathan Cameron
2016-04-01  5:51   ` Peter Rosin
2016-04-03  9:30     ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.