Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5092173ybb; Tue, 24 Mar 2020 10:48:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvZNTaNk00VWNPSCarnd0ekdA6Y8qUwDP5UgcaCDyKC0FnW0Pp3HXj5UEbuZ/s0d4SnjH4r X-Received: by 2002:aca:c390:: with SMTP id t138mr4122399oif.117.1585072108239; Tue, 24 Mar 2020 10:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585072108; cv=none; d=google.com; s=arc-20160816; b=DcQu895FJhvdWo095JFDjoo7Pkz/LIGbI81wyfKpCZmjHWpYZu344gsUaRLeGqjukw uNxxd9KfkuKSZardM09/7tEd6AbcB4wPNOddUzf815o2+S+t0J6oxSX737C72ndcuR6u hrilHd27EBmBU5EREmmWJm6q08/fk4wzDKTX+XLuyGm4HWSLHGX0adrvcCNye2VJVol2 DklggOR46Vy/apWrdO83wV//kFLy5nckEL+Z34W1iGYAmwCewP5o/Qbk6OO/vAHl6w2i 0nDoejeM0dn7KP6Zrjj5/QtQzLQ1Evbrz7fSwopWt/i/RQaxKzn7/y21BE3TUeww44MG OF/Q== 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=eNSNJjO7JMJPQ8sDTaX+eUo3ynrPJOgmuobuVtggDj8=; b=Eg15N5YuEq6U/57x6e2rUfJ5rfsds3Z3i0hg5mdbNVLW195thbgenuUYBg5yA8isag Wlv3NT3aZo4taCsPWlnjKggtamqNxrFyBu2aM5r+Clo67Tqure/L+cubFjuGvvXpb8cB 3QB6CPYkmZlArWNsIWOLVc/MqZnpBK1Qy2fiYsaOH7Rez4lFBruPLqa7AnhAMGj5Gvdr 7n9GDEozBuqGhMV+iOdmvDIvqiNF5KSiLkpxG2ll9jdS8/LZ8I5S0z+LYUtBKhMEwaDz v+i/+gO2lQiabEbSjbWzs/7Lo9aGp1ck9M15AWATgaly+uKhB358dLmgnrsbumaGe7yJ I5jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RX+rGI3K; 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 s139si9200416oih.7.2020.03.24.10.48.15; Tue, 24 Mar 2020 10:48:28 -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=RX+rGI3K; 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 S1727416AbgCXRqt (ORCPT + 99 others); Tue, 24 Mar 2020 13:46:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:34192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbgCXRqt (ORCPT ); Tue, 24 Mar 2020 13:46:49 -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 EA4AF206F6; Tue, 24 Mar 2020 17:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585072007; bh=obBvXsfoQJaST8AIFXbfAeXEKbif9Cn9RfiyBsQ/NFs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RX+rGI3K47uTHTYh9mjgx6P98/NTxlH0v7deLQCa1q3A251+Igvzk4GZRlV0y0M4n YTsDVH3JpsYT5//WkmN1iLiiNkSQYBnzRRK2cOv7sZXuvMObNl0RDADVPJ+3dJy37y SReYguBGIQCAYFymlsdwE7PkC/TUbejJkXlcTv9g= Date: Tue, 24 Mar 2020 18:46:42 +0100 From: Greg KH To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, nicholas.johnson-opensource@outlook.com.au Subject: Re: [PATCH 3/3] nvmem: core: use is_bin_visible for permissions Message-ID: <20200324174642.GA2524667@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: <20200324171600.15606-4-srinivas.kandagatla@linaro.org> 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 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; > +} 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