Re: [PATCH] i2c: Fix core-managed per-client debugfs handling

Wolfram Sang
2025-01-27T20:28:39Z

[-- Attachment #1: Type: text/plain, Size: 1640 bytes --]

On Mon, Jan 27, 2025 at 07:39:38AM -0800, Guenter Roeck wrote:
> Per-driver debugfs entries are created in the device probe function and
> released in the device remove function. The common debugfs directory
> introduced with commit d06905d68610 ("i2c: add core-managed per-client
> directory in debugfs") is added when a device is registered, not when it
> is probed, and it is removed when the device is unregistered. As result,
> debugfs entries added by a driver are not deleted when a device remove
> function is called since that does not necessarily result in device
> unregistration. If the probe function is then called again, the debugfs
> entries will already exist, which will result in error messages such as
>
> debugfs: File 'test' in directory '3-0020' already present!
>
> if 'test' was a debugfs file created during the first call to probe().
>
> This is easy to reproduce by executing "modprobe -r" followed by "modprobe"
> with a driver using the debugfs pointer created by the i2c subsystem.
>
> The debugfs directory should be created when a device is probed, not when
> it is registered. It should be removed when the device is removed, not
> when it is unregistered. Change the code accordingly.
>
> Also clear the client->debugfs if creating the debugfs directory fails.
> This simplifies I2C client driver code if it needs to call dentry
> functions which do not validate dentry pointers passed as argument.
>
> Fixes: d06905d68610 ("i2c: add core-managed per-client directory in debugfs")
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Applied to for-current, thanks!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]