[PATCH] crypto: atmel-sha204a - Fix error codes in OTP reads
Lothar Rubusch
l.rubusch at gmail.com
Sun Feb 22 09:03:16 PST 2026
Hi, find some comments below inlined.
On Sun, Feb 15, 2026 at 9:52 PM Thorsten Blum <thorsten.blum at linux.dev> wrote:
>
> 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 at vger.kernel.org
> Fixes: e05ce444e9e5 ("crypto: atmel-sha204a - add reading from otp zone")
> Signed-off-by: Thorsten Blum <thorsten.blum at linux.dev>
> ---
> Compile-tested only.
> ---
> drivers/crypto/atmel-i2c.c | 4 ++--
> drivers/crypto/atmel-sha204a.c | 7 ++++---
> 2 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c
> index 9688d116d07e..ba9d3f593601 100644
> --- a/drivers/crypto/atmel-i2c.c
> +++ b/drivers/crypto/atmel-i2c.c
> @@ -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;
> diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c
> index 0fcf4a39de27..6b4e2764523e 100644
> --- a/drivers/crypto/atmel-sha204a.c
> +++ b/drivers/crypto/atmel-sha204a.c
> @@ -94,9 +94,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;
Since I2C bus errors are caught here.
> @@ -106,7 +107,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;
The cmd.data holding 0xff here is not a bus error. AFAIR it can have
to do with the locking state, pre-initialization,
typically the atmel watchdog kicked in / timeout, etc - so the
response is invalid, although hardware connection (I2C) is
supposed to work. Currently the caller of this function does not
distinguish anyway.
But why is EIO preferable here, over EINVAL?
> }
>
> memcpy(otp, cmd.data+1, 4);
> --
> Thorsten Blum <thorsten.blum at linux.dev>
> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
>
More information about the linux-arm-kernel
mailing list