Skip to content

Commit d06905d

Browse files
author
Wolfram Sang
committed
i2c: add core-managed per-client directory in debugfs
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 <[email protected]> Reviewed-by: Guenter Roeck <[email protected]>
1 parent bfd74cd commit d06905d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *inf
10151015
if (status)
10161016
goto out_remove_swnode;
10171017

1018+
client->debugfs = debugfs_create_dir(dev_name(&client->dev), adap->debugfs);
1019+
10181020
dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n",
10191021
client->name, dev_name(&client->dev));
10201022

@@ -1058,6 +1060,8 @@ void i2c_unregister_device(struct i2c_client *client)
10581060

10591061
if (ACPI_COMPANION(&client->dev))
10601062
acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
1063+
1064+
debugfs_remove_recursive(client->debugfs);
10611065
device_remove_software_node(&client->dev);
10621066
device_unregister(&client->dev);
10631067
}

include/linux/i2c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ struct i2c_client {
347347
i2c_slave_cb_t slave_cb; /* callback for slave mode */
348348
#endif
349349
void *devres_group_id; /* ID of probe devres group */
350+
struct dentry *debugfs; /* per-client debugfs dir */
350351
};
351352
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
352353

0 commit comments

Comments
 (0)