mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 10:33:41 +02:00
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: 13909a0c88 ("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>
This commit is contained in:
parent
094c276da6
commit
635c3a757a
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user