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 error codes in OTP reads

Return -EINVAL from atmel_i2c_init_read_otp_cmd() on invalid addresses
instead of -1. Since the OTP zone is accessed in 4-byte blocks, valid
addresses range from 0 to OTP_ZONE_SIZE / 4 - 1. Fix the bounds check
accordingly.

In atmel_sha204a_otp_read(), propagate the actual error code from
atmel_i2c_init_read_otp_cmd() instead of -1. Also, return -EIO instead
of -EINVAL when the device is not ready.

Cc: stable@vger.kernel.org
Fixes: e05ce444e9e5 ("crypto: atmel-sha204a - add reading from otp zone")
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
094c276d b7abbc8c

+6 -5
+2 -2
drivers/crypto/atmel-i2c.c
··· 72 72 73 73 int atmel_i2c_init_read_otp_cmd(struct atmel_i2c_cmd *cmd, u16 addr) 74 74 { 75 - if (addr < 0 || addr > OTP_ZONE_SIZE) 76 - return -1; 75 + if (addr >= OTP_ZONE_SIZE / 4) 76 + return -EINVAL; 77 77 78 78 cmd->word_addr = COMMAND; 79 79 cmd->opcode = OPCODE_READ;
+4 -3
drivers/crypto/atmel-sha204a.c
··· 95 95 static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp) 96 96 { 97 97 struct atmel_i2c_cmd cmd; 98 - int ret = -1; 98 + int ret; 99 99 100 - if (atmel_i2c_init_read_otp_cmd(&cmd, addr) < 0) { 100 + ret = atmel_i2c_init_read_otp_cmd(&cmd, addr); 101 + if (ret < 0) { 101 102 dev_err(&client->dev, "failed, invalid otp address %04X\n", 102 103 addr); 103 104 return ret; ··· 108 107 109 108 if (cmd.data[0] == 0xff) { 110 109 dev_err(&client->dev, "failed, device not ready\n"); 111 - return -EINVAL; 110 + return -EIO; 112 111 } 113 112 114 113 memcpy(otp, cmd.data+1, 4);