FAILED: patch "[PATCH] i2c: core: fix adapter debugfs creation" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 07d5fb537928aad4369aaff0cbae73ba38a719af
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071636-amusing-conduit-3c6b@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 07d5fb537928aad4369aaff0cbae73ba38a719af Mon Sep 17 00:00:00 2001
From: Johan Hovold <[email protected]>
Date: Mon, 11 May 2026 16:37:10 +0200
Subject: [PATCH] i2c: core: fix adapter debugfs creation
Clients can be registered from bus notifier callbacks so the debugfs directory needs to be created before registering the adapter as clients use that directory as their debugfs parent.
Move debugfs creation before adapter registration to avoid having clients create their debugfs directories in the debugfs root (which is also more likely to fail due to name collisions).
Note that failure to allocate the adapter name must now be handled explicitly as debugfs_create_dir() cannot handle a NULL name (unlike device_add() which returns an error).
drivers/i2c/i2c-core-base.c +10 -6
@@ -1557,7 +1557,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap) goto out_list; } -dev_set_name (&adap->dev,"i2c-%d" , adap->nr); + res =dev_set_name (&adap->dev,"i2c-%d" , adap->nr); +if (res) + goto err_remove_irq_domain; + adap->dev.bus = &i2c_bus_type; adap->dev.type = &i2c_adapter_type;device_initialize (&adap->dev);
@@ -1575,14 +1578,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap)pm_suspend_ignore_children (&adap->dev, true);pm_runtime_enable (&adap->dev); + adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root); + res =device_add (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto err_put_adap; + goto err_remove_debugfs; } - adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root); - res =i2c_setup_smbus_alert (adap);if (res) goto out_reg;
@@ -1606,13 +1609,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap) out_reg:i2c_deregister_clients (adap); -debugfs_remove_recursive (adap->debugfs);device_del (&adap->dev); +err_remove_debugfs: +debugfs_remove_recursive (adap->debugfs); err_put_adap:init_completion (&adap->dev_released);put_device (&adap->dev);wait_for_completion (&adap->dev_released); - +err_remove_irq_domain:i2c_host_notify_irq_teardown (adap); out_list:mutex_lock (&core_lock);
Sasha Levin
maintainerPATCH 1/4 i2c: core: fix irq domain leak on adapter registration failure
From: Johan Hovold <[email protected]>
[ Upstream commit 8ce19524e4cc2462685f596a6402fbd8fb984ab2 ]
Make sure to tear down the host notify irq domain on adapter registration failure to avoid leaking it.
This issue was flagged by Sashiko when reviewing another adapter registration fix.
Stable-dep-of: 07d5fb537928 ("i2c: core: fix adapter debugfs creation")
--- drivers/i2c/i2c-core-base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core-base.c +3 -1
@@ -1551,7 +1551,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) res =device_register (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto out_list; + goto err_remove_irq_domain; } adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root);
@@ -1599,6 +1599,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)init_completion (&adap->dev_released);device_unregister (&adap->dev);wait_for_completion (&adap->dev_released); +err_remove_irq_domain: +i2c_host_notify_irq_teardown (adap); out_list:mutex_lock (&core_lock);idr_remove (&i2c_adapter_idr, adap->nr);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 i2c: core: fix hang on adapter registration failure
From: Johan Hovold <[email protected]>
[ Upstream commit 3c7e164344e5bcf6f274bbf59a3274f5caad9bc1 ]
Clients may be registered from bus notifier callbacks when the adapter is registered. On a subsequent error during registration, the adapter references taken by such clients prevent the wait for the references to be released from ever completing.
Fix this by refactoring client deregistration and deregistering also on late adapter registration failures.
Stable-dep-of: 07d5fb537928 ("i2c: core: fix adapter debugfs creation")
--- drivers/i2c/i2c-core-base.c | 49 ++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-)
drivers/i2c/i2c-core-base.c +29 -20
@@ -63,6 +63,7 @@static DEFINE_MUTEX (core_lock);static DEFINE_IDR (i2c_adapter_idr); +static void i2c_deregister_clients (struct i2c_adapter *adap);static int i2c_detect (struct i2c_adapter *adapter,struct i2c_driver *driver);static DEFINE_STATIC_KEY_FALSE (i2c_trace_msg_key);
@@ -1595,6 +1596,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)return 0 ; out_reg: +i2c_deregister_clients (adap);debugfs_remove_recursive (adap->debugfs);init_completion (&adap->dev_released);device_unregister (&adap->dev);
@@ -1738,29 +1740,10 @@ static int __process_removed_adapter(struct device_driver *d, void *data)return 0 ; } -/** -* i2c_del_adapter - unregister I2C adapter -* @adap: the adapter being unregistered -* Context: can sleep -* -* This unregisters an I2C adapter which was previously registered -* by @i2c_add_adapter or @i2c_add_numbered_adapter. -*/ -void i2c_del_adapter (struct i2c_adapter *adap) +static void i2c_deregister_clients (struct i2c_adapter *adap) { -struct i2c_adapter *found;struct i2c_client *client, *next; -/* First make sure that this adapter was ever added */ -mutex_lock (&core_lock); - found =idr_find (&i2c_adapter_idr, adap->nr); -mutex_unlock (&core_lock); -if (found != adap) { -pr_debug ("attempting to delete unregistered adapter [%s]\n" , adap->name); -return ; - } - -i2c_acpi_remove_space_handler (adap);/* Tell drivers about this removal */ mutex_lock (&core_lock); bus_for_each_drv(&i2c_bus_type, NULL, adap,
@@ -1786,6 +1769,32 @@ void i2c_del_adapter(struct i2c_adapter *adap)* them up properly, so we give them a chance to do that first. */ device_for_each_child (&adap->dev,NULL , __unregister_client);device_for_each_child (&adap->dev,NULL , __unregister_dummy); +} + +/** +* i2c_del_adapter - unregister I2C adapter +* @adap: the adapter being unregistered +* Context: can sleep +* +* This unregisters an I2C adapter which was previously registered +* by @i2c_add_adapter or @i2c_add_numbered_adapter. +*/ +void i2c_del_adapter (struct i2c_adapter *adap) +{ +struct i2c_adapter *found; + +/* First make sure that this adapter was ever added */ +mutex_lock (&core_lock); + found =idr_find (&i2c_adapter_idr, adap->nr); +mutex_unlock (&core_lock); +if (found != adap) { +pr_debug ("attempting to delete unregistered adapter [%s]\n" , adap->name); +return ; + } + +i2c_acpi_remove_space_handler (adap); + +i2c_deregister_clients (adap);#ifdef CONFIG_I2C_COMPAT class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 i2c: core: fix NULL-deref on adapter registration failure
In reply to Sasha LevinFrom: Johan Hovold <[email protected]>
[ Upstream commit 2295d2bb101faa663fbc45fadbb3fec45f107441 ]
If adapter registration ever fails the release callback would trigger a NULL-pointer dereference as the completion struct has not been initialised.
Note that before the offending commit this would instead have resulted in a minor memory leak of the adapter name.
Stable-dep-of: 07d5fb537928 ("i2c: core: fix adapter debugfs creation")
--- drivers/i2c/i2c-core-base.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/i2c/i2c-core-base.c +5 -3
@@ -1552,7 +1552,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) res =device_register (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto err_remove_irq_domain; + goto err_put_adap; } adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root);
@@ -1598,10 +1598,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap) out_reg:i2c_deregister_clients (adap);debugfs_remove_recursive (adap->debugfs); +device_del (&adap->dev); +err_put_adap:init_completion (&adap->dev_released); -device_unregister (&adap->dev); +put_device (&adap->dev);wait_for_completion (&adap->dev_released); -err_remove_irq_domain: +i2c_host_notify_irq_teardown (adap); out_list:mutex_lock (&core_lock);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 i2c: core: fix adapter debugfs creation
In reply to Sasha LevinFrom: Johan Hovold <[email protected]>
[ Upstream commit 07d5fb537928aad4369aaff0cbae73ba38a719af ]
Clients can be registered from bus notifier callbacks so the debugfs directory needs to be created before registering the adapter as clients use that directory as their debugfs parent.
Move debugfs creation before adapter registration to avoid having clients create their debugfs directories in the debugfs root (which is also more likely to fail due to name collisions).
Note that failure to allocate the adapter name must now be handled explicitly as debugfs_create_dir() cannot handle a NULL name (unlike device_add() which returns an error).
--- drivers/i2c/i2c-core-base.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/i2c/i2c-core-base.c +13 -8
@@ -1546,17 +1546,22 @@ static int i2c_register_adapter(struct i2c_adapter *adap) goto out_list; } -dev_set_name (&adap->dev,"i2c-%d" , adap->nr); + res =dev_set_name (&adap->dev,"i2c-%d" , adap->nr); +if (res) + goto err_remove_irq_domain; + adap->dev.bus = &i2c_bus_type; adap->dev.type = &i2c_adapter_type; - res =device_register (&adap->dev); +device_initialize (&adap->dev); + + adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root); + + res =device_add (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto err_put_adap; + goto err_remove_debugfs; } - adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root); - res =i2c_setup_smbus_alert (adap);if (res) goto out_reg;
@@ -1597,13 +1602,13 @@ static int i2c_register_adapter(struct i2c_adapter *adap) out_reg:i2c_deregister_clients (adap); -debugfs_remove_recursive (adap->debugfs);device_del (&adap->dev); -err_put_adap: +err_remove_debugfs: +debugfs_remove_recursive (adap->debugfs);init_completion (&adap->dev_released);put_device (&adap->dev);wait_for_completion (&adap->dev_released); - +err_remove_irq_domain:i2c_host_notify_irq_teardown (adap); out_list:mutex_lock (&core_lock);
Signature · 1 line
2.53.0
Re: [PATCH 6.6.y 1/4] i2c: core: fix irq domain leak on adapter registration failure
In reply to Sasha LevinQuoted 47 lines · Sasha Levin
From: Johan Hovold <[email protected]>
[ Upstream commit
8ce19524e4cc2462685f596a6402fbd8fb984ab2]Make sure to tear down the host notify irq domain on adapter registration failure to avoid leaking it.
This issue was flagged by Sashiko when reviewing another adapter registration fix.
Fixes 4d5538f5882a ("i2c: use an IRQ to report Host Notify events, not alert")Cc [email protected] # 4.10Cc Benjamin Tissoires <[email protected]>Signed-off-by Johan Hovold <[email protected]>Signed-off-by Wolfram Sang <[email protected]>Stable-dep-of:
07d5fb537928("i2c: core: fix adapter debugfs creation")Signed-off-by Sasha Levin <[email protected]>--- drivers/i2c/i2c-core-base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/i2c/i2c-core-base.c +3
-1@@ -1551,7 +1551,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) res =device_register (&adap->dev);if (res) {pr_err ("adapter '%s': can't register device (%d)\n" , adap->name, res); - goto out_list; + goto err_remove_irq_domain; } adap->debugfs =debugfs_create_dir (dev_name (&adap->dev), i2c_debugfs_root);@@ -1599,6 +1599,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)init_completion (&adap->dev_released);device_unregister (&adap->dev);wait_for_completion (&adap->dev_released); +err_remove_irq_domain: +i2c_host_notify_irq_teardown (adap); out_list:mutex_lock (&core_lock);idr_remove (&i2c_adapter_idr, adap->nr);Signature · 1 line
2.53.0
Didn't apply :(