linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: adp5588-keys: fix check on return code
@ 2024-09-20  7:22 Nuno Sa via B4 Relay
  2024-09-20  8:17 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-09-20  7:22 UTC (permalink / raw)
  To: Andy Shevchenko, Dmitry Torokhov; +Cc: linux-input, Michael Hennerich

From: Nuno Sa <nuno.sa@analog.com>

During adp5588_setup(), we read all the events to clear the event FIFO.
However, adp5588_read() just calls i2c_smbus_read_byte_data() which
returns the byte read in case everything goes well. Hence, we need to
explicitly check for a negative error code instead of checking for
something different than 0.

Fixes: e960309ce318 ("Input: adp5588-keys - bail out on returned error")
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/input/keyboard/adp5588-keys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index b5f4becf5cb6f..d25d63a807f23 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -620,7 +620,7 @@ static int adp5588_setup(struct adp5588_kpad *kpad)
 
 	for (i = 0; i < KEYP_MAX_EVENT; i++) {
 		ret = adp5588_read(client, KEY_EVENTA);
-		if (ret)
+		if (ret < 0)
 			return ret;
 	}
 

---
base-commit: 55bef83509f0cbe4cc54a583ac0313389dabee66
change-id: 20240920-fix-adp5588-err-check-6ee553b7b856
--

Thanks!
- Nuno Sá



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

* Re: [PATCH] Input: adp5588-keys: fix check on return code
  2024-09-20  7:22 [PATCH] Input: adp5588-keys: fix check on return code Nuno Sa via B4 Relay
@ 2024-09-20  8:17 ` Dmitry Torokhov
  2024-09-20 11:07   ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2024-09-20  8:17 UTC (permalink / raw)
  To: nuno.sa; +Cc: Andy Shevchenko, linux-input, Michael Hennerich

On Fri, Sep 20, 2024 at 09:22:52AM +0200, Nuno Sa via B4 Relay wrote:
> From: Nuno Sa <nuno.sa@analog.com>
> 
> During adp5588_setup(), we read all the events to clear the event FIFO.
> However, adp5588_read() just calls i2c_smbus_read_byte_data() which
> returns the byte read in case everything goes well. Hence, we need to
> explicitly check for a negative error code instead of checking for
> something different than 0.
> 
> Fixes: e960309ce318 ("Input: adp5588-keys - bail out on returned error")
> Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> ---
>  drivers/input/keyboard/adp5588-keys.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
> index b5f4becf5cb6f..d25d63a807f23 100644
> --- a/drivers/input/keyboard/adp5588-keys.c
> +++ b/drivers/input/keyboard/adp5588-keys.c
> @@ -620,7 +620,7 @@ static int adp5588_setup(struct adp5588_kpad *kpad)
>  
>  	for (i = 0; i < KEYP_MAX_EVENT; i++) {
>  		ret = adp5588_read(client, KEY_EVENTA);
> -		if (ret)
> +		if (ret < 0)
>  			return ret;
>  	}

Hmm... There are a bunch of places where we do not check result of
adp5588_read(). I wonder if we should:

1. add the checks
2. change it to return error or 0 and return the value through a pointer
argument.

In the meantime I'll apply this patch.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] Input: adp5588-keys: fix check on return code
  2024-09-20  8:17 ` Dmitry Torokhov
@ 2024-09-20 11:07   ` Nuno Sá
  0 siblings, 0 replies; 3+ messages in thread
From: Nuno Sá @ 2024-09-20 11:07 UTC (permalink / raw)
  To: Dmitry Torokhov, nuno.sa; +Cc: Andy Shevchenko, linux-input, Michael Hennerich

On Fri, 2024-09-20 at 08:17 +0000, Dmitry Torokhov wrote:
> On Fri, Sep 20, 2024 at 09:22:52AM +0200, Nuno Sa via B4 Relay wrote:
> > From: Nuno Sa <nuno.sa@analog.com>
> > 
> > During adp5588_setup(), we read all the events to clear the event FIFO.
> > However, adp5588_read() just calls i2c_smbus_read_byte_data() which
> > returns the byte read in case everything goes well. Hence, we need to
> > explicitly check for a negative error code instead of checking for
> > something different than 0.
> > 
> > Fixes: e960309ce318 ("Input: adp5588-keys - bail out on returned error")
> > Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> > ---
> >  drivers/input/keyboard/adp5588-keys.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/input/keyboard/adp5588-keys.c
> > b/drivers/input/keyboard/adp5588-keys.c
> > index b5f4becf5cb6f..d25d63a807f23 100644
> > --- a/drivers/input/keyboard/adp5588-keys.c
> > +++ b/drivers/input/keyboard/adp5588-keys.c
> > @@ -620,7 +620,7 @@ static int adp5588_setup(struct adp5588_kpad *kpad)
> >  
> >  	for (i = 0; i < KEYP_MAX_EVENT; i++) {
> >  		ret = adp5588_read(client, KEY_EVENTA);
> > -		if (ret)
> > +		if (ret < 0)
> >  			return ret;
> >  	}
> 
> Hmm... There are a bunch of places where we do not check result of
> adp5588_read(). I wonder if we should:
> 
> 1. add the checks
> 2. change it to return error or 0 and return the value through a pointer
> argument.

It does make sense. I can take care of that. 

And similar work will be needed in the adp5589 driver. I'll include it in the series
I'm preparing for the FW properties.

- Nuno Sá



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

end of thread, other threads:[~2024-09-20 11:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-20  7:22 [PATCH] Input: adp5588-keys: fix check on return code Nuno Sa via B4 Relay
2024-09-20  8:17 ` Dmitry Torokhov
2024-09-20 11:07   ` Nuno Sá

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).