Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp349731ybb; Wed, 25 Mar 2020 00:37:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvrZUaCIoa5D65LxRgqWpkS9Ec86Jp+A6Dz+3HWKY2Myk5A0xHAr7gD+hpLbWV0yiwxEXFs X-Received: by 2002:a9d:6b85:: with SMTP id b5mr1500600otq.101.1585121852412; Wed, 25 Mar 2020 00:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585121852; cv=none; d=google.com; s=arc-20160816; b=wKEMEKiZKOqtKFfInZOe7U462bR/UA8FvVF5pipo+QsDSypaT+uM/PUOEUYbOnQ4ZK 0kKlQfS2oMGO45N0UjdrnJ0tyWN7Nfb/PInMCy2BUjoamc50dYV43qcUwDqQOzicy++u LNro8OSqeYExNGANcG3e0ZCto/QSnqaXIOHXI4SnmN7XNxe7kcpWJWpW088VhIuCnp3j 2yqUi9FBiIhAmrElNqdVha2vr73dzSA2HfopCS56BTacCoypiuU+WxmC79I6XQp+7+5b qYxdzRK9YZ+yPV32Bcq5BLwk744oA38Z3F0i3839XYIVa3qLgq3t+5dsqCx4lz27OVf7 JF8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YmRstWliax+HTd12P9/5HHY+fM06e4+ZcK3ECCXwVfs=; b=WDRdCVDdGTvFSovYKsW61TanwfgJcTQPT4b3X5uQi25OsWiFvyq3kf9uYYdixwilJo gAYoSDajzgaxHVBLVLucM9A65Cy6BSWQhtX4Vd3xZbVAkqXPWDScyBP/Ip930lWJhU9n q0guUOeCO+hV5PyziU8tH8YXUBONmmZFSFsZVo2UK0RXIAHYCAwMPxHRofcjIByznRn9 jlFP8RDSEqNLdbT92kZwpdR6nZqHRm7wkdx+fRm4R84RjY6G4VJ3aUISQez1qdE2ntcS BXURYJv/IqdQBX7A6kfmpIocHRqZnLr5nhW1nlnnSgrVkewr3b5ccHJwf819gEKLJMuh 9UFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IJ+K28Cj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g81si10155077oia.8.2020.03.25.00.37.20; Wed, 25 Mar 2020 00:37:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IJ+K28Cj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbgCYHhA (ORCPT + 99 others); Wed, 25 Mar 2020 03:37:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:38290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgCYHg7 (ORCPT ); Wed, 25 Mar 2020 03:36:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A40C92051A; Wed, 25 Mar 2020 07:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585121819; bh=KFHVOj3TQ5nDXf7jm3X9jRhbM3EIINnqrMU+w1cIYWY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IJ+K28CjFmrvTBzuky+gQfJF0tQggxOXPEJMqNUKLjJbWhzrbs8dwWIzNyYea1DHX Pf+epF0xPc+FuR+54ReOUHR/iAl0axw7tj6Jff2j41yeYeQg3rWZRuneLBAYkDggSk kdGbwzCWMer9pO9io56ay18RBTA70s6Kyh37w+K4= Date: Wed, 25 Mar 2020 08:36:56 +0100 From: "gregkh@linuxfoundation.org" To: Nicholas Johnson Cc: Srinivas Kandagatla , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 3/3] nvmem: core: use is_bin_visible for permissions Message-ID: <20200325073656.GA2985010@kroah.com> References: <20200324171600.15606-1-srinivas.kandagatla@linaro.org> <20200324171600.15606-4-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 24, 2020 at 11:05:07PM +0000, Nicholas Johnson wrote: > 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 > > Signed-off-by: Srinivas Kandagatla > > --- > > 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; > > +} > Looks like I did a pretty good job as I arrived at a similar result > independently. Even added root_only to nvmem_device. You beat me to it. > :) > > > 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; > > - > > - return nvmem->read_only ? nvmem_ro_dev_groups : nvmem_rw_dev_groups; > > + return nvmem_dev_groups; > > } > I was wondering if we can export nvmem_dev_group instead of this > nvmem_sysfs_get_groups() to fetch it. > > Also, we need some logic in nvmem_register() to abort if bad combination > is given (i.e. root_only set but no reg_read), as returning 0 in > is_bin_visible callback does not abort. I can do that in my patch if you > want. Returning 0 will cause the file to not be created at all, which is probably what you want, right? thanks, greg k-h