All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: Re: [PATCH v3 1/2] nvmem: Allow nvmem_sysfs_get_groups() to return NULL as error condition
Date: Tue, 10 Mar 2020 13:10:39 +0000	[thread overview]
Message-ID: <bc9c0714-6e21-4a6c-48ad-df3eb0cbb4a4@linaro.org> (raw)
In-Reply-To: <PSXP216MB0438C66F372D62AA71CFC04780FE0@PSXP216MB0438.KORP216.PROD.OUTLOOK.COM>



On 09/03/2020 17:49, Nicholas Johnson wrote:
> Currently, nvmem_register() does not check for NULL return from
> nvmem_sysfs_get_groups(), and hence nvmem_sysfs_get_groups() has to
> always return a valid group, even if it is given invalid inputs.
> 
> Add check in nvmem_register() to return an error if NULL group is given.
> 
> Signed-off-by: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
> ---
>   drivers/nvmem/core.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index ef326f243..f6cd8a56a 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -388,6 +388,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   			   config->read_only || !nvmem->reg_write;
>   
>   	nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config);
Code as it today will never return null so this patch belongs to the 
next patch where its possible to return null.

> +	if (!nvmem->dev.groups) {
> +		kfree(nvmem);

This is still leaking few more things here!
> +		return ERR_PTR(-EPERM);

Error code hear does not really reflect why it failed, we should return 
-EINVAL indicating that its invalid configuration.

--srini
> +	}
>   
>   	device_initialize(&nvmem->dev);
>   
> 

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 17:49 [PATCH v3 0/2] nvmem: Add support for write-only instances, and clean-up Nicholas Johnson
2020-03-09 17:49 ` [PATCH v3 1/2] nvmem: Allow nvmem_sysfs_get_groups() to return NULL as error condition Nicholas Johnson
2020-03-10 13:10   ` Srinivas Kandagatla [this message]
2020-03-09 17:50 ` [PATCH v3 2/2] nvmem: Add support for write-only instances Nicholas Johnson
2020-03-10  1:10   ` Nicholas Johnson
2020-03-10  2:45   ` Nicholas Johnson

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=bc9c0714-6e21-4a6c-48ad-df3eb0cbb4a4@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=nicholas.johnson-opensource@outlook.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.