i2c: add core-managed per-client directory in debugfs
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 9 Jan 2025 12:21:10 +0000 (13:21 +0100)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Tue, 14 Jan 2025 12:02:11 +0000 (13:02 +0100)
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
include/linux/i2c.h

index b072030a9105ad5c4a299b0422ec716eea6165ca..00f171ebc01f12fbc9675f9d84982d825b2ed2e3 100644 (file)
@@ -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);
 }
index 66fb3d6cf686c71f624ac50d63e2f2e3daf84a60..36de788dc7fe6103df8435d746b6c9aef2e635da 100644 (file)
@@ -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)