diff mbox series

[1/5] iio: light: noa1305: Simplify noa1305_read_raw()

Message ID 20240715183120.143417-1-marex@denx.de (mailing list archive)
State Accepted
Headers show
Series [1/5] iio: light: noa1305: Simplify noa1305_read_raw() | expand

Commit Message

Marek Vasut July 15, 2024, 6:28 p.m. UTC
The only channel this hardware supports is IIO_LIGHT, if the channel
is anything else, exit right away. The 'ret' variable is now always
only assigned by noa1305_measure(), do not initialize it anymore.
Update function parameter indent. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
---
 drivers/iio/light/noa1305.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

Comments

Jonathan Cameron July 20, 2024, 1:29 p.m. UTC | #1
On Mon, 15 Jul 2024 20:28:55 +0200
Marek Vasut <marex@denx.de> wrote:

> The only channel this hardware supports is IIO_LIGHT, if the channel
> is anything else, exit right away. The 'ret' variable is now always
> only assigned by noa1305_measure(), do not initialize it anymore.
> Update function parameter indent. No functional change.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
Hi Marek,

One minor thing - please use a cover letter.
Provides an obvious place for me to reply when picking things up and
gives the whole series a meaningful title in patchwork.

Anyhow, looks straight forward to me so I'll apply it to my current testing
tree. Not that will get rebased on rc1 once available.
If anyone has additional feedback in the meantime I'm happy to rebase
until this gets pushed out as togreg so can add tags or make other changes.

Thanks,

Jonathan

> ---
> Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: linux-iio@vger.kernel.org
> ---
>  drivers/iio/light/noa1305.c | 37 +++++++++++++------------------------
>  1 file changed, 13 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
> index 596cc48c4c341..a76f158bb50e5 100644
> --- a/drivers/iio/light/noa1305.c
> +++ b/drivers/iio/light/noa1305.c
> @@ -125,38 +125,27 @@ static const struct iio_chan_spec noa1305_channels[] = {
>  };
>  
>  static int noa1305_read_raw(struct iio_dev *indio_dev,
> -				struct iio_chan_spec const *chan,
> -				int *val, int *val2, long mask)
> +			    struct iio_chan_spec const *chan,
> +			    int *val, int *val2, long mask)
>  {
> -	int ret = -EINVAL;
>  	struct noa1305_priv *priv = iio_priv(indio_dev);
> +	int ret;
> +
> +	if (chan->type != IIO_LIGHT)
> +		return -EINVAL;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> -		switch (chan->type) {
> -		case IIO_LIGHT:
> -			ret = noa1305_measure(priv);
> -			if (ret < 0)
> -				return ret;
> -			*val = ret;
> -			return IIO_VAL_INT;
> -		default:
> -			break;
> -		}
> -		break;
> +		ret = noa1305_measure(priv);
> +		if (ret < 0)
> +			return ret;
> +		*val = ret;
> +		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
> -		switch (chan->type) {
> -		case IIO_LIGHT:
> -			return noa1305_scale(priv, val, val2);
> -		default:
> -			break;
> -		}
> -		break;
> +		return noa1305_scale(priv, val, val2);
>  	default:
> -		break;
> +		return -EINVAL;
>  	}
> -
> -	return ret;
>  }
>  
>  static const struct iio_info noa1305_info = {
Marek Vasut July 20, 2024, 4:22 p.m. UTC | #2
On 7/20/24 3:29 PM, Jonathan Cameron wrote:
> On Mon, 15 Jul 2024 20:28:55 +0200
> Marek Vasut <marex@denx.de> wrote:
> 
>> The only channel this hardware supports is IIO_LIGHT, if the channel
>> is anything else, exit right away. The 'ret' variable is now always
>> only assigned by noa1305_measure(), do not initialize it anymore.
>> Update function parameter indent. No functional change.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
> Hi Marek,
> 
> One minor thing - please use a cover letter.
> Provides an obvious place for me to reply when picking things up and
> gives the whole series a meaningful title in patchwork.

I will keep that in mind, thanks for the reminder.
diff mbox series

Patch

diff --git a/drivers/iio/light/noa1305.c b/drivers/iio/light/noa1305.c
index 596cc48c4c341..a76f158bb50e5 100644
--- a/drivers/iio/light/noa1305.c
+++ b/drivers/iio/light/noa1305.c
@@ -125,38 +125,27 @@  static const struct iio_chan_spec noa1305_channels[] = {
 };
 
 static int noa1305_read_raw(struct iio_dev *indio_dev,
-				struct iio_chan_spec const *chan,
-				int *val, int *val2, long mask)
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long mask)
 {
-	int ret = -EINVAL;
 	struct noa1305_priv *priv = iio_priv(indio_dev);
+	int ret;
+
+	if (chan->type != IIO_LIGHT)
+		return -EINVAL;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		switch (chan->type) {
-		case IIO_LIGHT:
-			ret = noa1305_measure(priv);
-			if (ret < 0)
-				return ret;
-			*val = ret;
-			return IIO_VAL_INT;
-		default:
-			break;
-		}
-		break;
+		ret = noa1305_measure(priv);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		switch (chan->type) {
-		case IIO_LIGHT:
-			return noa1305_scale(priv, val, val2);
-		default:
-			break;
-		}
-		break;
+		return noa1305_scale(priv, val, val2);
 	default:
-		break;
+		return -EINVAL;
 	}
-
-	return ret;
 }
 
 static const struct iio_info noa1305_info = {