* [PATCH 0/2] i2c: core-managed per-client directory in debugfs with example @ 2025-01-09 12:21 Wolfram Sang 2025-01-09 12:21 ` [PATCH 1/2] i2c: add core-managed per-client directory in debugfs Wolfram Sang 2025-01-09 12:21 ` [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry Wolfram Sang 0 siblings, 2 replies; 6+ messages in thread From: Wolfram Sang @ 2025-01-09 12:21 UTC (permalink / raw) To: linux-renesas-soc Cc: Guenter Roeck, linux-kernel, Wolfram Sang, Carsten Spieß, Jean Delvare, linux-hwmon, linux-i2c I think there are enough i2c_drivers now using debugfs that it justifies a central handling of an debugfs entry per i2c client. Here is the I2C core code with an example conversion of the isl28022 driver. Quite convincing diffstat, I'd say. Tested on a Renesas RZ/G3S SMARC board. The branch is based on 6.13-rc6 plus 'i2c/for-mergewindow' plus 'hwmon/next' and can be found here: git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/g3s/isl28022 @Guenter: because both patches have dependencies in their respective for-next branches, I suggest that I'll apply the I2C core patch soon and resend the ISL patch during next merge window once my pull request is included. Does that sound okay to you? And once both are in, I will send further conversions as RFT patches aiming for 6.15? Looking forward to further comments as well! Happy hacking! Wolfram Sang (2): i2c: add core-managed per-client directory in debugfs hwmon: (isl28022) Use per-client debugfs entry drivers/hwmon/isl28022.c | 44 ++----------------------------------- drivers/i2c/i2c-core-base.c | 4 ++++ include/linux/i2c.h | 1 + 3 files changed, 7 insertions(+), 42 deletions(-) -- 2.45.2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] i2c: add core-managed per-client directory in debugfs 2025-01-09 12:21 [PATCH 0/2] i2c: core-managed per-client directory in debugfs with example Wolfram Sang @ 2025-01-09 12:21 ` Wolfram Sang 2025-01-09 15:29 ` Guenter Roeck 2025-01-14 11:59 ` Wolfram Sang 2025-01-09 12:21 ` [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry Wolfram Sang 1 sibling, 2 replies; 6+ messages in thread From: Wolfram Sang @ 2025-01-09 12:21 UTC (permalink / raw) To: linux-renesas-soc; +Cc: Guenter Roeck, linux-kernel, Wolfram Sang, linux-i2c More and more I2C client drivers use debugfs entries and currently they need to manage a subdir for their files on their own. This means inconsistent naming for these subdirs and they are scattered all over the debugfs-tree as well. Not to mention the duplicated code. Let the I2C core provide and maintain a proper directory per client. Note: It was considered to save the additional pointer in 'struct i2c_client' and only provide a subdir when requested via a helper function. When sketching this approach, more and more corner cases appeared, though, so the current solution with its simple and unabiguous code was chosen. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> --- drivers/i2c/i2c-core-base.c | 4 ++++ include/linux/i2c.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index b072030a9105..00f171ebc01f 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1015,6 +1015,8 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf if (status) goto out_remove_swnode; + client->debugfs = debugfs_create_dir(dev_name(&client->dev), adap->debugfs); + dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n", client->name, dev_name(&client->dev)); @@ -1058,6 +1060,8 @@ void i2c_unregister_device(struct i2c_client *client) if (ACPI_COMPANION(&client->dev)) acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev)); + + debugfs_remove_recursive(client->debugfs); device_remove_software_node(&client->dev); device_unregister(&client->dev); } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 66fb3d6cf686..36de788dc7fe 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -347,6 +347,7 @@ struct i2c_client { i2c_slave_cb_t slave_cb; /* callback for slave mode */ #endif void *devres_group_id; /* ID of probe devres group */ + struct dentry *debugfs; /* per-client debugfs dir */ }; #define to_i2c_client(d) container_of(d, struct i2c_client, dev) -- 2.45.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] i2c: add core-managed per-client directory in debugfs 2025-01-09 12:21 ` [PATCH 1/2] i2c: add core-managed per-client directory in debugfs Wolfram Sang @ 2025-01-09 15:29 ` Guenter Roeck 2025-01-14 11:59 ` Wolfram Sang 1 sibling, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2025-01-09 15:29 UTC (permalink / raw) To: Wolfram Sang; +Cc: linux-renesas-soc, linux-kernel, linux-i2c On Thu, Jan 09, 2025 at 01:21:10PM +0100, Wolfram Sang wrote: > More and more I2C client drivers use debugfs entries and currently they > need to manage a subdir for their files on their own. This means > inconsistent naming for these subdirs and they are scattered all over > the debugfs-tree as well. Not to mention the duplicated code. > > Let the I2C core provide and maintain a proper directory per client. > > Note: It was considered to save the additional pointer in 'struct > i2c_client' and only provide a subdir when requested via a helper > function. When sketching this approach, more and more corner cases > appeared, though, so the current solution with its simple and unabiguous > code was chosen. > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/i2c/i2c-core-base.c | 4 ++++ > include/linux/i2c.h | 1 + > 2 files changed, 5 insertions(+) > > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > index b072030a9105..00f171ebc01f 100644 > --- a/drivers/i2c/i2c-core-base.c > +++ b/drivers/i2c/i2c-core-base.c > @@ -1015,6 +1015,8 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf > if (status) > goto out_remove_swnode; > > + client->debugfs = debugfs_create_dir(dev_name(&client->dev), adap->debugfs); > + > dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n", > client->name, dev_name(&client->dev)); > > @@ -1058,6 +1060,8 @@ void i2c_unregister_device(struct i2c_client *client) > > if (ACPI_COMPANION(&client->dev)) > acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev)); > + > + debugfs_remove_recursive(client->debugfs); > device_remove_software_node(&client->dev); > device_unregister(&client->dev); > } > diff --git a/include/linux/i2c.h b/include/linux/i2c.h > index 66fb3d6cf686..36de788dc7fe 100644 > --- a/include/linux/i2c.h > +++ b/include/linux/i2c.h > @@ -347,6 +347,7 @@ struct i2c_client { > i2c_slave_cb_t slave_cb; /* callback for slave mode */ > #endif > void *devres_group_id; /* ID of probe devres group */ > + struct dentry *debugfs; /* per-client debugfs dir */ > }; > #define to_i2c_client(d) container_of(d, struct i2c_client, dev) > > -- > 2.45.2 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] i2c: add core-managed per-client directory in debugfs 2025-01-09 12:21 ` [PATCH 1/2] i2c: add core-managed per-client directory in debugfs Wolfram Sang 2025-01-09 15:29 ` Guenter Roeck @ 2025-01-14 11:59 ` Wolfram Sang 1 sibling, 0 replies; 6+ messages in thread From: Wolfram Sang @ 2025-01-14 11:59 UTC (permalink / raw) To: linux-renesas-soc; +Cc: Guenter Roeck, linux-kernel, linux-i2c [-- Attachment #1: Type: text/plain, Size: 832 bytes --] On Thu, Jan 09, 2025 at 01:21:10PM +0100, Wolfram Sang wrote: > More and more I2C client drivers use debugfs entries and currently they > need to manage a subdir for their files on their own. This means > inconsistent naming for these subdirs and they are scattered all over > the debugfs-tree as well. Not to mention the duplicated code. > > Let the I2C core provide and maintain a proper directory per client. > > Note: It was considered to save the additional pointer in 'struct > i2c_client' and only provide a subdir when requested via a helper > function. When sketching this approach, more and more corner cases > appeared, though, so the current solution with its simple and unabiguous > code was chosen. > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Applied to for-next, thanks! [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry 2025-01-09 12:21 [PATCH 0/2] i2c: core-managed per-client directory in debugfs with example Wolfram Sang 2025-01-09 12:21 ` [PATCH 1/2] i2c: add core-managed per-client directory in debugfs Wolfram Sang @ 2025-01-09 12:21 ` Wolfram Sang 2025-01-09 15:30 ` Guenter Roeck 1 sibling, 1 reply; 6+ messages in thread From: Wolfram Sang @ 2025-01-09 12:21 UTC (permalink / raw) To: linux-renesas-soc Cc: Guenter Roeck, linux-kernel, Wolfram Sang, Carsten Spieß, Jean Delvare, linux-hwmon The I2C core now offers a debugfs-directory per client. Use it and remove the custom handling. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> --- drivers/hwmon/isl28022.c | 44 ++-------------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c index 3f9b4520b53e..1fb9864635db 100644 --- a/drivers/hwmon/isl28022.c +++ b/drivers/hwmon/isl28022.c @@ -324,26 +324,6 @@ static int shunt_voltage_show(struct seq_file *seqf, void *unused) } DEFINE_SHOW_ATTRIBUTE(shunt_voltage); -static struct dentry *isl28022_debugfs_root; - -static void isl28022_debugfs_remove(void *res) -{ - debugfs_remove_recursive(res); -} - -static void isl28022_debugfs_init(struct i2c_client *client, struct isl28022_data *data) -{ - char name[16]; - struct dentry *debugfs; - - scnprintf(name, sizeof(name), "%d-%04hx", client->adapter->nr, client->addr); - - debugfs = debugfs_create_dir(name, isl28022_debugfs_root); - debugfs_create_file("shunt_voltage", 0444, debugfs, data, &shunt_voltage_fops); - - devm_add_action_or_reset(&client->dev, isl28022_debugfs_remove, debugfs); -} - /* * read property values and make consistency checks. * @@ -475,7 +455,7 @@ static int isl28022_probe(struct i2c_client *client) if (err) return err; - isl28022_debugfs_init(client, data); + debugfs_create_file("shunt_voltage", 0444, client->debugfs, data, &shunt_voltage_fops); hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, &isl28022_chip_info, NULL); @@ -505,27 +485,7 @@ static struct i2c_driver isl28022_driver = { .probe = isl28022_probe, .id_table = isl28022_ids, }; - -static int __init isl28022_init(void) -{ - int err; - - isl28022_debugfs_root = debugfs_create_dir("isl28022", NULL); - err = i2c_add_driver(&isl28022_driver); - if (!err) - return 0; - - debugfs_remove_recursive(isl28022_debugfs_root); - return err; -} -module_init(isl28022_init); - -static void __exit isl28022_exit(void) -{ - i2c_del_driver(&isl28022_driver); - debugfs_remove_recursive(isl28022_debugfs_root); -} -module_exit(isl28022_exit); +module_i2c_driver(isl28022_driver); MODULE_AUTHOR("Carsten Spieß <mail@carsten-spiess.de>"); MODULE_DESCRIPTION("ISL28022 driver"); -- 2.45.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry 2025-01-09 12:21 ` [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry Wolfram Sang @ 2025-01-09 15:30 ` Guenter Roeck 0 siblings, 0 replies; 6+ messages in thread From: Guenter Roeck @ 2025-01-09 15:30 UTC (permalink / raw) To: Wolfram Sang Cc: linux-renesas-soc, linux-kernel, Carsten Spieß, Jean Delvare, linux-hwmon On Thu, Jan 09, 2025 at 01:21:11PM +0100, Wolfram Sang wrote: > The I2C core now offers a debugfs-directory per client. Use it and > remove the custom handling. > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> For my reference: Reviewed-by: Guenter Roeck <linux@roeck-us.net> Guenter ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-01-14 11:59 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-09 12:21 [PATCH 0/2] i2c: core-managed per-client directory in debugfs with example Wolfram Sang 2025-01-09 12:21 ` [PATCH 1/2] i2c: add core-managed per-client directory in debugfs Wolfram Sang 2025-01-09 15:29 ` Guenter Roeck 2025-01-14 11:59 ` Wolfram Sang 2025-01-09 12:21 ` [PATCH 2/2] hwmon: (isl28022) Use per-client debugfs entry Wolfram Sang 2025-01-09 15:30 ` Guenter Roeck
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).