From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755396AbbINPeH (ORCPT ); Mon, 14 Sep 2015 11:34:07 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:34736 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752655AbbINPeF (ORCPT ); Mon, 14 Sep 2015 11:34:05 -0400 Subject: Re: [PATCH v2 1/3] sysfs: Support is_visible() on binary attributes To: =?UTF-8?Q?Emilio_L=c3=b3pez?= , gregkh@linuxfoundation.org, olof@lixom.net, kgene@kernel.org, k.kozlowski@samsung.com References: <1442234049-18637-1-git-send-email-emilio.lopez@collabora.co.uk> <1442234049-18637-2-git-send-email-emilio.lopez@collabora.co.uk> Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org From: Guenter Roeck Message-ID: <55F6E8E6.9030509@roeck-us.net> Date: Mon, 14 Sep 2015 08:33:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <1442234049-18637-2-git-send-email-emilio.lopez@collabora.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/14/2015 05:34 AM, Emilio López wrote: > According to the sysfs header file: > > "The returned value will replace static permissions defined in > struct attribute or struct bin_attribute." > > but this isn't the case, as is_visible is only called on struct attribute > only. This patch introduces a new is_bin_visible() function to implement > the same functionality for binary attributes, and updates documentation > accordingly. > > Signed-off-by: Emilio López Nitpick below, but otherwise looks ok to me. Reviewed-by: Guenter Roeck Guenter > --- > > Changes from v1: > - Don't overload is_visible, introduce is_bin_visible instead as > discussed on the list. > > fs/sysfs/group.c | 17 +++++++++++++++-- > include/linux/sysfs.h | 18 ++++++++++++++---- > 2 files changed, 29 insertions(+), 6 deletions(-) > > diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c > index 39a0199..51b56e6 100644 > --- a/fs/sysfs/group.c > +++ b/fs/sysfs/group.c > @@ -73,13 +73,26 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, > } > > if (grp->bin_attrs) { > - for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) { > + for (i = 0, bin_attr = grp->bin_attrs; *bin_attr; i++, bin_attr++) { > + umode_t mode = (*bin_attr)->attr.mode; > + > if (update) > kernfs_remove_by_name(parent, > (*bin_attr)->attr.name); > + if (grp->is_bin_visible) { > + mode = grp->is_bin_visible(kobj, *bin_attr, i); > + if (!mode) > + continue; > + } > + > + WARN(mode & ~(SYSFS_PREALLOC | 0664), > + "Attribute %s: Invalid permissions 0%o\n", > + (*bin_attr)->attr.name, mode); > + > + mode &= SYSFS_PREALLOC | 0664; Strictly speaking, the mode validation for binary attributes is new and logically separate. Should it be mentioned in the commit log, or even be a separate patch ? > error = sysfs_add_file_mode_ns(parent, > &(*bin_attr)->attr, true, > - (*bin_attr)->attr.mode, NULL); > + mode, NULL); > if (error) > break; > } > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h > index 9f65758..2f66050 100644 > --- a/include/linux/sysfs.h > +++ b/include/linux/sysfs.h > @@ -64,10 +64,18 @@ do { \ > * a new subdirectory with this name. > * @is_visible: Optional: Function to return permissions associated with an > * attribute of the group. Will be called repeatedly for each > - * attribute in the group. Only read/write permissions as well as > - * SYSFS_PREALLOC are accepted. Must return 0 if an attribute is > - * not visible. The returned value will replace static permissions > - * defined in struct attribute or struct bin_attribute. > + * non-binary attribute in the group. Only read/write > + * permissions as well as SYSFS_PREALLOC are accepted. Must > + * return 0 if an attribute is not visible. The returned value > + * will replace static permissions defined in struct attribute. > + * @is_bin_visible: > + * Optional: Function to return permissions associated with a > + * binary attribute of the group. Will be called repeatedly > + * for each binary attribute in the group. Only read/write > + * permissions as well as SYSFS_PREALLOC are accepted. Must > + * return 0 if a binary attribute is not visible. The returned > + * value will replace static permissions defined in > + * struct bin_attribute. > * @attrs: Pointer to NULL terminated list of attributes. > * @bin_attrs: Pointer to NULL terminated list of binary attributes. > * Either attrs or bin_attrs or both must be provided. > @@ -76,6 +84,8 @@ struct attribute_group { > const char *name; > umode_t (*is_visible)(struct kobject *, > struct attribute *, int); > + umode_t (*is_bin_visible)(struct kobject *, > + struct bin_attribute *, int); > struct attribute **attrs; > struct bin_attribute **bin_attrs; > }; > From mboxrd@z Thu Jan 1 00:00:00 1970 From: linux@roeck-us.net (Guenter Roeck) Date: Mon, 14 Sep 2015 08:33:58 -0700 Subject: [PATCH v2 1/3] sysfs: Support is_visible() on binary attributes In-Reply-To: <1442234049-18637-2-git-send-email-emilio.lopez@collabora.co.uk> References: <1442234049-18637-1-git-send-email-emilio.lopez@collabora.co.uk> <1442234049-18637-2-git-send-email-emilio.lopez@collabora.co.uk> Message-ID: <55F6E8E6.9030509@roeck-us.net> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On 09/14/2015 05:34 AM, Emilio L?pez wrote: > According to the sysfs header file: > > "The returned value will replace static permissions defined in > struct attribute or struct bin_attribute." > > but this isn't the case, as is_visible is only called on struct attribute > only. This patch introduces a new is_bin_visible() function to implement > the same functionality for binary attributes, and updates documentation > accordingly. > > Signed-off-by: Emilio L?pez Nitpick below, but otherwise looks ok to me. Reviewed-by: Guenter Roeck Guenter > --- > > Changes from v1: > - Don't overload is_visible, introduce is_bin_visible instead as > discussed on the list. > > fs/sysfs/group.c | 17 +++++++++++++++-- > include/linux/sysfs.h | 18 ++++++++++++++---- > 2 files changed, 29 insertions(+), 6 deletions(-) > > diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c > index 39a0199..51b56e6 100644 > --- a/fs/sysfs/group.c > +++ b/fs/sysfs/group.c > @@ -73,13 +73,26 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, > } > > if (grp->bin_attrs) { > - for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) { > + for (i = 0, bin_attr = grp->bin_attrs; *bin_attr; i++, bin_attr++) { > + umode_t mode = (*bin_attr)->attr.mode; > + > if (update) > kernfs_remove_by_name(parent, > (*bin_attr)->attr.name); > + if (grp->is_bin_visible) { > + mode = grp->is_bin_visible(kobj, *bin_attr, i); > + if (!mode) > + continue; > + } > + > + WARN(mode & ~(SYSFS_PREALLOC | 0664), > + "Attribute %s: Invalid permissions 0%o\n", > + (*bin_attr)->attr.name, mode); > + > + mode &= SYSFS_PREALLOC | 0664; Strictly speaking, the mode validation for binary attributes is new and logically separate. Should it be mentioned in the commit log, or even be a separate patch ? > error = sysfs_add_file_mode_ns(parent, > &(*bin_attr)->attr, true, > - (*bin_attr)->attr.mode, NULL); > + mode, NULL); > if (error) > break; > } > diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h > index 9f65758..2f66050 100644 > --- a/include/linux/sysfs.h > +++ b/include/linux/sysfs.h > @@ -64,10 +64,18 @@ do { \ > * a new subdirectory with this name. > * @is_visible: Optional: Function to return permissions associated with an > * attribute of the group. Will be called repeatedly for each > - * attribute in the group. Only read/write permissions as well as > - * SYSFS_PREALLOC are accepted. Must return 0 if an attribute is > - * not visible. The returned value will replace static permissions > - * defined in struct attribute or struct bin_attribute. > + * non-binary attribute in the group. Only read/write > + * permissions as well as SYSFS_PREALLOC are accepted. Must > + * return 0 if an attribute is not visible. The returned value > + * will replace static permissions defined in struct attribute. > + * @is_bin_visible: > + * Optional: Function to return permissions associated with a > + * binary attribute of the group. Will be called repeatedly > + * for each binary attribute in the group. Only read/write > + * permissions as well as SYSFS_PREALLOC are accepted. Must > + * return 0 if a binary attribute is not visible. The returned > + * value will replace static permissions defined in > + * struct bin_attribute. > * @attrs: Pointer to NULL terminated list of attributes. > * @bin_attrs: Pointer to NULL terminated list of binary attributes. > * Either attrs or bin_attrs or both must be provided. > @@ -76,6 +84,8 @@ struct attribute_group { > const char *name; > umode_t (*is_visible)(struct kobject *, > struct attribute *, int); > + umode_t (*is_bin_visible)(struct kobject *, > + struct bin_attribute *, int); > struct attribute **attrs; > struct bin_attribute **bin_attrs; > }; >