mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>
Cc: linux-kernel@vger.kernel.org, bingbu.cao@linux.intel.com
Subject: Re: [PATCH] nvmem: core: add sanity check in nvmem_device_read()
Date: Tue, 4 Aug 2020 11:03:26 +0100	[thread overview]
Message-ID: <0e8d60cf-7f8b-c6ab-4184-b869c16b603e@linaro.org> (raw)
In-Reply-To: <20200804095815.GF13316@paasikivi.fi.intel.com>



On 04/08/2020 10:58, Sakari Ailus wrote:
> 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?

We should probably move these sanity checks to a common place like 
nvmem_reg_read() and nvmem_reg_write(), so the callers need not 
duplicate the same!

--srini

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

  reply	other threads:[~2020-08-04 10:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-04  9:13 Bingbu Cao
2020-08-04  9:58 ` Sakari Ailus
2020-08-04 10:03   ` Srinivas Kandagatla [this message]
2020-08-04 10:44     ` Bingbu Cao
2020-08-04 10:56       ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e8d60cf-7f8b-c6ab-4184-b869c16b603e@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=bingbu.cao@intel.com \
    --cc=bingbu.cao@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®