Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: atmel-sha204a - Fix OTP sysfs read and error handling

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>

authored by

Thorsten Blum and committed by
Herbert Xu
635c3a75 094c276d

+11 -9
+11 -9
drivers/crypto/atmel-sha204a.c
··· 15 15 #include <linux/module.h> 16 16 #include <linux/scatterlist.h> 17 17 #include <linux/slab.h> 18 + #include <linux/sysfs.h> 18 19 #include <linux/workqueue.h> 19 20 #include "atmel-i2c.h" 20 21 ··· 122 121 { 123 122 u16 addr; 124 123 u8 otp[OTP_ZONE_SIZE]; 125 - char *str = buf; 126 124 struct i2c_client *client = to_i2c_client(dev); 127 - int i; 125 + ssize_t len = 0; 126 + int i, ret; 128 127 129 - for (addr = 0; addr < OTP_ZONE_SIZE/4; addr++) { 130 - if (atmel_sha204a_otp_read(client, addr, otp + addr * 4) < 0) { 128 + for (addr = 0; addr < OTP_ZONE_SIZE / 4; addr++) { 129 + ret = atmel_sha204a_otp_read(client, addr, otp + addr * 4); 130 + if (ret < 0) { 131 131 dev_err(dev, "failed to read otp zone\n"); 132 - break; 132 + return ret; 133 133 } 134 134 } 135 135 136 - for (i = 0; i < addr*2; i++) 137 - str += sprintf(str, "%02X", otp[i]); 138 - str += sprintf(str, "\n"); 139 - return str - buf; 136 + for (i = 0; i < OTP_ZONE_SIZE; i++) 137 + len += sysfs_emit_at(buf, len, "%02X", otp[i]); 138 + len += sysfs_emit_at(buf, len, "\n"); 139 + return len; 140 140 } 141 141 static DEVICE_ATTR_RO(otp); 142 142