]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: atmel-sha204a - Fix OTP sysfs read and error handling
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 16 Feb 2026 07:45:51 +0000 (08:45 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 28 Feb 2026 03:54:14 +0000 (12:54 +0900)
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>
Reviewed-by: Lothar Rubusch <l.rubusch@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/atmel-sha204a.c

index 8f422ed223d32c31b4dda7c234d213e51494d7b6..72c9d74d3062ef68195fec4e82b19be7d6f79c17 100644 (file)
@@ -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"
 
@@ -121,21 +122,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);