lkml.org 
[lkml]   [2020]   [Aug]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] nvmem: core: add sanity check in nvmem_device_read()
Hi Bingbu,

Thank you for the patch.

On Tue, Aug 04, 2020 at 05:13:56PM +0800, Bingbu Cao wrote:
> nvmem_device_read() could be called directly once nvmem device
> registered, the sanity check should be done before call
> nvmem_reg_read() as cell and sysfs read did now.
>
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
> drivers/nvmem/core.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 927eb5f6003f..c9a77993f008 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1491,6 +1491,13 @@ int nvmem_device_read(struct nvmem_device *nvmem,
> if (!nvmem)
> return -EINVAL;
>
> + if (offset >= nvmem->size || bytes < nvmem->word_size)
> + return 0;
> +
> + if (bytes + offset > nvmem->size)
> + bytes = nvmem->size - offset;

The check is relevant for nvmem_device_write(), too.

There are also other ways to access nvmem devices such as nvmem_cell_read
and others alike. Should they be considered as well?

> +
> + bytes = round_down(bytes, nvmem->word_size);
> rc = nvmem_reg_read(nvmem, offset, buf, bytes);
>
> if (rc)

--
Kind regards,

Sakari Ailus

\
 
 \ /
  Last update: 2020-08-04 11:59    [W:0.050 / U:0.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site