Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5064119ybb; Tue, 24 Mar 2020 10:17:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvWTDl0CmLcOc7limUTV/k8BJdbuIUK99J0iVfvxzKw4prU2oIkFdcxoYG0egzrFzry/XyC X-Received: by 2002:a9d:228:: with SMTP id 37mr23847799otb.52.1585070245967; Tue, 24 Mar 2020 10:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585070245; cv=none; d=google.com; s=arc-20160816; b=lwSDyuy5jMjfpxU/+1S9cd6qOr1r6utuqcBHMsindR6RQTbczsyHhghgsE/udkkO5K qrbySzSj5qiWEHMkc+V/nwh9aN1So9oOlwRF2NR/pSC3xfAkIJgrfsh7T/HkwOrq19Kv n3baHOlBWx4dgG2cXo5eSItRS1U1Sd7XuiS8JWXC3nhgGJY/F4iQH5OVnMlyk3ab/LUs AJZ5vkPU+TG64lH+rlsH+OmLI+w/hxHmwYVIZdrSGdcHWMmDOaG+fdOV7jTzK0vOiK2T WGhkprsZuC9nV34+J7JOjq8tE/d1hMW4xa/PIGB31eg4L59eL0AlFkTsoMlmxt+tYnj7 53KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nNCOW9v2LJpxTzkezjzdYan/Qow8ukjHWizHnsEFt8w=; b=qnIzb0wByvIp6+EtViYBEbm+747y2Sx3up5ED5hlLU+rDMEKHd+wO0dWPaSdZwPxB4 9ISRuNUMYdsJ9aoMH8T+fgod/NyQCrNl3Asdp3/3G/T1xP+cLyiGmeUGy0tOdgsrufdL 3DePDEXEIHUIUndgazZosF7TXN9BfVkDaiuzaYac4AaMDaT5+O532gUechc6JPq7Tknm V8qjRZXA3MCAWijKAWmBbhjw/uOBonqEH11SdrI6XtnqxbvrvqFeFntOA50uZwJvCqVL XQ1hQlVLy+oGe2rR+x5Ea5T02UBWtAJwQ0wJ1w1SP7mAadbfzVDh1aDne0bVuz1DjOdk 9B2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Uy7n/9Qu"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si9459750oib.135.2020.03.24.10.17.13; Tue, 24 Mar 2020 10:17:25 -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=@linaro.org header.s=google header.b="Uy7n/9Qu"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbgCXRQW (ORCPT + 99 others); Tue, 24 Mar 2020 13:16:22 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51431 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727618AbgCXRQU (ORCPT ); Tue, 24 Mar 2020 13:16:20 -0400 Received: by mail-wm1-f68.google.com with SMTP id c187so4097709wme.1 for ; Tue, 24 Mar 2020 10:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nNCOW9v2LJpxTzkezjzdYan/Qow8ukjHWizHnsEFt8w=; b=Uy7n/9QuBGclxlJkPSkG2+4aWIAGdwaVC3V3c65zKIo4biiCJlaOE0d1eyjYEruJGO Cyuttehm5d+TywNg08a+jRVw/B9unVLI/ukfIpATGYVLyPZ/XuhNlzdCkinNpYN9vpLT 8YXlQNtg7BSDG2deZWFXHe8gDhGXo9l3JLGQ0cGu6bVAPBbm9b2eKaTP9bGNV/RaFElq fXSl29AqF5QZ1iMLTX301K5eJ+WNIJBjjKvLVY3mviVJJzvl8dy6kOdUcsMQnYNojcLo a6ZSMrt/Kjzi3c9+K+l3IiSJlZUUl06CUAnu4sI4U0iBJZAXxGvmE/PfsOHZvyw8Hmtb KfcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nNCOW9v2LJpxTzkezjzdYan/Qow8ukjHWizHnsEFt8w=; b=DiZXF75HmuWsp5+Eieqrb4I9+VDtvgBM5uztbPHBFldQEmqXLxWsDgu8UT/x42cSTe SVs+o2OYBV3lSlWfobPZO+3Yv5mqmH1t5hagMrGIwS4fOBs7ao/tjWHPDtXjqUjAGeGa gq8usdKuxwjgKk9K5bmtklkoWD0zaZHKPN4hBnbhvhcc6A1j4A7ec6Hz6kHV0mBUBatM vb3/++IPsre3l13AjPxEVGD2nbkAoBktuPybmT+JrClhQAFwC6h89N4juUM+9TRxhRTv kjT5ckXEleNUZgdqae/asXl1MmGNu7nM5KXBmlVLVSqy/OA3VBYjdpOU+JHbEI9I8TCM W/tg== X-Gm-Message-State: ANhLgQ3U7OuYRMN3YDfy9aj+ndyuBsUiSe5H98fNmjx9Nn2/JBaNVzx/ Y61XeugIaW/YNxDUnV3V006z7Q== X-Received: by 2002:a05:600c:24d2:: with SMTP id 18mr6554773wmu.38.1585070177481; Tue, 24 Mar 2020 10:16:17 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id m11sm5269514wmf.9.2020.03.24.10.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 10:16:16 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, nicholas.johnson-opensource@outlook.com.au, Srinivas Kandagatla Subject: [PATCH 3/3] nvmem: core: use is_bin_visible for permissions Date: Tue, 24 Mar 2020 17:16:00 +0000 Message-Id: <20200324171600.15606-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200324171600.15606-1-srinivas.kandagatla@linaro.org> References: <20200324171600.15606-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; +} /* default read/write permissions */ static struct bin_attribute bin_attr_rw_nvmem = { @@ -114,18 +125,19 @@ static struct bin_attribute bin_attr_rw_nvmem = { .write = bin_attr_nvmem_write, }; -static struct bin_attribute *nvmem_bin_rw_attributes[] = { +static struct bin_attribute *nvmem_bin_attributes[] = { &bin_attr_rw_nvmem, NULL, }; -static const struct attribute_group nvmem_bin_rw_group = { - .bin_attrs = nvmem_bin_rw_attributes, +static const struct attribute_group nvmem_bin_group = { + .bin_attrs = nvmem_bin_attributes, .attrs = nvmem_attrs, + .is_bin_visible = nvmem_bin_attr_is_visible, }; -static const struct attribute_group *nvmem_rw_dev_groups[] = { - &nvmem_bin_rw_group, +static const struct attribute_group *nvmem_dev_groups[] = { + &nvmem_bin_group, NULL, }; @@ -138,21 +150,6 @@ static struct bin_attribute bin_attr_ro_nvmem = { .read = bin_attr_nvmem_read, }; -static struct bin_attribute *nvmem_bin_ro_attributes[] = { - &bin_attr_ro_nvmem, - NULL, -}; - -static const struct attribute_group nvmem_bin_ro_group = { - .bin_attrs = nvmem_bin_ro_attributes, - .attrs = nvmem_attrs, -}; - -static const struct attribute_group *nvmem_ro_dev_groups[] = { - &nvmem_bin_ro_group, - NULL, -}; - /* default read/write permissions, root only */ static struct bin_attribute bin_attr_rw_root_nvmem = { .attr = { @@ -163,21 +160,6 @@ static struct bin_attribute bin_attr_rw_root_nvmem = { .write = bin_attr_nvmem_write, }; -static struct bin_attribute *nvmem_bin_rw_root_attributes[] = { - &bin_attr_rw_root_nvmem, - NULL, -}; - -static const struct attribute_group nvmem_bin_rw_root_group = { - .bin_attrs = nvmem_bin_rw_root_attributes, - .attrs = nvmem_attrs, -}; - -static const struct attribute_group *nvmem_rw_root_dev_groups[] = { - &nvmem_bin_rw_root_group, - NULL, -}; - /* read only permission, root only */ static struct bin_attribute bin_attr_ro_root_nvmem = { .attr = { @@ -187,31 +169,11 @@ static struct bin_attribute bin_attr_ro_root_nvmem = { .read = bin_attr_nvmem_read, }; -static struct bin_attribute *nvmem_bin_ro_root_attributes[] = { - &bin_attr_ro_root_nvmem, - NULL, -}; - -static const struct attribute_group nvmem_bin_ro_root_group = { - .bin_attrs = nvmem_bin_ro_root_attributes, - .attrs = nvmem_attrs, -}; - -static const struct attribute_group *nvmem_ro_root_dev_groups[] = { - &nvmem_bin_ro_root_group, - NULL, -}; - 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; } /* -- 2.21.0