Re: [PATCH] dca: fix provider device memory leak on domain allocation failure
From: Guangshuo Li
Date: Tue Sep 22 2026 - 04:24:37 EST
Hi Markus,
Thanks for the suggestion.
On Mon, 21 Sept 2026 at 19:30, Markus Elfring <Markus.Elfring@xxxxxx> wrote:
>
> …
> > +++ b/drivers/dca/dca-core.c
> > @@ -368,8 +368,11 @@ 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);
> …
>
> Please avoid a bit of duplicate source code in this function implementation
> by using another goto chain.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.3-rc4#n572
>
> https://elixir.bootlin.com/linux/v7.3-rc3/source/drivers/dca/dca-core.c#L335-L389
>
> Regards,
> Markus
Do you mean using a common error path like this?
if (dca_providers_blocked) {
raw_spin_unlock_irqrestore(&dca_lock, flags);
- dca_sysfs_remove_provider(dca);
unregister_dca_providers();
- return -ENODEV;
+ goto err_remove_provider;
}
...
newdomain = dca_allocate_domain(rc);
if (!newdomain)
- return -ENODEV;
+ goto err_remove_provider;
...
kfree(newdomain);
return 0;
+
+err_remove_provider:
+ dca_sysfs_remove_provider(dca);
+ return -ENODEV;
}
Would this be the preferred change? If so, I'll follow Krzysztof's
suggestion and include it in a properly organized series for v2.
Thanks,
Guangshuo