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 3/8] hwmon: (pmbus/core) Use the new i2c_client debugfs directory
Date: Sat, 8 Feb 2025 17:26:12 -0800 [thread overview]
Message-ID: <20250209012617.944499-4-linux@roeck-us.net> (raw)
In-Reply-To: <20250209012617.944499-1-linux@roeck-us.net>
The I2C core now manages a debugfs directory per I2C client. PMBus has
its own debugfs hierarchy. Link the two, so a user will be pointed to
the I2C domain from the PMBus domain.
Suggested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/pmbus/pmbus_core.c | 63 +++++++++++++++++++++-----------
1 file changed, 41 insertions(+), 22 deletions(-)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 472375b62379..be794ba993b8 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -8,6 +8,7 @@
#include <linux/debugfs.h>
#include <linux/delay.h>
+#include <linux/dcache.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/module.h>
@@ -99,7 +100,6 @@ struct pmbus_data {
int num_attributes;
struct attribute_group group;
const struct attribute_group **groups;
- struct dentry *debugfs; /* debugfs device directory */
struct pmbus_sensor *sensors;
@@ -3497,34 +3497,49 @@ static const struct file_operations pmbus_debugfs_ops_mfr = {
.open = simple_open,
};
-static void pmbus_remove_debugfs(void *data)
+static void pmbus_remove_symlink(void *symlink)
{
- struct dentry *entry = data;
-
- debugfs_remove_recursive(entry);
+ debugfs_remove(symlink);
}
static int pmbus_init_debugfs(struct i2c_client *client,
struct pmbus_data *data)
{
- struct dentry *debugfs;
- int i, idx = 0;
- char name[PMBUS_NAME_SIZE];
+ struct dentry *symlink_d, *debugfs = client->debugfs;
struct pmbus_debugfs_entry *entries;
+ const char *pathname, *symlink;
+ char name[PMBUS_NAME_SIZE];
+ int i, idx = 0;
- if (!pmbus_debugfs_dir)
+ /*
+ * client->debugfs may be NULL or an ERR_PTR(). dentry_path_raw()
+ * does not check if its parameters are valid, so validate
+ * client->debugfs before using it.
+ */
+ if (!pmbus_debugfs_dir || IS_ERR_OR_NULL(debugfs))
return -ENODEV;
/*
- * Create the debugfs directory for this device. Use the hwmon device
- * name to avoid conflicts (hwmon numbers are globally unique).
+ * Backwards compatibility: Create symlink from /pmbus/<hwmon_device>
+ * to i2c debugfs directory.
*/
- debugfs = debugfs_create_dir(dev_name(data->hwmon_dev),
- pmbus_debugfs_dir);
- if (IS_ERR_OR_NULL(debugfs))
- return -ENODEV;
+ pathname = dentry_path_raw(debugfs, name, sizeof(name));
+ if (IS_ERR(pathname))
+ return PTR_ERR(pathname);
- data->debugfs = debugfs;
+ /*
+ * The path returned by dentry_path_raw() starts with '/'. Prepend it
+ * with ".." to get the symlink relative to the pmbus root directory.
+ */
+ symlink = kasprintf(GFP_KERNEL, "..%s", pathname);
+ if (!symlink)
+ return -ENOMEM;
+
+ symlink_d = debugfs_create_symlink(dev_name(data->hwmon_dev),
+ pmbus_debugfs_dir, symlink);
+ kfree(symlink);
+
+ devm_add_action_or_reset(data->dev, pmbus_remove_symlink, symlink_d);
/*
* Allocate the max possible entries we need.
@@ -3712,9 +3727,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
&pmbus_debugfs_ops);
}
}
-
- return devm_add_action_or_reset(data->dev, pmbus_remove_debugfs,
- debugfs);
+ return 0;
}
#else
static int pmbus_init_debugfs(struct i2c_client *client,
@@ -3819,9 +3832,15 @@ EXPORT_SYMBOL_NS_GPL(pmbus_do_probe, "PMBUS");
struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client)
{
- struct pmbus_data *data = i2c_get_clientdata(client);
-
- return data->debugfs;
+ /*
+ * client->debugfs may be an ERR_PTR(). Returning that to
+ * the calling code would potentially require additional
+ * complexity in the calling code and otherwise add no
+ * value. Return NULL in that case.
+ */
+ if (IS_ERR_OR_NULL(client->debugfs))
+ return NULL;
+ return client->debugfs;
}
EXPORT_SYMBOL_NS_GPL(pmbus_get_debugfs_dir, "PMBUS");
--
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 ` Guenter Roeck [this message]
2025-02-10 2:21 ` [PATCH 3/8] hwmon: (pmbus/core) Use the new i2c_client debugfs directory 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 ` [PATCH 6/8] hwmon: (pmbus/core) Optimize debugfs block data attribute initialization Guenter Roeck
2025-02-10 2:22 ` 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-4-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