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: e05ce444e9 ("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>
This commit is contained in:
Thorsten Blum 2026-02-15 21:51:53 +01:00 committed by Herbert Xu
parent b7abbc8c7a
commit 094c276da6
2 changed files with 6 additions and 5 deletions

View File

@ -72,8 +72,8 @@ EXPORT_SYMBOL(atmel_i2c_init_read_config_cmd);
int atmel_i2c_init_read_otp_cmd(struct atmel_i2c_cmd *cmd, u16 addr)
{
if (addr < 0 || addr > OTP_ZONE_SIZE)
return -1;
if (addr >= OTP_ZONE_SIZE / 4)
return -EINVAL;
cmd->word_addr = COMMAND;
cmd->opcode = OPCODE_READ;

View File

@ -95,9 +95,10 @@ static int atmel_sha204a_rng_read(struct hwrng *rng, void *data, size_t max,
static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
{
struct atmel_i2c_cmd cmd;
int ret = -1;
int ret;
if (atmel_i2c_init_read_otp_cmd(&cmd, addr) < 0) {
ret = atmel_i2c_init_read_otp_cmd(&cmd, addr);
if (ret < 0) {
dev_err(&client->dev, "failed, invalid otp address %04X\n",
addr);
return ret;
@ -107,7 +108,7 @@ static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
if (cmd.data[0] == 0xff) {
dev_err(&client->dev, "failed, device not ready\n");
return -EINVAL;
return -EIO;
}
memcpy(otp, cmd.data+1, 4);