public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
@ 2024-06-13 12:07 Joy Chakraborty
  2024-06-13 12:31 ` Dan Carpenter
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Joy Chakraborty @ 2024-06-13 12:07 UTC (permalink / raw)
  To: Sean Anderson, Alexandre Belloni, Srinivas Kandagatla,
	Dan Carpenter
  Cc: linux-rtc, linux-kernel, Joy Chakraborty, stable

Read callbacks registered with nvmem core expect 0 to be returned on
success and a negative value to be returned on failure.

abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
returns the number of bytes read on success as per its api description,
this return value is handled as an error and returned to nvmem even on
success.

Fix to handle all possible values that would be returned by
i2c_smbus_read_i2c_block_data().

Fixes: e90ff8ede777 ("rtc: abx80x: Add nvmem support")
Cc: stable@vger.kernel.org
Signed-off-by: Joy Chakraborty <joychakr@google.com>
---
 drivers/rtc/rtc-abx80x.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index fde2b8054c2e..1298962402ff 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -705,14 +705,18 @@ static int abx80x_nvmem_xfer(struct abx80x_priv *priv, unsigned int offset,
 		if (ret)
 			return ret;
 
-		if (write)
+		if (write) {
 			ret = i2c_smbus_write_i2c_block_data(priv->client, reg,
 							     len, val);
-		else
+			if (ret)
+				return ret;
+		} else {
 			ret = i2c_smbus_read_i2c_block_data(priv->client, reg,
 							    len, val);
-		if (ret)
-			return ret;
+			if (ret <= 0)
+				return ret ? ret : -EIO;
+			len = ret;
+		}
 
 		offset += len;
 		val += len;
-- 
2.45.2.505.gda0bf45e8d-goog


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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-13 12:07 [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read Joy Chakraborty
@ 2024-06-13 12:31 ` Dan Carpenter
  2024-06-13 15:11 ` Sean Anderson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-06-13 12:31 UTC (permalink / raw)
  To: Joy Chakraborty
  Cc: Sean Anderson, Alexandre Belloni, Srinivas Kandagatla, linux-rtc,
	linux-kernel, stable

On Thu, Jun 13, 2024 at 12:07:50PM +0000, Joy Chakraborty wrote:
> Read callbacks registered with nvmem core expect 0 to be returned on
> success and a negative value to be returned on failure.
> 
> abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
> returns the number of bytes read on success as per its api description,
> this return value is handled as an error and returned to nvmem even on
> success.
> 
> Fix to handle all possible values that would be returned by
> i2c_smbus_read_i2c_block_data().
> 
> Fixes: e90ff8ede777 ("rtc: abx80x: Add nvmem support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joy Chakraborty <joychakr@google.com>

Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter


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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-13 12:07 [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read Joy Chakraborty
  2024-06-13 12:31 ` Dan Carpenter
@ 2024-06-13 15:11 ` Sean Anderson
  2024-06-21  6:23 ` Srinivas Kandagatla
  2024-06-27 22:22 ` Alexandre Belloni
  3 siblings, 0 replies; 7+ messages in thread
From: Sean Anderson @ 2024-06-13 15:11 UTC (permalink / raw)
  To: Joy Chakraborty, Alexandre Belloni, Srinivas Kandagatla,
	Dan Carpenter
  Cc: linux-rtc, linux-kernel, stable

On 6/13/24 08:07, Joy Chakraborty wrote:
> Read callbacks registered with nvmem core expect 0 to be returned on
> success and a negative value to be returned on failure.
> 
> abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
> returns the number of bytes read on success as per its api description,
> this return value is handled as an error and returned to nvmem even on
> success.

Humm, I wish this were documented in nvmem-provider.h...

> Fix to handle all possible values that would be returned by
> i2c_smbus_read_i2c_block_data().
> 
> Fixes: e90ff8ede777 ("rtc: abx80x: Add nvmem support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joy Chakraborty <joychakr@google.com>
> ---
>  drivers/rtc/rtc-abx80x.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> index fde2b8054c2e..1298962402ff 100644
> --- a/drivers/rtc/rtc-abx80x.c
> +++ b/drivers/rtc/rtc-abx80x.c
> @@ -705,14 +705,18 @@ static int abx80x_nvmem_xfer(struct abx80x_priv *priv, unsigned int offset,
>  		if (ret)
>  			return ret;
>  
> -		if (write)
> +		if (write) {
>  			ret = i2c_smbus_write_i2c_block_data(priv->client, reg,
>  							     len, val);
> -		else
> +			if (ret)
> +				return ret;
> +		} else {
>  			ret = i2c_smbus_read_i2c_block_data(priv->client, reg,
>  							    len, val);
> -		if (ret)
> -			return ret;
> +			if (ret <= 0)
> +				return ret ? ret : -EIO;
> +			len = ret;
> +		}
>  
>  		offset += len;
>  		val += len;

Reviewed-by: Sean Anderson <sean.anderson@seco.com>

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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-13 12:07 [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read Joy Chakraborty
  2024-06-13 12:31 ` Dan Carpenter
  2024-06-13 15:11 ` Sean Anderson
@ 2024-06-21  6:23 ` Srinivas Kandagatla
  2024-06-21 15:03   ` Alexandre Belloni
  2024-06-27 22:22 ` Alexandre Belloni
  3 siblings, 1 reply; 7+ messages in thread
