[PATCH] dca: unregister the provider when domain allocation fails

From: Wentao Liang

Date: Tue Nov 03 2026 - 22:25:09 EST


register_dca_provider() registers the provider in sysfs and in the
provider IDR before it tries to create a new domain. If the domain
allocation fails, the function returns -ENODEV without calling
dca_sysfs_remove_provider(), so the IDR entry and the sysfs device stay
registered while the caller frees the provider, leaving a dangling
pointer behind that a later lookup can dereference.

Remove the sysfs and IDR registration before bailing out, matching what
the adjacent error path already does.

Fixes: a1741e7fcbc1 ("locking, drivers/dca: Annotate dca_lock as raw")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/dca/dca-core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/dca/dca-core.c b/drivers/dca/dca-core.c
index 583510850fad..e08f8894d7e9 100644
--- a/drivers/dca/dca-core.c
+++ b/drivers/dca/dca-core.c
@@ -368,8 +368,10 @@ int register_dca_provider(struct dca_provider *dca, struct device *dev)
raw_spin_unlock_irqrestore(&dca_lock, flags);
rc = dca_pci_rc_from_dev(dev);
newdomain = dca_allocate_domain(rc);
- if (!newdomain)
+ if (!newdomain) {
+ dca_sysfs_remove_provider(dca);
return -ENODEV;
+ }
raw_spin_lock_irqsave(&dca_lock, flags);
/* Recheck, we might have raced after dropping the lock */
domain = dca_get_domain(dev);
--
2.34.1