public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling
@ 2026-02-16  7:45 Thorsten Blum
  2026-02-17 10:34 ` Hi Thorsten, Lothar Rubusch
  2026-02-28  8:48 ` [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-02-16  7:45 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Lothar Rubusch
  Cc: Thorsten Blum, stable, linux-crypto, linux-arm-kernel,
	linux-kernel

Fix otp_show() to read and print all 64 bytes of the OTP zone.
Previously, the loop only printed half of the OTP (32 bytes), and
partial output was returned on read errors.

Propagate the actual error from atmel_sha204a_otp_read() instead of
producing partial output.

Replace sprintf() with sysfs_emit_at(), which is preferred for
formatting sysfs output because it provides safer bounds checking.

Cc: stable@vger.kernel.org
Fixes: 13909a0c8897 ("crypto: atmel-sha204a - provide the otp content")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Compile-tested only.

Changes in v2:
- Return the total number of bytes written by sysfs_emit_at() after
  feedback from Lothar (thanks!)
- Link to v1: https://lore.kernel.org/lkml/20260215124125.465162-2-thorsten.blum@linux.dev/
---
 drivers/crypto/atmel-sha204a.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
index 0fcf4a39de27..8af767f903ea 100644
--- a/drivers/crypto/atmel-sha204a.c
+++ b/drivers/crypto/atmel-sha204a.c
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/scatterlist.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/workqueue.h>
 #include "atmel-i2c.h"
 
@@ -119,21 +120,22 @@ static ssize_t otp_show(struct device *dev,
 {
 	u16 addr;
 	u8 otp[OTP_ZONE_SIZE];
-	char *str = buf;
 	struct i2c_client *client = to_i2c_client(dev);
-	int i;
+	ssize_t len = 0;
+	int i, ret;
 
-	for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) {
-		if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) {
+	for (addr = 0; addr < OTP_ZONE_SIZE / 4; addr++) {
+		ret = atmel_sha204a_otp_read(client, addr, otp + addr * 4);
+		if (ret < 0) {
 			dev_err(dev, "failed to read otp zone\n");
-			break;
+			return ret;
 		}
 	}
 
-	for (i = 0; i < addr*2; i++)
-		str += sprintf(str, "%02X", otp[i]);
-	str += sprintf(str, "\n");
-	return str - buf;
+	for (i = 0; i < OTP_ZONE_SIZE; i++)
+		len += sysfs_emit_at(buf, len, "%02X", otp[i]);
+	len += sysfs_emit_at(buf, len, "\n");
+	return len;
 }
 static DEVICE_ATTR_RO(otp);
 
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


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

* Hi Thorsten,
  2026-02-16  7:45 [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Thorsten Blum
@ 2026-02-17 10:34 ` Lothar Rubusch
  2026-02-28  8:48 ` [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Lothar Rubusch @ 2026-02-17 10:34 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Herbert Xu, David S. Miller, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, stable, linux-crypto, linux-arm-kernel,
	linux-kernel

On Mon, Feb 16, 2026 at 8:46 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Fix otp_show() to read and print all 64 bytes of the OTP zone.
> Previously, the loop only printed half of the OTP (32 bytes), and
> partial output was returned on read errors.
>
> Propagate the actual error from atmel_sha204a_otp_read() instead of
> producing partial output.
>
> Replace sprintf() with sysfs_emit_at(), which is preferred for
> formatting sysfs output because it provides safer bounds checking.
>
> Cc: stable@vger.kernel.org
> Fixes: 13909a0c8897 ("crypto: atmel-sha204a - provide the otp content")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Compile-tested only.
>
> Changes in v2:
> - Return the total number of bytes written by sysfs_emit_at() after
>   feedback from Lothar (thanks!)
> - Link to v1: https://lore.kernel.org/lkml/20260215124125.465162-2-thorsten.blum@linux.dev/
> ---
>  drivers/crypto/atmel-sha204a.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
> index 0fcf4a39de27..8af767f903ea 100644
> --- a/drivers/crypto/atmel-sha204a.c
> +++ b/drivers/crypto/atmel-sha204a.c
> @@ -15,6 +15,7 @@
>  #include <linux/module.h>
>  #include <linux/scatterlist.h>
>  #include <linux/slab.h>
> +#include <linux/sysfs.h>
>  #include <linux/workqueue.h>
>  #include "atmel-i2c.h"
>
> @@ -119,21 +120,22 @@ static ssize_t otp_show(struct device *dev,
>  {
>         u16 addr;
>         u8 otp[OTP_ZONE_SIZE];
> -       char *str = buf;
>         struct i2c_client *client = to_i2c_client(dev);
> -       int i;
> +       ssize_t len = 0;
> +       int i, ret;
>
> -       for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) {
> -               if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) {
> +       for (addr = 0; addr < OTP_ZONE_SIZE / 4; addr++) {
> +               ret = atmel_sha204a_otp_read(client, addr, otp + addr * 4);
> +               if (ret < 0) {
>                         dev_err(dev, "failed to read otp zone\n");
> -                       break;
> +                       return ret;
>                 }
>         }
>
> -       for (i = 0; i < addr*2; i++)
> -               str += sprintf(str, "%02X", otp[i]);
> -       str += sprintf(str, "\n");
> -       return str - buf;
> +       for (i = 0; i < OTP_ZONE_SIZE; i++)
> +               len += sysfs_emit_at(buf, len, "%02X", otp[i]);
> +       len += sysfs_emit_at(buf, len, "\n");
> +       return len;
>  }
>  static DEVICE_ATTR_RO(otp);
>
> --
> Thorsten Blum <thorsten.blum@linux.dev>
> GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
>

I took the patch as of link below. I verified on the before described setup.
https://lore.kernel.org/lkml/20260216074552.656814-1-thorsten.blum@linux.dev/

worked, LGTM

Reviewed-by: Lothar Rubusch <l.rubusch@gmail.com>

Best,
L

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

* Re: [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling
  2026-02-16  7:45 [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Thorsten Blum
  2026-02-17 10:34 ` Hi Thorsten, Lothar Rubusch
@ 2026-02-28  8:48 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2026-02-28  8:48 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: David S. Miller, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
	Lothar Rubusch, stable, linux-crypto, linux-arm-kernel,
	linux-kernel

On Mon, Feb 16, 2026 at 08:45:51AM +0100, Thorsten Blum wrote:
> Fix otp_show() to read and print all 64 bytes of the OTP zone.
> Previously, the loop only printed half of the OTP (32 bytes), and
> partial output was returned on read errors.
> 
> Propagate the actual error from atmel_sha204a_otp_read() instead of
> producing partial output.
> 
> Replace sprintf() with sysfs_emit_at(), which is preferred for
> formatting sysfs output because it provides safer bounds checking.
> 
> Cc: stable@vger.kernel.org
> Fixes: 13909a0c8897 ("crypto: atmel-sha204a - provide the otp content")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Compile-tested only.
> 
> Changes in v2:
> - Return the total number of bytes written by sysfs_emit_at() after
>   feedback from Lothar (thanks!)
> - Link to v1: https://lore.kernel.org/lkml/20260215124125.465162-2-thorsten.blum@linux.dev/
> ---
>  drivers/crypto/atmel-sha204a.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2026-02-28  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16  7:45 [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Thorsten Blum
2026-02-17 10:34 ` Hi Thorsten, Lothar Rubusch
2026-02-28  8:48 ` [PATCH v2] crypto: atmel-sha204a - Fix OTP sysfs read and error handling Herbert Xu

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