From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
nicholas.johnson-opensource@outlook.com.au,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: [PATCH 3/3] nvmem: core: use is_bin_visible for permissions
Date: Tue, 24 Mar 2020 17:16:00 +0000 [thread overview]
Message-ID: <20200324171600.15606-4-srinivas.kandagatla@linaro.org> (raw)
In-Reply-To: <20200324171600.15606-1-srinivas.kandagatla@linaro.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 <gregkh@linuxfoundation.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
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
next prev parent reply other threads:[~2020-03-24 17:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 17:15 [PATCH 0/3] nvmem: use is_bin_visible callback Srinivas Kandagatla
2020-03-24 17:15 ` [PATCH 1/3] nvmem: core: use device_register and device_unregister Srinivas Kandagatla
2020-03-24 17:15 ` [PATCH 2/3] nvmem: core: add root_only member to nvmem device struct Srinivas Kandagatla
2020-03-24 17:16 ` Srinivas Kandagatla [this message]
2020-03-24 17:46 ` [PATCH 3/3] nvmem: core: use is_bin_visible for permissions Greg KH
2020-03-25 9:15 ` Srinivas Kandagatla
2020-03-24 23:05 ` Nicholas Johnson
2020-03-25 7:36 ` gregkh
2020-03-25 9:36 ` Srinivas Kandagatla
2020-03-24 17:58 ` [PATCH 0/3] nvmem: use is_bin_visible callback Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200324171600.15606-4-srinivas.kandagatla@linaro.org \
--to=srinivas.kandagatla@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicholas.johnson-opensource@outlook.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).