From patchwork Tue Sep 8 12:07:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Emilio_L=C3=B3pez?= X-Patchwork-Id: 7140511 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3BC6CBEEC1 for ; Tue, 8 Sep 2015 12:09:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 655C4206E5 for ; Tue, 8 Sep 2015 12:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B6B0206EB for ; Tue, 8 Sep 2015 12:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754701AbbIHMI5 (ORCPT ); Tue, 8 Sep 2015 08:08:57 -0400 Received: from bhuna.collabora.co.uk ([93.93.135.160]:38237 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754246AbbIHMI4 (ORCPT ); Tue, 8 Sep 2015 08:08:56 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: emilio) with ESMTPSA id D2AEC5188042 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= To: gregkh@linuxfoundation.org, olof@lixom.net, kgene@kernel.org, k.kozlowski@samsung.com Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, =?UTF-8?q?Emilio=20L=C3=B3pez?= Subject: [PATCH 1/3] sysfs: Fix is_visible() support for binary attributes Date: Tue, 8 Sep 2015 09:07:44 -0300 Message-Id: <1441714066-5599-2-git-send-email-emilio.lopez@collabora.co.uk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441714066-5599-1-git-send-email-emilio.lopez@collabora.co.uk> References: <1441714066-5599-1-git-send-email-emilio.lopez@collabora.co.uk> MIME-Version: 1.0 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 adds the code paths required to support is_visible() on binary attributes. Signed-off-by: Emilio López --- fs/sysfs/group.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 39a0199..eb6996a 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -37,10 +37,10 @@ static int create_files(struct kernfs_node *parent, struct kobject *kobj, { struct attribute *const *attr; struct bin_attribute *const *bin_attr; - int error = 0, i; + int error = 0, i = 0; if (grp->attrs) { - for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) { + for (attr = grp->attrs; *attr && !error; i++, attr++) { umode_t mode = (*attr)->mode; /* @@ -73,13 +73,27 @@ 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 (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_visible) { + mode = grp->is_visible(kobj, + &(*bin_attr)->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; error = sysfs_add_file_mode_ns(parent, &(*bin_attr)->attr, true, - (*bin_attr)->attr.mode, NULL); + mode, NULL); if (error) break; }