All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/5] nvmem: Add support for write-only instances
Date: Tue, 24 Mar 2020 13:29:39 +0100	[thread overview]
Message-ID: <20200324122939.GA2348009@kroah.com> (raw)
In-Reply-To: <4820047d-9a99-749c-491d-dbb91a2f5447@linaro.org>

On Tue, Mar 24, 2020 at 12:24:00PM +0000, Srinivas Kandagatla wrote:
> 
> 
> On 23/03/2020 19:05, Greg KH wrote:
> > On Mon, Mar 23, 2020 at 03:00:07PM +0000, Srinivas Kandagatla wrote:
> > > From: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
> > > 
> > > There is at least one real-world use-case for write-only nvmem
> > > instances. Refer to 03cd45d2e219 ("thunderbolt: Prevent crash if
> > > non-active NVMem file is read").
> > > 
> > > Add support for write-only nvmem instances by adding attrs for 0200.
> > > 
> > > Change nvmem_register() to abort if NULL group is returned from
> > > nvmem_sysfs_get_groups().
> > > 
> > > Return NULL from nvmem_sysfs_get_groups() in invalid cases.
> > > 
> > > Signed-off-by: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
> > > Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> > > ---
> > >   drivers/nvmem/core.c        | 10 +++++--
> > >   drivers/nvmem/nvmem-sysfs.c | 56 +++++++++++++++++++++++++++++++------
> > >   2 files changed, 56 insertions(+), 10 deletions(-)
> > > 
> > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> > > index 77d890d3623d..ddc7be5149d5 100644
> > > --- a/drivers/nvmem/core.c
> > > +++ b/drivers/nvmem/core.c
> > > @@ -381,6 +381,14 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> > >   	nvmem->type = config->type;
> > >   	nvmem->reg_read = config->reg_read;
> > >   	nvmem->reg_write = config->reg_write;
> > > +	nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config);
> > > +	if (!nvmem->dev.groups) {
> > > +		ida_simple_remove(&nvmem_ida, nvmem->id);
> > > +		gpiod_put(nvmem->wp_gpio);
> > > +		kfree(nvmem);
> > > +		return ERR_PTR(-EINVAL);
> > > +	}
> > > +
> > >   	if (!config->no_of_node)
> > >   		nvmem->dev.of_node = config->dev->of_node;
> > > @@ -395,8 +403,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> > >   	nvmem->read_only = device_property_present(config->dev, "read-only") ||
> > >   			   config->read_only || !nvmem->reg_write;
> > > -	nvmem->dev.groups = nvmem_sysfs_get_groups(nvmem, config);
> > > -
> > >   	device_initialize(&nvmem->dev);
> > >   	dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
> > > diff --git a/drivers/nvmem/nvmem-sysfs.c b/drivers/nvmem/nvmem-sysfs.c
> > > index 8759c4470012..9728da948988 100644
> > > --- a/drivers/nvmem/nvmem-sysfs.c
> > > +++ b/drivers/nvmem/nvmem-sysfs.c
> > > @@ -202,16 +202,49 @@ static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
> > >   	NULL,
> > >   };
> > > +/* write only permission, root only */
> > > +static struct bin_attribute bin_attr_wo_root_nvmem = {
> > > +	.attr	= {
> > > +		.name	= "nvmem",
> > > +		.mode	= 0200,
> > > +	},
> > > +	.write	= bin_attr_nvmem_write,
> > > +};
> > 
> > You are adding a new sysfs file without a Documentation/ABI/ new entry
> > as well?
> 
> This is not a new file, we already have documentation for this file at
> ./Documentation/ABI/stable/sysfs-bus-nvmem
> 
> Thanks for dropping this patch, I did endup finding some issues with this
> patch.
> 
> replied to original patch on the list with CC.
> 
> > 
> > 
> > > +
> > > +static struct bin_attribute *nvmem_bin_wo_root_attributes[] = {
> > > +	&bin_attr_wo_root_nvmem,
> > > +	NULL,
> > > +};
> > > +
> > > +static const struct attribute_group nvmem_bin_wo_root_group = {
> > > +	.bin_attrs	= nvmem_bin_wo_root_attributes,
> > > +	.attrs		= nvmem_attrs,
> > > +};
> > > +
> > > +static const struct attribute_group *nvmem_wo_root_dev_groups[] = {
> > > +	&nvmem_bin_wo_root_group,
> > > +	NULL,
> > > +};
> > > +
> > >   const struct attribute_group **nvmem_sysfs_get_groups(
> > >   					struct nvmem_device *nvmem,
> > >   					const struct nvmem_config *config)
> > >   {
> > > -	if (config->root_only)
> > > -		return nvmem->read_only ?
> > > -			nvmem_ro_root_dev_groups :
> > > -			nvmem_rw_root_dev_groups;
> > > +	/* Read-only */
> > > +	if (nvmem->reg_read && (!nvmem->reg_write || nvmem->read_only))
> > > +		return config->root_only ?
> > > +			nvmem_ro_root_dev_groups : nvmem_ro_dev_groups;
> > > +
> > > +	/* Read-write */
> > > +	if (nvmem->reg_read && nvmem->reg_write && !nvmem->read_only)
> > > +		return config->root_only ?
> > > +			nvmem_rw_root_dev_groups : nvmem_rw_dev_groups;
> > > +
> > > +	/* Write-only, do not honour request for global writable entry */
> > > +	if (!nvmem->reg_read && nvmem->reg_write && !nvmem->read_only)
> > > +		return config->root_only ? nvmem_wo_root_dev_groups : NULL;
> > 
> > 
> > What is this supposed to be doing, I am totally lost.
> 
> I agree, its bit confusing to the reader, but it does work.
> 
> But the Idea here is :
> We ended up with providing different options like read-only,root-only to
> nvmem providers combined with read/write callbacks.
> With that, there are some cases which are totally invalid, existing code
> does very minimal check to ensure that before populating with correct
> attributes to sysfs file. One of such case is with thunderbolt provider
> which supports only write callback.
> 
> With this new checks in place these flags and callbacks are correctly
> validated, would result in correct file attributes.

Why this crazy set of different groups?  You can set the mode of a sysfs
file in the callback for when the file is about to be created, that's so
much simpler and is what it is for.  This feels really hacky and almost
impossible to follow :(

thanks,

greg k-h

  reply	other threads:[~2020-03-24 12:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 15:00 [PATCH 0/5] nvmem: patches (set 2) for 5.7 Srinivas Kandagatla
2020-03-23 15:00 ` [PATCH 1/5] nvmem: sprd: Fix the block lock operation Srinivas Kandagatla
2020-03-23 19:02   ` Greg KH
2020-03-23 15:00 ` [PATCH 2/5] nvmem: sprd: Optimize " Srinivas Kandagatla
2020-03-23 15:00 ` [PATCH 3/5] nvmem: sprd: Determine double data programming from device data Srinivas Kandagatla
2020-03-23 15:00 ` [PATCH 4/5] nvmem: mxs-ocotp: Use devm_add_action_or_reset() for cleanup Srinivas Kandagatla
2020-03-23 15:00 ` [PATCH 5/5] nvmem: Add support for write-only instances Srinivas Kandagatla
2020-03-23 19:05   ` Greg KH
2020-03-24  3:25     ` Nicholas Johnson
2020-03-24 12:24     ` Srinivas Kandagatla
2020-03-24 12:29       ` Greg KH [this message]
2020-03-24 13:25         ` Srinivas Kandagatla
2020-03-24 13:33           ` Greg KH
2020-03-24 14:24           ` Nicholas Johnson
2020-03-24 15:18             ` Greg KH
2020-03-24 15:59               ` Nicholas Johnson
2020-03-24 16:58             ` Srinivas Kandagatla
2020-03-23 19:06 ` [PATCH 0/5] nvmem: patches (set 2) for 5.7 Greg KH
2020-03-24 12:11   ` Srinivas Kandagatla

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=20200324122939.GA2348009@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicholas.johnson-opensource@outlook.com.au \
    --cc=srinivas.kandagatla@linaro.org \
    /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.