linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: inv-mpu: make inv_write_raw_get_fmt() more readable
@ 2015-07-27 21:48 Luis Henriques
  2015-08-02 17:51 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Luis Henriques @ 2015-07-27 21:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio,
	linux-kernel

Replace nested switch statements by a single if statement, making function
inv_write_raw_get_fmt() more readable.

Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 65ce86837177..afbc2d2b8608 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -434,19 +434,9 @@ static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val)
 static int inv_write_raw_get_fmt(struct iio_dev *indio_dev,
 				 struct iio_chan_spec const *chan, long mask)
 {
-	switch (mask) {
-	case IIO_CHAN_INFO_SCALE:
-		switch (chan->type) {
-		case IIO_ANGL_VEL:
-			return IIO_VAL_INT_PLUS_NANO;
-		default:
-			return IIO_VAL_INT_PLUS_MICRO;
-		}
-	default:
-		return IIO_VAL_INT_PLUS_MICRO;
-	}
-
-	return -EINVAL;
+	if ((mask == IIO_CHAN_INFO_SCALE) && (chan->type == IIO_ANGL_VEL))
+		return IIO_VAL_INT_PLUS_NANO;
+	return IIO_VAL_INT_PLUS_MICRO;
 }
 static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val)
 {

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

* Re: [PATCH] iio: inv-mpu: make inv_write_raw_get_fmt() more readable
  2015-07-27 21:48 [PATCH] iio: inv-mpu: make inv_write_raw_get_fmt() more readable Luis Henriques
@ 2015-08-02 17:51 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2015-08-02 17:51 UTC (permalink / raw)
  To: Luis Henriques
  Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald, linux-iio,
	linux-kernel

On 27/07/15 22:48, Luis Henriques wrote:
> Replace nested switch statements by a single if statement, making function
> inv_write_raw_get_fmt() more readable.
> 
> Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Hi Luis,

I can see where you are coming from here, but my gut feeling
is to leave it be as the chances are more stuff will get added
to this function in the future.  The mpu6050 are complex parts
for which we currently only support a very limited subset of
functionality.  An example of this is we have no filter
control at the moment.  The double case statement is ugly
but it easy to verify.

So I'm not going to take this one.

Sorry,

Jonathan
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 65ce86837177..afbc2d2b8608 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -434,19 +434,9 @@ static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val)
>  static int inv_write_raw_get_fmt(struct iio_dev *indio_dev,
>  				 struct iio_chan_spec const *chan, long mask)
>  {
> -	switch (mask) {
> -	case IIO_CHAN_INFO_SCALE:
> -		switch (chan->type) {
> -		case IIO_ANGL_VEL:
> -			return IIO_VAL_INT_PLUS_NANO;
> -		default:
> -			return IIO_VAL_INT_PLUS_MICRO;
> -		}
> -	default:
> -		return IIO_VAL_INT_PLUS_MICRO;
> -	}
> -
> -	return -EINVAL;
> +	if ((mask == IIO_CHAN_INFO_SCALE) && (chan->type == IIO_ANGL_VEL))
> +		return IIO_VAL_INT_PLUS_NANO;
> +	return IIO_VAL_INT_PLUS_MICRO;
>  }
>  static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val)
>  {
> --
> 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] 2+ messages in thread

end of thread, other threads:[~2015-08-02 17:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 21:48 [PATCH] iio: inv-mpu: make inv_write_raw_get_fmt() more readable Luis Henriques
2015-08-02 17:51 ` 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).