All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: Replace occurrences of magic number 0 by IIO_CHAN_INFO_RAW
@ 2018-03-06 12:02 Rodrigo Siqueira
  2018-03-07 20:16 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Siqueira @ 2018-03-06 12:02 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel
  Cc: daniel.baluta, linux-iio, linux-kernel

Usually, functions responsible for reading raw data typically relies on
values from iio_chan_info_enum to correctly identify the type of data to
be read. There is a set of a device driver that uses the magic number 0
instead of IIO_CHAN_INFO_RAW. This patch improves the readability by
replaces the magic number 0 for the appropriate IIO_CHAN_INFO_RAW in six
devices driver in the IIO subsystem.

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c | 2 +-
 drivers/iio/dac/ad5380.c                | 2 +-
 drivers/iio/dac/ad5764.c                | 2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c   | 2 +-
 drivers/iio/light/hid-sensor-als.c      | 2 +-
 drivers/iio/light/lm3533-als.c          | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index c066a3bdbff7..41d97faf5013 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -155,7 +155,7 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		hid_sensor_power_state(&accel_state->common_attributes, true);
 		report_id = accel_state->accel[chan->scan_index].report_id;
 		address = accel_3d_addresses[chan->scan_index];
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
index 845fd1c0fd9d..873c2bf637c0 100644
--- a/drivers/iio/dac/ad5380.c
+++ b/drivers/iio/dac/ad5380.c
@@ -158,7 +158,7 @@ static unsigned int ad5380_info_to_reg(struct iio_chan_spec const *chan,
 	long info)
 {
 	switch (info) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		return AD5380_REG_DATA(chan->address);
 	case IIO_CHAN_INFO_CALIBBIAS:
 		return AD5380_REG_OFFSET(chan->address);
diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
index 033f20eca616..9333177062c0 100644
--- a/drivers/iio/dac/ad5764.c
+++ b/drivers/iio/dac/ad5764.c
@@ -168,7 +168,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
 static int ad5764_chan_info_to_reg(struct iio_chan_spec const *chan, long info)
 {
 	switch (info) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		return AD5764_REG_DATA(chan->address);
 	case IIO_CHAN_INFO_CALIBBIAS:
 		return AD5764_REG_OFFSET(chan->address);
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index f59995a90387..36941e69f959 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -115,7 +115,7 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		hid_sensor_power_state(&gyro_state->common_attributes, true);
 		report_id = gyro_state->gyro[chan->scan_index].report_id;
 		address = gyro_3d_addresses[chan->scan_index];
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index befd693a4a31..406caaee9a3c 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -97,7 +97,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
 	*val = 0;
 	*val2 = 0;
 	switch (mask) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		switch (chan->scan_index) {
 		case  CHANNEL_SCAN_INDEX_INTENSITY:
 		case  CHANNEL_SCAN_INDEX_ILLUM:
diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
index 36208a3652e9..ff5a3324b489 100644
--- a/drivers/iio/light/lm3533-als.c
+++ b/drivers/iio/light/lm3533-als.c
@@ -199,7 +199,7 @@ static int lm3533_als_read_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (mask) {
-	case 0:
+	case IIO_CHAN_INFO_RAW:
 		switch (chan->type) {
 		case IIO_LIGHT:
 			ret = lm3533_als_get_adc(indio_dev, false, val);
-- 
2.16.2

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

* Re: [PATCH] iio: Replace occurrences of magic number 0 by IIO_CHAN_INFO_RAW
  2018-03-06 12:02 [PATCH] iio: Replace occurrences of magic number 0 by IIO_CHAN_INFO_RAW Rodrigo Siqueira
@ 2018-03-07 20:16 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-03-07 20:16 UTC (permalink / raw)
  To: Rodrigo Siqueira
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	linux-iio, linux-kernel, daniel.baluta

On Tue, 6 Mar 2018 09:02:57 -0300
Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com> wrote:

> Usually, functions responsible for reading raw data typically relies on
> values from iio_chan_info_enum to correctly identify the type of data to
> be read. There is a set of a device driver that uses the magic number 0
> instead of IIO_CHAN_INFO_RAW. This patch improves the readability by
> replaces the magic number 0 for the appropriate IIO_CHAN_INFO_RAW in six
> devices driver in the IIO subsystem.
> 
> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Just for reference this is a result of a weird piece of history
where 0 used to be deliberately not in the enum (also the reason
the variable is called mask in a lot of drivers which doesn't
make all that much sense.)  We used to pass through bit mask
with just one bit ever set.  Hence 0 was spcial.

Anyhow, good to clear these up.

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

Thanks,

Jonathan

> ---
>  drivers/iio/accel/hid-sensor-accel-3d.c | 2 +-
>  drivers/iio/dac/ad5380.c                | 2 +-
>  drivers/iio/dac/ad5764.c                | 2 +-
>  drivers/iio/gyro/hid-sensor-gyro-3d.c   | 2 +-
>  drivers/iio/light/hid-sensor-als.c      | 2 +-
>  drivers/iio/light/lm3533-als.c          | 2 +-
>  6 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
> index c066a3bdbff7..41d97faf5013 100644
> --- a/drivers/iio/accel/hid-sensor-accel-3d.c
> +++ b/drivers/iio/accel/hid-sensor-accel-3d.c
> @@ -155,7 +155,7 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
>  	*val = 0;
>  	*val2 = 0;
>  	switch (mask) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		hid_sensor_power_state(&accel_state->common_attributes, true);
>  		report_id = accel_state->accel[chan->scan_index].report_id;
>  		address = accel_3d_addresses[chan->scan_index];
> diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c
> index 845fd1c0fd9d..873c2bf637c0 100644
> --- a/drivers/iio/dac/ad5380.c
> +++ b/drivers/iio/dac/ad5380.c
> @@ -158,7 +158,7 @@ static unsigned int ad5380_info_to_reg(struct iio_chan_spec const *chan,
>  	long info)
>  {
>  	switch (info) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		return AD5380_REG_DATA(chan->address);
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		return AD5380_REG_OFFSET(chan->address);
> diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
> index 033f20eca616..9333177062c0 100644
> --- a/drivers/iio/dac/ad5764.c
> +++ b/drivers/iio/dac/ad5764.c
> @@ -168,7 +168,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
>  static int ad5764_chan_info_to_reg(struct iio_chan_spec const *chan, long info)
>  {
>  	switch (info) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		return AD5764_REG_DATA(chan->address);
>  	case IIO_CHAN_INFO_CALIBBIAS:
>  		return AD5764_REG_OFFSET(chan->address);
> diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> index f59995a90387..36941e69f959 100644
> --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
> +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
> @@ -115,7 +115,7 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
>  	*val = 0;
>  	*val2 = 0;
>  	switch (mask) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		hid_sensor_power_state(&gyro_state->common_attributes, true);
>  		report_id = gyro_state->gyro[chan->scan_index].report_id;
>  		address = gyro_3d_addresses[chan->scan_index];
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index befd693a4a31..406caaee9a3c 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -97,7 +97,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
>  	*val = 0;
>  	*val2 = 0;
>  	switch (mask) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		switch (chan->scan_index) {
>  		case  CHANNEL_SCAN_INDEX_INTENSITY:
>  		case  CHANNEL_SCAN_INDEX_ILLUM:
> diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c
> index 36208a3652e9..ff5a3324b489 100644
> --- a/drivers/iio/light/lm3533-als.c
> +++ b/drivers/iio/light/lm3533-als.c
> @@ -199,7 +199,7 @@ static int lm3533_als_read_raw(struct iio_dev *indio_dev,
>  	int ret;
>  
>  	switch (mask) {
> -	case 0:
> +	case IIO_CHAN_INFO_RAW:
>  		switch (chan->type) {
>  		case IIO_LIGHT:
>  			ret = lm3533_als_get_adc(indio_dev, false, val);

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

end of thread, other threads:[~2018-03-07 20:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-06 12:02 [PATCH] iio: Replace occurrences of magic number 0 by IIO_CHAN_INFO_RAW Rodrigo Siqueira
2018-03-07 20:16 ` 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.