Linux Kernel Mentees list
 help / color / mirror / Atom feed
* [PATCH] iio: humidity: htc100c: Fix checkpatch warn unnecessary else
@ 2026-08-02  1:44 Adi Nata
  2026-08-02 14:48 ` David Lechner
  0 siblings, 1 reply; 3+ messages in thread
From: Adi Nata @ 2026-08-02  1:44 UTC (permalink / raw)
  To: jic23, dlechner, nuno.sa, andy, u.kleine-koenig,
	adinata.softwareengineer, mazziesaccount, bhelgaas, o-takashi,
	linux-iio, linux-kernel
  Cc: linux-kernel-mentees

Checkpatch warning:

WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return
+			return IIO_VAL_FRACTIONAL;
+		} else {

Signed-off-by: Adi Nata <adinata.softwareengineer@gmail.com>
---
 drivers/iio/humidity/hdc100x.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
index bc452cc8fbcf..38903239fb9a 100644
--- a/drivers/iio/humidity/hdc100x.c
+++ b/drivers/iio/humidity/hdc100x.c
@@ -229,13 +229,11 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
 		if (chan->type == IIO_TEMP) {
 			*val = 165000;
 			*val2 = 65536;
-			return IIO_VAL_FRACTIONAL;
 		} else {
 			*val = 100000;
 			*val2 = 65536;
-			return IIO_VAL_FRACTIONAL;
 		}
-		break;
+		return IIO_VAL_FRACTIONAL;
 	case IIO_CHAN_INFO_OFFSET:
 		*val = -15887;
 		*val2 = 515151;
-- 
2.47.3


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

* Re: [PATCH] iio: humidity: htc100c: Fix checkpatch warn unnecessary else
  2026-08-02  1:44 [PATCH] iio: humidity: htc100c: Fix checkpatch warn unnecessary else Adi Nata
@ 2026-08-02 14:48 ` David Lechner
  2026-08-02 17:03   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2026-08-02 14:48 UTC (permalink / raw)
  To: Adi Nata, jic23, nuno.sa, andy, u.kleine-koenig, mazziesaccount,
	bhelgaas, o-takashi, linux-iio, linux-kernel
  Cc: linux-kernel-mentees

On 8/1/26 8:44 PM, Adi Nata wrote:
> Checkpatch warning:

Making checkpatch happy is not a good reason for a change on it's own.
It is only there for guidance. It is not a strict rule that has to be
followed.

I think this is a good change because it reduces duplication of the
return statements and eliminates an unreachable break statement. So
write the commit message with that reasoning and don't mention checkpatch.

> 
> WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return
> +			return IIO_VAL_FRACTIONAL;
> +		} else {
> 
> Signed-off-by: Adi Nata <adinata.softwareengineer@gmail.com>
> ---
>  drivers/iio/humidity/hdc100x.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
> index bc452cc8fbcf..38903239fb9a 100644
> --- a/drivers/iio/humidity/hdc100x.c
> +++ b/drivers/iio/humidity/hdc100x.c
> @@ -229,13 +229,11 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
>  		if (chan->type == IIO_TEMP) {
>  			*val = 165000;
>  			*val2 = 65536;
> -			return IIO_VAL_FRACTIONAL;
>  		} else {
>  			*val = 100000;
>  			*val2 = 65536;
> -			return IIO_VAL_FRACTIONAL;
>  		}
> -		break;
> +		return IIO_VAL_FRACTIONAL;
>  	case IIO_CHAN_INFO_OFFSET:
>  		*val = -15887;
>  		*val2 = 515151;


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

* Re: [PATCH] iio: humidity: htc100c: Fix checkpatch warn unnecessary else
  2026-08-02 14:48 ` David Lechner
@ 2026-08-02 17:03   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-08-02 17:03 UTC (permalink / raw)
  To: David Lechner
  Cc: Adi Nata, nuno.sa, andy, u.kleine-koenig, mazziesaccount,
	bhelgaas, o-takashi, linux-iio, linux-kernel,
	linux-kernel-mentees

On Sun, 2 Aug 2026 09:48:11 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 8/1/26 8:44 PM, Adi Nata wrote:
> > Checkpatch warning:  
> 
> Making checkpatch happy is not a good reason for a change on it's own.
> It is only there for guidance. It is not a strict rule that has to be
> followed.
> 
> I think this is a good change because it reduces duplication of the
> return statements and eliminates an unreachable break statement. So
> write the commit message with that reasoning and don't mention checkpatch.

A 'whilst I was looking at this code' comment below if you want to take
on an additional minor readability improvement.  Whilst it is a bit
churn heavy given touching most of the code you are changing here, I think
it would still need to be a separate follow on patch.  Also do check my
suggestion carefully as I may have missed something!

thanks,

Jonathan
> 
> > 
> > WARNING:UNNECESSARY_ELSE: else is not generally useful after a break or return
> > +			return IIO_VAL_FRACTIONAL;
> > +		} else {
> > 
> > Signed-off-by: Adi Nata <adinata.softwareengineer@gmail.com>
> > ---
> >  drivers/iio/humidity/hdc100x.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
> > index bc452cc8fbcf..38903239fb9a 100644
> > --- a/drivers/iio/humidity/hdc100x.c
> > +++ b/drivers/iio/humidity/hdc100x.c
> > @@ -229,13 +229,11 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
> >  		if (chan->type == IIO_TEMP) {
> >  			*val = 165000;
> >  			*val2 = 65536;
A whilst we are here comment.

This is 2**16  So maybe can use chan->real_bits
to provide a form of documentation of where it comes from and
then return IIO_VAL_FRACTIONAL_LOG2;


> > -			return IIO_VAL_FRACTIONAL;
> >  		} else {
> >  			*val = 100000;
> >  			*val2 = 65536;
> > -			return IIO_VAL_FRACTIONAL;
> >  		}
> > -		break;
> > +		return IIO_VAL_FRACTIONAL;
> >  	case IIO_CHAN_INFO_OFFSET:
> >  		*val = -15887;
> >  		*val2 = 515151;  
> 


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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-02  1:44 [PATCH] iio: humidity: htc100c: Fix checkpatch warn unnecessary else Adi Nata
2026-08-02 14:48 ` David Lechner
2026-08-02 17:03   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox