Skip to content

Commit de438ec

Browse files
committed
hwmon: (pmbus/core) Use the new i2c_client debugfs directory
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> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 6625a05 commit de438ec

1 file changed

Lines changed: 41 additions & 22 deletions

File tree

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/debugfs.h>
1010
#include <linux/delay.h>
11+
#include <linux/dcache.h>
1112
#include <linux/kernel.h>
1213
#include <linux/math64.h>
1314
#include <linux/module.h>
@@ -99,7 +100,6 @@ struct pmbus_data {
99100
int num_attributes;
100101
struct attribute_group group;
101102
const struct attribute_group **groups;
102-
struct dentry *debugfs; /* debugfs device directory */
103103

104104
struct pmbus_sensor *sensors;
105105

@@ -3496,34 +3496,49 @@ static const struct file_operations pmbus_debugfs_ops_mfr = {
34963496
.open = simple_open,
34973497
};
34983498

3499-
static void pmbus_remove_debugfs(void *data)
3499+
static void pmbus_remove_symlink(void *symlink)
35003500
{
3501-
struct dentry *entry = data;
3502-
3503-
debugfs_remove_recursive(entry);
3501+
debugfs_remove(symlink);
35043502
}
35053503

35063504
static int pmbus_init_debugfs(struct i2c_client *client,
35073505
struct pmbus_data *data)
35083506
{
3509-
struct dentry *debugfs;
3510-
int i, idx = 0;
3511-
char name[PMBUS_NAME_SIZE];
3507+
struct dentry *symlink_d, *debugfs = client->debugfs;
35123508
struct pmbus_debugfs_entry *entries;
3509+
const char *pathname, *symlink;
3510+
char name[PMBUS_NAME_SIZE];
3511+
int i, idx = 0;
35133512

3514-
if (!pmbus_debugfs_dir)
3513+
/*
3514+
* client->debugfs may be NULL or an ERR_PTR(). dentry_path_raw()
3515+
* does not check if its parameters are valid, so validate
3516+
* client->debugfs before using it.
3517+
*/
3518+
if (!pmbus_debugfs_dir || IS_ERR_OR_NULL(debugfs))
35153519
return -ENODEV;
35163520

35173521
/*
3518-
* Create the debugfs directory for this device. Use the hwmon device
3519-
* name to avoid conflicts (hwmon numbers are globally unique).
3522+
* Backwards compatibility: Create symlink from /pmbus/<hwmon_device>
3523+
* to i2c debugfs directory.
35203524
*/
3521-
debugfs = debugfs_create_dir(dev_name(data->hwmon_dev),
3522-
pmbus_debugfs_dir);
3523-
if (IS_ERR_OR_NULL(debugfs))
3524-
return -ENODEV;
3525+
pathname = dentry_path_raw(debugfs, name, sizeof(name));
3526+
if (IS_ERR(pathname))
3527+
return PTR_ERR(pathname);
3528+
3529+
/*
3530+
* The path returned by dentry_path_raw() starts with '/'. Prepend it
3531+
* with ".." to get the symlink relative to the pmbus root directory.
3532+
*/
3533+
symlink = kasprintf(GFP_KERNEL, "..%s", pathname);
3534+
if (!symlink)
3535+
return -ENOMEM;
3536+
3537+
symlink_d = debugfs_create_symlink(dev_name(data->hwmon_dev),
3538+
pmbus_debugfs_dir, symlink);
3539+
kfree(symlink);
35253540

3526-
data->debugfs = debugfs;
3541+
devm_add_action_or_reset(data->dev, pmbus_remove_symlink, symlink_d);
35273542

35283543
/*
35293544
* Allocate the max possible entries we need.
@@ -3711,9 +3726,7 @@ static int pmbus_init_debugfs(struct i2c_client *client,
37113726
&pmbus_debugfs_ops);
37123727
}
37133728
}
3714-
3715-
return devm_add_action_or_reset(data->dev, pmbus_remove_debugfs,
3716-
debugfs);
3729+
return 0;
37173730
}
37183731
#else
37193732
static int pmbus_init_debugfs(struct i2c_client *client,
@@ -3818,9 +3831,15 @@ EXPORT_SYMBOL_NS_GPL(pmbus_do_probe, "PMBUS");
38183831

38193832
struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client)
38203833
{
3821-
struct pmbus_data *data = i2c_get_clientdata(client);
3822-
3823-
return data->debugfs;
3834+
/*
3835+
* client->debugfs may be an ERR_PTR(). Returning that to
3836+
* the calling code would potentially require additional
3837+
* complexity in the calling code and otherwise add no
3838+
* value. Return NULL in that case.
3839+
*/
3840+
if (IS_ERR_OR_NULL(client->debugfs))
3841+
return NULL;
3842+
return client->debugfs;
38243843
}
38253844
EXPORT_SYMBOL_NS_GPL(pmbus_get_debugfs_dir, "PMBUS");
38263845

0 commit comments

Comments
 (0)