rockchip: fix efuse/otp misc_read return values
Subsystems (4)
v3 cover rockchip: fix efuse/otp misc_read return values
Fix the return value for misc_read() in the two Rockchip nvmem drivers so that they return the number of bytes read.
In v3 there is a new initial patch to fix the one place that uses this return value to correctly check for negative error returns. The other two patches are unchanged from v2.
John Keeping (3):
rockchip: misc: fix misc_read() return check
rockchip: efuse: fix misc_read() return values
rockchip: otp: fix misc_read() return values
arch/arm/mach-rockchip/misc.c | 2 +- drivers/misc/rockchip-efuse.c | 12 ++++++++---- drivers/misc/rockchip-otp.c | 12 ++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.40.0
PATCH v3 1/3 rockchip: misc: fix misc_read() return check
misc_read() is documented to return the number of bytes read or a negative error value. The Rockchip drivers currently do not implement this correctly and instead return zero on success or a negative error value.
In preparation for fixing the drivers, fix the condition here to only error on negative values.
---
v3: new patch
arch/arm/mach-rockchip/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-rockchip/misc.c +1 -1
@@ -83,7 +83,7 @@ int rockchip_cpuid_from_efuse(const u32 cpuid_offset,/* read the cpu_id range from the efuses */ ret =misc_read (dev, cpuid_offset, cpuid, cpuid_length); -if (ret) { +if (ret <0 ) {debug ("%s: reading cpuid from the efuses failed\n" , __func__);return -1 ;
Signature · 1 line
2.40.0
Re: [PATCH v3 1/3] rockchip: misc: fix misc_read() return check
Quoted 9 lines · John Keeping
misc_read()is documented to return the number of bytes read or a negative error value. The Rockchip drivers currently do not implement this correctly and instead return zero on success or a negative error value.In preparation for fixing the drivers, fix the condition here to only error on negative values.
Quoted 7 lines
Suggested-by Jonas Karlman <[email protected]>Signed-off-by John Keeping <[email protected]>---
v3: new patcharch/arm/mach-rockchip/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH v3 1/3] rockchip: misc: fix misc_read() return check
In reply to John KeepingQuoted 10 lines · John Keeping
misc_read()is documented to return the number of bytes read or a negative error value. The Rockchip drivers currently do not implement this correctly and instead return zero on success or a negative error value.In preparation for fixing the drivers, fix the condition here to only error on negative values.
Suggested-by Jonas Karlman <[email protected]>Signed-off-by John Keeping <[email protected]>
Thanks,
- Kever
Quoted 19 lines
---
v3: new patcharch/arm/mach-rockchip/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/mach-rockchip/misc.c +1
-1@@ -83,7 +83,7 @@ int rockchip_cpuid_from_efuse(const u32 cpuid_offset,/* read the cpu_id range from the efuses */ ret =misc_read (dev, cpuid_offset, cpuid, cpuid_length); -if (ret) { +if (ret <0 ) {debug ("%s: reading cpuid from the efuses failed\n" , __func__);return -1 ;
PATCH v3 2/3 rockchip: efuse: fix misc_read() return values
In reply to John KeepingThe documentation for misc_read() says:
Return: number of bytes read if OK (may be 0 if EOF), -ve on error
The Rockchip efuse driver implements this so it should return the number of bytes read rather than zero on success. Fix this so that the driver follows the usual contract for read operations.
---
v3: unchanged
v2:
- Fix when block_size > 1 by moving the return value to the main rockchip_efuse_read() wrapper and leaving the individual implementations alone (Jonas)
drivers/misc/rockchip-efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/misc/rockchip-efuse.c +8 -4
@@ -73,7 +73,7 @@ static int dump_efuse(struct cmd_tbl *cmdtp, int flag,for (i =0 ; true; i +=sizeof (data)) { ret =misc_read (dev, i, &data,sizeof (data)); -if (ret <0 ) +if (ret <=0 )return 0 ;print_buffer (i, data,1 ,sizeof (data),sizeof (data));
@@ -238,8 +238,10 @@ static int rockchip_efuse_read(struct udevice *dev, int offset, offset += data->offset; -if (data->block_size <=1 ) -return data->read (dev, offset, buf, size); +if (data->block_size <=1 ) { + ret = data->read (dev, offset, buf, size); + goto done; + } block_start = offset / data->block_size; block_offset = offset % data->block_size;
@@ -255,7 +257,9 @@ static int rockchip_efuse_read(struct udevice *dev, int offset,memcpy (buf, buffer + block_offset, size);free (buffer); -return ret; + +done: +return ret <0 ? ret : size; }static const struct misc_ops rockchip_efuse_ops = {
Signature · 1 line
2.40.0
Re: [PATCH v3 2/3] rockchip: efuse: fix misc_read() return values
Quoted 11 lines · John Keeping
The documentation for
misc_read()says:Return: number of bytes read if OK (may be 0 if EOF), -ve on error
The Rockchip efuse driver implements this so it should return the number of bytes read rather than zero on success. Fix this so that the driver follows the usual contract for read operations.
Reviewed-by Simon Glass <[email protected]>Reviewed-by Jonas Karlman <[email protected]>Signed-off-by John Keeping <[email protected]>
Thanks,
- Kever
Quoted 47 lines
---
v3: unchanged
v2:
- Fix whenblock_size> 1 by moving the return value to the mainrockchip_efuse_read()wrapper and leaving the individual implementations alone (Jonas)drivers/misc/rockchip-efuse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/misc/rockchip-efuse.c +8
-4@@ -73,7 +73,7 @@ static int dump_efuse(struct cmd_tbl *cmdtp, int flag,for (i =0 ; true; i +=sizeof (data)) { ret =misc_read (dev, i, &data,sizeof (data)); -if (ret <0 ) +if (ret <=0 )return 0 ;print_buffer (i, data,1 ,sizeof (data),sizeof (data));@@ -238,8 +238,10 @@ static int rockchip_efuse_read(struct udevice *dev, int offset, offset += data->offset; -if (data->block_size <=1 ) -return data->read (dev, offset, buf, size); +if (data->block_size <=1 ) { + ret = data->read (dev, offset, buf, size); + goto done; + } block_start = offset / data->block_size; block_offset = offset % data->block_size;@@ -255,7 +257,9 @@ static int rockchip_efuse_read(struct udevice *dev, int offset,memcpy (buf, buffer + block_offset, size);free (buffer); -return ret; + +done: +return ret <0 ? ret : size; }static const struct misc_ops rockchip_efuse_ops = {
PATCH v3 3/3 rockchip: otp: fix misc_read() return values
In reply to John KeepingThe documentation for misc_read() says:
Return: number of bytes read if OK (may be 0 if EOF), -ve on error
The Rockchip efuse driver implements this so it should return the number of bytes read rather than zero on success. Fix this so that the driver follows the usual contract for read operations.
---
v3: unchanged
v2: new patch
drivers/misc/rockchip-otp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/misc/rockchip-otp.c +8 -4
@@ -89,7 +89,7 @@ static int dump_otp(struct cmd_tbl *cmdtp, int flag,for (i =0 ; true; i +=sizeof (data)) { ret =misc_read (dev, i, &data,sizeof (data)); -if (ret <0 ) +if (ret <=0 )return 0 ;print_buffer (i, data,1 ,sizeof (data),sizeof (data));
@@ -249,8 +249,10 @@ static int rockchip_otp_read(struct udevice *dev, int offset, offset += data->offset; -if (data->block_size <=1 ) -return data->read (dev, offset, buf, size); +if (data->block_size <=1 ) { + ret = data->read (dev, offset, buf, size); + goto done; + } block_start = offset / data->block_size; block_offset = offset % data->block_size;
@@ -266,7 +268,9 @@ static int rockchip_otp_read(struct udevice *dev, int offset,memcpy (buf, buffer + block_offset, size);free (buffer); -return ret; + +done: +return ret <0 ? ret : size; }static const struct misc_ops rockchip_otp_ops = {
Signature · 1 line
2.40.0
Re: [PATCH v3 3/3] rockchip: otp: fix misc_read() return values
Quoted 11 lines · John Keeping
The documentation for
misc_read()says:Return: number of bytes read if OK (may be 0 if EOF), -ve on error
The Rockchip efuse driver implements this so it should return the number of bytes read rather than zero on success. Fix this so that the driver follows the usual contract for read operations.
Reviewed-by Simon Glass <[email protected]>Reviewed-by Jonas Karlman <[email protected]>Signed-off-by John Keeping <[email protected]>
Thanks,
- Kever
Quoted 44 lines
---
v3: unchanged
v2: new patchdrivers/misc/rockchip-otp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/misc/rockchip-otp.c +8
-4@@ -89,7 +89,7 @@ static int dump_otp(struct cmd_tbl *cmdtp, int flag,for (i =0 ; true; i +=sizeof (data)) { ret =misc_read (dev, i, &data,sizeof (data)); -if (ret <0 ) +if (ret <=0 )return 0 ;print_buffer (i, data,1 ,sizeof (data),sizeof (data));@@ -249,8 +249,10 @@ static int rockchip_otp_read(struct udevice *dev, int offset, offset += data->offset; -if (data->block_size <=1 ) -return data->read (dev, offset, buf, size); +if (data->block_size <=1 ) { + ret = data->read (dev, offset, buf, size); + goto done; + } block_start = offset / data->block_size; block_offset = offset % data->block_size;@@ -266,7 +268,9 @@ static int rockchip_otp_read(struct udevice *dev, int offset,memcpy (buf, buffer + block_offset, size);free (buffer); -return ret; + +done: +return ret <0 ? ret : size; }static const struct misc_ops rockchip_otp_ops = {