From: Srinivas Kandagatla @ 2024-06-21  6:23 UTC (permalink / raw)
  To: Sean Anderson, Alexandre Belloni, Dan Carpenter, Joy Chakraborty
  Cc: linux-rtc, linux-kernel, stable


On Thu, 13 Jun 2024 12:07:50 +0000, Joy Chakraborty wrote:
> Read callbacks registered with nvmem core expect 0 to be returned on
> success and a negative value to be returned on failure.
> 
> abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
> returns the number of bytes read on success as per its api description,
> this return value is handled as an error and returned to nvmem even on
> success.
> 
> [...]

Applied, thanks!

[1/1] rtc: abx80x: Fix return value of nvmem callback on read
      commit: 126b2b4ec0f471d46117ca31b99cd76b1eee48d8

Best regards,
-- 
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>


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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-21  6:23 ` Srinivas Kandagatla
@ 2024-06-21 15:03   ` Alexandre Belloni
  2024-06-21 21:21     ` Srinivas Kandagatla
  0 siblings, 1 reply; 7+ messages in thread
From: Alexandre Belloni @ 2024-06-21 15:03 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Sean Anderson, Dan Carpenter, Joy Chakraborty, linux-rtc,
	linux-kernel, stable

On 21/06/2024 07:23:24+0100, Srinivas Kandagatla wrote:
> 
> On Thu, 13 Jun 2024 12:07:50 +0000, Joy Chakraborty wrote:
> > Read callbacks registered with nvmem core expect 0 to be returned on
> > success and a negative value to be returned on failure.
> > 
> > abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
> > returns the number of bytes read on success as per its api description,
> > this return value is handled as an error and returned to nvmem even on
> > success.
> > 
> > [...]
> 
> Applied, thanks!
> 
> [1/1] rtc: abx80x: Fix return value of nvmem callback on read
>       commit: 126b2b4ec0f471d46117ca31b99cd76b1eee48d8
> 

Please drop it from your tree, I'm going to handle the rtc related
patches...

> Best regards,
> -- 
> Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-21 15:03   ` Alexandre Belloni
@ 2024-06-21 21:21     ` Srinivas Kandagatla
  0 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2024-06-21 21:21 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Sean Anderson, Dan Carpenter, Joy Chakraborty, linux-rtc,
	linux-kernel, stable



On 21/06/2024 16:03, Alexandre Belloni wrote:
> On 21/06/2024 07:23:24+0100, Srinivas Kandagatla wrote:
>>
>> On Thu, 13 Jun 2024 12:07:50 +0000, Joy Chakraborty wrote:
>>> Read callbacks registered with nvmem core expect 0 to be returned on
>>> success and a negative value to be returned on failure.
>>>
>>> abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
>>> returns the number of bytes read on success as per its api description,
>>> this return value is handled as an error and returned to nvmem even on
>>> success.
>>>
>>> [...]
>>
>> Applied, thanks!
>>
>> [1/1] rtc: abx80x: Fix return value of nvmem callback on read
>>        commit: 126b2b4ec0f471d46117ca31b99cd76b1eee48d8
>>
> 
> Please drop it from your tree, I'm going to handle the rtc related
> patches...
> 

Sure I will drop it.

--srini
>> Best regards,
>> -- 
>> Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>>
> 

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

* Re: [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read
  2024-06-13 12:07 [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read Joy Chakraborty
                   ` (2 preceding siblings ...)
  2024-06-21  6:23 ` Srinivas Kandagatla
@ 2024-06-27 22:22 ` Alexandre Belloni
  3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2024-06-27 22:22 UTC (permalink / raw)
  To: Sean Anderson, Srinivas Kandagatla, Dan Carpenter,
	Joy Chakraborty
  Cc: linux-rtc, linux-kernel, stable

On Thu, 13 Jun 2024 12:07:50 +0000, Joy Chakraborty wrote:
> Read callbacks registered with nvmem core expect 0 to be returned on
> success and a negative value to be returned on failure.
> 
> abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which
> returns the number of bytes read on success as per its api description,
> this return value is handled as an error and returned to nvmem even on
> success.
> 
> [...]

Applied, thanks!

[1/1] rtc: abx80x: Fix return value of nvmem callback on read
      https://git.kernel.org/abelloni/c/fc82336b50e7

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2024-06-27 22:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 12:07 [PATCH v2] rtc: abx80x: Fix return value of nvmem callback on read Joy Chakraborty
2024-06-13 12:31 ` Dan Carpenter
2024-06-13 15:11 ` Sean Anderson
2024-06-21  6:23 ` Srinivas Kandagatla
2024-06-21 15:03   ` Alexandre Belloni
2024-06-21 21:21     ` Srinivas Kandagatla
2024-06-27 22:22 ` Alexandre Belloni

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