lkml.org 
[lkml]   [2020]   [Mar]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 3/3] nvmem: core: use is_bin_visible for permissions
On Tue, Mar 24, 2020 at 05:16:00PM +0000, Srinivas Kandagatla wrote:
> By using is_bin_visible callback to set permissions will remove a large list
> of attribute groups. These group permissions can be dynamically derived in
> the callback.
>
> Suggested-by: Greg KH <gregkh@linuxfoundation.org>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
> drivers/nvmem/nvmem-sysfs.c | 74 +++++++++----------------------------
> 1 file changed, 18 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/nvmem/nvmem-sysfs.c b/drivers/nvmem/nvmem-sysfs.c
> index 8759c4470012..1ff1801048f6 100644
> --- a/drivers/nvmem/nvmem-sysfs.c
> +++ b/drivers/nvmem/nvmem-sysfs.c
> @@ -103,6 +103,17 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
>
> return count;
> }
> +static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj,
> + struct bin_attribute *attr, int i)
> +{
> + struct device *dev = container_of(kobj, struct device, kobj);
> + struct nvmem_device *nvmem = to_nvmem_device(dev);
> +
> + if (nvmem->root_only)
> + return nvmem->read_only ? 0400 : 0600;
> +
> + return nvmem->read_only ? 0444 : 0644;
> +}

I don't know why this is so hard for me to read, but how about this
instead:

static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj,
struct bin_attribute *attr, int i)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct nvmem_device *nvmem = to_nvmem_device(dev);
umode_t mode = 0400;

if (!nvmem->root_only)
mode |= 0044;

if (!nvmem->read_only)
mode |= 0200;

return mode;
}

Did I get the logic corect?
thanks,

greg k-h

\
 
 \ /
  Last update: 2020-03-24 18:47    [W:0.091 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site