From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 6/8] hwmon: (pmbus/core) Optimize debugfs block data attribute initialization
Date: Sat, 8 Feb 2025 17:26:15 -0800 [thread overview]
Message-ID: <20250209012617.944499-7-linux@roeck-us.net> (raw)
In-Reply-To: <20250209012617.944499-1-linux@roeck-us.net>
Define debugfs attributes which need block data access in a data
structure and loop through it instead of creating debugfs files
one by one. This reduces code size and simplifies adding additional
attributes if needed.
While this is currently only used for manufacturer specific attributes,
the access code is generic and also works for other block attributes,
so rename operation functions from _mfg to _block.
While at it, rename the "revison" file to "pmbus_revision" to make its
meaning more obvious and to create a clear distinction against the
"mfg_revision" file.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/pmbus/pmbus_core.c | 85 +++++++++++---------------------
1 file changed, 29 insertions(+), 56 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 3085afc9c1ed..91dfb9ec9223 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -3461,8 +3461,8 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
NULL, "0x%04llx\n");
-static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t pmbus_debugfs_block_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
{
int rc;
struct pmbus_debugfs_entry *entry = file->private_data;
@@ -3487,9 +3487,9 @@ static ssize_t pmbus_debugfs_mfr_read(struct file *file, char __user *buf,
return simple_read_from_buffer(buf, count, ppos, data, rc);
}
-static const struct file_operations pmbus_debugfs_ops_mfr = {
+static const struct file_operations pmbus_debugfs_block_ops = {
.llseek = noop_llseek,
- .read = pmbus_debugfs_mfr_read,
+ .read = pmbus_debugfs_block_read,
.write = NULL,
.open = simple_open,
};
@@ -3499,6 +3499,20 @@ static void pmbus_remove_symlink(void *symlink)
debugfs_remove(symlink);
}
+struct pmbus_debugfs_data {
+ u8 reg;
+ const char *name;
+};
+
+static const struct pmbus_debugfs_data pmbus_debugfs_block_data[] = {
+ { .reg = PMBUS_MFR_ID, .name = "mfr_id" },
+ { .reg = PMBUS_MFR_MODEL, .name = "mfr_model" },
+ { .reg = PMBUS_MFR_REVISION, .name = "mfr_revision" },
+ { .reg = PMBUS_MFR_LOCATION, .name = "mfr_location" },
+ { .reg = PMBUS_MFR_DATE, .name = "mfr_date" },
+ { .reg = PMBUS_MFR_SERIAL, .name = "mfr_serial" },
+};
+
static void pmbus_init_debugfs(struct i2c_client *client,
struct pmbus_data *data)
{
@@ -3561,63 +3575,22 @@ static void pmbus_init_debugfs(struct i2c_client *client,
entries[idx].client = client;
entries[idx].page = 0;
entries[idx].reg = PMBUS_REVISION;
- debugfs_create_file("revision", 0444, debugfs,
+ debugfs_create_file("pmbus_revision", 0444, debugfs,
&entries[idx++],
&pmbus_debugfs_ops);
}
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_ID)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_ID;
- debugfs_create_file("mfr_id", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
- }
+ for (i = 0; i < ARRAY_SIZE(pmbus_debugfs_block_data); i++) {
+ const struct pmbus_debugfs_data *d = &pmbus_debugfs_block_data[i];
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_MODEL)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_MODEL;
- debugfs_create_file("mfr_model", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
- }
-
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_REVISION)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_REVISION;
- debugfs_create_file("mfr_revision", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
- }
-
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_LOCATION)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_LOCATION;
- debugfs_create_file("mfr_location", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
- }
-
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_DATE)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_DATE;
- debugfs_create_file("mfr_date", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
- }
-
- if (pmbus_check_block_register(client, 0, PMBUS_MFR_SERIAL)) {
- entries[idx].client = client;
- entries[idx].page = 0;
- entries[idx].reg = PMBUS_MFR_SERIAL;
- debugfs_create_file("mfr_serial", 0444, debugfs,
- &entries[idx++],
- &pmbus_debugfs_ops_mfr);
+ if (pmbus_check_block_register(client, 0, d->reg)) {
+ entries[idx].client = client;
+ entries[idx].page = 0;
+ entries[idx].reg = d->reg;
+ debugfs_create_file(d->name, 0444, debugfs,
+ &entries[idx++],
+ &pmbus_debugfs_block_ops);
+ }
}
/* Add page specific entries */
--
2.45.2
next prev parent reply other threads:[~2025-02-09 1:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-09 1:26 [PATCH 0/8] hwmon: (pmbus/core) Various fixes and improvements Guenter Roeck
2025-02-09 1:26 ` [PATCH 1/8] hwmon: (pmbus/core) Fix various coding style issues Guenter Roeck
2025-02-10 2:21 ` Tzung-Bi Shih
2025-02-09 1:26 ` [PATCH 2/8] hwmon: (pmbus/core) Use local debugfs variable in debugfs initialization Guenter Roeck
2025-02-10 2:21 ` Tzung-Bi Shih
2025-02-09 1:26 ` [PATCH 3/8] hwmon: (pmbus/core) Use the new i2c_client debugfs directory Guenter Roeck
2025-02-10 2:21 ` Tzung-Bi Shih
2025-02-09 1:26 ` [PATCH 4/8] hwmon: (pmbus/core) Make debugfs code unconditional Guenter Roeck
2025-02-10 2:22 ` Tzung-Bi Shih
2025-02-09 1:26 ` [PATCH 5/8] hwmon: (pmbus/core) Declare regulator notification function as void Guenter Roeck
2025-02-10 2:22 ` Tzung-Bi Shih
2025-02-09 1:26 ` Guenter Roeck [this message]
2025-02-10 2:22 ` [PATCH 6/8] hwmon: (pmbus/core) Optimize debugfs block data attribute initialization Tzung-Bi Shih
2025-02-10 2:21 ` [PATCH 0/8] hwmon: (pmbus/core) Various fixes and improvements Tzung-Bi Shih
2025-02-10 4:00 ` Guenter Roeck
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=20250209012617.944499-7-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-hwmon@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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