lkml.org 
[lkml]   [2020]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v3 1/2] nvmem: Allow nvmem_sysfs_get_groups() to return NULL as error condition
From
Date


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);
>
>

\
 
 \ /
  Last update: 2020-03-10 14:11    [W:0.709 / U:0.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site