[PATCH v3 2/3] rockchip: efuse: fix misc_read() return values

Kever Yang kever.yang at rock-chips.com
Fri Apr 14 10:51:03 CEST 2023


On 2023/3/27 19:01, John Keeping wrote:
> The documentation for misc_read() says:
>
>      Return: number of bytes read if OK (may be 0 if EOF), -ve on error
>
> The Rockchip efuse driver implements this so it should return the number
> of bytes read rather than zero on success.  Fix this so that the driver
> follows the usual contract for read operations.
>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Jonas Karlman <jonas at kwiboo.se>
> Signed-off-by: John Keeping <john at metanate.com>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>

Thanks,
- Kever
> ---
> v3: unchanged
> v2:
> - Fix when block_size > 1 by moving the return value to the main
>    rockchip_efuse_read() wrapper and leaving the individual
>    implementations alone (Jonas)
>
>   drivers/misc/rockchip-efuse.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c
> index 60931a5131..2f96b79ea4 100644
> --- a/drivers/misc/rockchip-efuse.c
> +++ b/drivers/misc/rockchip-efuse.c
> @@ -73,7 +73,7 @@ static int dump_efuse(struct cmd_tbl *cmdtp, int flag,
>   
>   	for (i = 0; true; i += sizeof(data)) {
>   		ret = misc_read(dev, i, &data, sizeof(data));
> -		if (ret < 0)
> +		if (ret <= 0)
>   			return 0;
>   
>   		print_buffer(i, data, 1, sizeof(data), sizeof(data));
> @@ -238,8 +238,10 @@ static int rockchip_efuse_read(struct udevice *dev, int offset,
>   
>   	offset += data->offset;
>   
> -	if (data->block_size <= 1)
> -		return data->read(dev, offset, buf, size);
> +	if (data->block_size <= 1) {
> +		ret = data->read(dev, offset, buf, size);
> +		goto done;
> +	}
>   
>   	block_start = offset / data->block_size;
>   	block_offset = offset % data->block_size;
> @@ -255,7 +257,9 @@ static int rockchip_efuse_read(struct udevice *dev, int offset,
>   		memcpy(buf, buffer + block_offset, size);
>   
>   	free(buffer);
> -	return ret;
> +
> +done:
> +	return ret < 0 ? ret : size;
>   }
>   
>   static const struct misc_ops rockchip_efuse_ops = {


More information about the U-Boot mailing list