[PATCH] ASoC: Intel: SST: fix platform device leak on probe failure

Guangshuo Li posted 1 patch 3 days, 11 hours ago
sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
[PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Guangshuo Li 3 days, 11 hours ago
sst_acpi_probe() registers platform devices for the SST platform and
machine drivers using platform_device_register_data(), but does not
unregister them when later probe steps fail.

If machine device registration fails, the already registered SST platform
device is left registered. The same leak happens when
sst_platform_get_resources() or sst_context_init() fails after both
platform devices have been successfully registered.

A registered platform device owns resources allocated by the platform
device core and must be released with platform_device_unregister() so
that the device reference is dropped and platform_device_release() can
free the backing platform_object.

Unregister the created platform devices on all failure paths to restore
the missing cleanup.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/sound/soc/intel/atom/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c
index 73624e1b138a..a1f16083bd3d 100644
--- a/sound/soc/intel/atom/sst/sst_acpi.c
+++ b/sound/soc/intel/atom/sst/sst_acpi.c
@@ -352,7 +352,8 @@ static int sst_acpi_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev)) {
 		dev_err(dev, "Failed to create machine device: %s\n",
 			mach->drv_name);
-		return PTR_ERR(mdev);
+		ret = PTR_ERR(mdev);
+		goto err_unregister_plat_dev;
 	}
 
 	/* Fill sst platform data */
@@ -361,15 +362,21 @@ static int sst_acpi_probe(struct platform_device *pdev)
 
 	ret = sst_platform_get_resources(ctx);
 	if (ret)
-		return ret;
+		goto err_unregister_mdev;
 
 	ret = sst_context_init(ctx);
 	if (ret < 0)
-		return ret;
+		goto err_unregister_mdev;
 
 	sst_configure_runtime_pm(ctx);
 	platform_set_drvdata(pdev, ctx);
 	return ret;
+
+err_unregister_mdev:
+	platform_device_unregister(mdev);
+err_unregister_plat_dev:
+	platform_device_unregister(plat_dev);
+	return ret;
 }
 
 /**
-- 
2.43.0
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by krzk@kernel.org 3 days, 4 hours ago
On Mon, 21 Sep 2026 15:38:47 +0800, Guangshuo Li wrote:
> sst_acpi_probe() registers platform devices for the SST platform and
> machine drivers using platform_device_register_data(), but does not
> unregister them when later probe steps fail.
> 
> If machine device registration fails, the already registered SST platform
> device is left registered. The same leak happens when
> sst_platform_get_resources() or sst_context_init() fails after both
> platform devices have been successfully registered.
> 
> A registered platform device owns resources allocated by the platform
> device core and must be released with platform_device_unregister() so
> that the device reference is dropped and platform_device_release() can
> free the backing platform_object.
> 
> Unregister the created platform devices on all failure paths to restore
> the missing cleanup.
> 
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
> 
> Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 


You sent multiple independent patches, to multiple independent
subsystems. The amount of these patches clearly suggest this was
AI generated and most likely not tested.

More importantly, you sent all this work without properly organizing
relevant patches into patchsets. This makes reviewing difficult
and might cause multiple reviewers to address the same issue.
Replying to the entire set is impossible and requires handling each
patch independently, instead of applying or discarding the set.
Maintainers also won't see the bigger picture of your work. Quite
worrying.

This is on the verge of hostile patch: bomb us with so many
contributions, we won't be able to handle them in efficient manner,
like responding ONCE to ask you to slow down.  Considering all this
is untested and LLM generated, I have even more doubts whether this
should be considered for review.

Please read kernel documentation BEFORE posting more work. It will
explain you how to identify subsystems, how to organize your work per
subsystem, how to document usage of LLM and how what you should not
do if this was posted in a good faith.

Best regards,
Krzysztof
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by krzk@kernel.org 3 days, 4 hours ago
On Mon, 21 Sep 2026 15:38:47 +0800, Guangshuo Li wrote:
> sst_acpi_probe() registers platform devices for the SST platform and
> machine drivers using platform_device_register_data(), but does not
> unregister them when later probe steps fail.
> 
> If machine device registration fails, the already registered SST platform
> device is left registered. The same leak happens when
> sst_platform_get_resources() or sst_context_init() fails after both
> platform devices have been successfully registered.
> 
> A registered platform device owns resources allocated by the platform
> device core and must be released with platform_device_unregister() so
> that the device reference is dropped and platform_device_release() can
> free the backing platform_object.
> 
> Unregister the created platform devices on all failure paths to restore
> the missing cleanup.
> 
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
> 
> Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 


You sent multiple independent patches, to multiple independent
subsystems. The amount of these patches clearly suggest this was
AI generated and most likely not tested.

More importantly, you sent all this work without properly organizing
relevant patches into patchsets. This makes reviewing difficult
and might cause multiple reviewers to address the same issue.
Replying to the entire set is impossible and requires handling each
patch independently, instead of applying or discarding the set.
Maintainers also won't see the bigger picture of your work. Quite
worrying.

This is on the verge of hostile patch: bomb us with so many
contributions, we won't be able to handle them in efficient manner,
like responding ONCE to ask you to slow down.  Considering all this
is untested and LLM generated, I have even more doubts whether this
should be considered for review.

Please read kernel documentation BEFORE posting more work. It will
explain you how to identify subsystems, how to organize your work per
subsystem, how to document usage of LLM and how what you should not
do if this was posted in a good faith.

Best regards,
Krzysztof
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by krzk@kernel.org 3 days, 4 hours ago
On Mon, 21 Sep 2026 15:38:47 +0800, Guangshuo Li wrote:
> sst_acpi_probe() registers platform devices for the SST platform and
> machine drivers using platform_device_register_data(), but does not
> unregister them when later probe steps fail.
> 
> If machine device registration fails, the already registered SST platform
> device is left registered. The same leak happens when
> sst_platform_get_resources() or sst_context_init() fails after both
> platform devices have been successfully registered.
> 
> A registered platform device owns resources allocated by the platform
> device core and must be released with platform_device_unregister() so
> that the device reference is dropped and platform_device_release() can
> free the backing platform_object.
> 
> Unregister the created platform devices on all failure paths to restore
> the missing cleanup.
> 
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
> 
> Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 


You sent multiple independent patches, to multiple independent
subsystems. The amount of these patches clearly suggest this was
AI generated and most likely not tested.

More importantly, you sent all this work without properly organizing
relevant patches into patchsets. This makes reviewing difficult
and might cause multiple reviewers to address the same issue.
Replying to the entire set is impossible and requires handling each
patch independently, instead of applying or discarding the set.
Maintainers also won't see the bigger picture of your work. Quite
worrying.

This is on the verge of hostile patch: bomb us with so many
contributions, we won't be able to handle them in efficient manner,
like responding ONCE to ask you to slow down.  Considering all this
is untested and LLM generated, I have even more doubts whether this
should be considered for review.

Please read kernel documentation BEFORE posting more work. It will
explain you how to identify subsystems, how to organize your work per
subsystem, how to document usage of LLM and how what you should not
do if this was posted in a good faith.

Best regards,
Krzysztof
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Guangshuo Li 2 days, 16 hours ago
Hi Krzysztof,

Thank you for your feedback.

On Mon, 21 Sept 2026 at 23:06, <krzk@kernel.org> wrote:
>
>
> On Mon, 21 Sep 2026 15:38:47 +0800, Guangshuo Li wrote:
> > sst_acpi_probe() registers platform devices for the SST platform and
> > machine drivers using platform_device_register_data(), but does not
> > unregister them when later probe steps fail.
> >
> > If machine device registration fails, the already registered SST platform
> > device is left registered. The same leak happens when
> > sst_platform_get_resources() or sst_context_init() fails after both
> > platform devices have been successfully registered.
> >
> > A registered platform device owns resources allocated by the platform
> > device core and must be released with platform_device_unregister() so
> > that the device reference is dropped and platform_device_release() can
> > free the backing platform_object.
> >
> > Unregister the created platform devices on all failure paths to restore
> > the missing cleanup.
> >
> > The issue was identified by a static analysis tool I developed and
> > confirmed by manual review.
> >
> > Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> > ---
> >  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> >
>
>
> You sent multiple independent patches, to multiple independent
> subsystems. The amount of these patches clearly suggest this was
> AI generated and most likely not tested.
>
> More importantly, you sent all this work without properly organizing
> relevant patches into patchsets. This makes reviewing difficult
> and might cause multiple reviewers to address the same issue.
> Replying to the entire set is impossible and requires handling each
> patch independently, instead of applying or discarding the set.
> Maintainers also won't see the bigger picture of your work. Quite
> worrying.
>
> This is on the verge of hostile patch: bomb us with so many
> contributions, we won't be able to handle them in efficient manner,
> like responding ONCE to ask you to slow down.  Considering all this
> is untested and LLM generated, I have even more doubts whether this
> should be considered for review.
>
> Please read kernel documentation BEFORE posting more work. It will
> explain you how to identify subsystems, how to organize your work per
> subsystem, how to document usage of LLM and how what you should not
> do if this was posted in a good faith.
>
> Best regards,
> Krzysztof
>
>
>
I would like to clarify that these patches were manually reviewed and
audited by us; they were not simply generated and submitted by an LLM.
However, I understand why the recent submission pattern may have given
that impression. We sent too many patches in a short period of time,
and we also failed to respond to some discussions in a timely manner,
which made the situation look worse.

Many of the recent patches, especially the v2 revisions, are
corrections and improvements based on previous review feedback rather
than completely new untested changes. That said, we recognize that the
way we submitted them increased the burden on maintainers and
reviewers.

We apologize for the pressure this caused to the community. We will be
more careful about organizing patches by subsystem, preparing proper
patchsets, and following the kernel contribution guidelines before
sending future work.

Thank you again for pointing this out.

Best regards,
Guangshuo
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Cezary Rojewski 3 days, 9 hours ago
On 9/21/2026 9:38 AM, Guangshuo Li wrote:
> sst_acpi_probe() registers platform devices for the SST platform and
> machine drivers using platform_device_register_data(), but does not
> unregister them when later probe steps fail.

s/machine drivers/machine board/

The above paragraph alone is sufficient, please drop everything else in
the commit message.  There is no need to write wall-of-text for a fix
addressing a missing error path.  In case this wall was provided by an
agent, relevant Assisted-by: tag is needed in the tag area.

You can keep the very last sentence if you want to.

> If machine device registration fails, the already registered SST platform
> device is left registered. The same leak happens when
> sst_platform_get_resources() or sst_context_init() fails after both
> platform devices have been successfully registered.
> 
> A registered platform device owns resources allocated by the platform
> device core and must be released with platform_device_unregister() so
> that the device reference is dropped and platform_device_release() can
> free the backing platform_object.
> 
> Unregister the created platform devices on all failure paths to restore
> the missing cleanup.
> 
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
> 
> Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>

For the commit title: please update to:
	ASoC: Intel: atom: Fix (...)

Provided both the commit title and message are updated, feel free to add:
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>

> ---
>  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/intel/atom/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c
> index 73624e1b138a..a1f16083bd3d 100644
> --- a/sound/soc/intel/atom/sst/sst_acpi.c
> +++ b/sound/soc/intel/atom/sst/sst_acpi.c
> @@ -352,7 +352,8 @@ static int sst_acpi_probe(struct platform_device *pdev)
>  	if (IS_ERR(mdev)) {
>  		dev_err(dev, "Failed to create machine device: %s\n",
>  			mach->drv_name);
> -		return PTR_ERR(mdev);
> +		ret = PTR_ERR(mdev);
> +		goto err_unregister_plat_dev;
>  	}
>  
>  	/* Fill sst platform data */
> @@ -361,15 +362,21 @@ static int sst_acpi_probe(struct platform_device *pdev)
>  
>  	ret = sst_platform_get_resources(ctx);
>  	if (ret)
> -		return ret;
> +		goto err_unregister_mdev;
>  
>  	ret = sst_context_init(ctx);
>  	if (ret < 0)
> -		return ret;
> +		goto err_unregister_mdev;
>  
>  	sst_configure_runtime_pm(ctx);
>  	platform_set_drvdata(pdev, ctx);
>  	return ret;
> +
> +err_unregister_mdev:
> +	platform_device_unregister(mdev);
> +err_unregister_plat_dev:
> +	platform_device_unregister(plat_dev);
> +	return ret;
>  }

Looks like sst_acpi_remove() does not unregister the devices either.
That could be fixed by enlisting devm_add_action_or_reset() in
sst_acpi_probe() without altering sst_acpi_remove() at all.

Would you mind sending a separate patch updating the function so both
the error path and the driver-unload clean up the device objects?


Kind regards,
Czarek
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Guangshuo Li 2 days, 11 hours ago
Hi Czarek,

Thanks for the review.

On Mon, 21 Sept 2026 at 17:31, Cezary Rojewski
<cezary.rojewski@intel.com> wrote:
>
> On 9/21/2026 9:38 AM, Guangshuo Li wrote:
> > sst_acpi_probe() registers platform devices for the SST platform and
> > machine drivers using platform_device_register_data(), but does not
> > unregister them when later probe steps fail.
>
> s/machine drivers/machine board/
>
> The above paragraph alone is sufficient, please drop everything else in
> the commit message.  There is no need to write wall-of-text for a fix
> addressing a missing error path.  In case this wall was provided by an
> agent, relevant Assisted-by: tag is needed in the tag area.
>
> You can keep the very last sentence if you want to.
>
> > If machine device registration fails, the already registered SST platform
> > device is left registered. The same leak happens when
> > sst_platform_get_resources() or sst_context_init() fails after both
> > platform devices have been successfully registered.
> >
> > A registered platform device owns resources allocated by the platform
> > device core and must be released with platform_device_unregister() so
> > that the device reference is dropped and platform_device_release() can
> > free the backing platform_object.
> >
> > Unregister the created platform devices on all failure paths to restore
> > the missing cleanup.
> >
> > The issue was identified by a static analysis tool I developed and
> > confirmed by manual review.
> >
> > Fixes: caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
>
> For the commit title: please update to:
>         ASoC: Intel: atom: Fix (...)
>
> Provided both the commit title and message are updated, feel free to add:
> Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
>
> > ---
> >  sound/soc/intel/atom/sst/sst_acpi.c | 13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> >
> > diff --git a/sound/soc/intel/atom/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c
> > index 73624e1b138a..a1f16083bd3d 100644
> > --- a/sound/soc/intel/atom/sst/sst_acpi.c
> > +++ b/sound/soc/intel/atom/sst/sst_acpi.c
> > @@ -352,7 +352,8 @@ static int sst_acpi_probe(struct platform_device *pdev)
> >       if (IS_ERR(mdev)) {
> >               dev_err(dev, "Failed to create machine device: %s\n",
> >                       mach->drv_name);
> > -             return PTR_ERR(mdev);
> > +             ret = PTR_ERR(mdev);
> > +             goto err_unregister_plat_dev;
> >       }
> >
> >       /* Fill sst platform data */
> > @@ -361,15 +362,21 @@ static int sst_acpi_probe(struct platform_device *pdev)
> >
> >       ret = sst_platform_get_resources(ctx);
> >       if (ret)
> > -             return ret;
> > +             goto err_unregister_mdev;
> >
> >       ret = sst_context_init(ctx);
> >       if (ret < 0)
> > -             return ret;
> > +             goto err_unregister_mdev;
> >
> >       sst_configure_runtime_pm(ctx);
> >       platform_set_drvdata(pdev, ctx);
> >       return ret;
> > +
> > +err_unregister_mdev:
> > +     platform_device_unregister(mdev);
> > +err_unregister_plat_dev:
> > +     platform_device_unregister(plat_dev);
> > +     return ret;
> >  }
>
> Looks like sst_acpi_remove() does not unregister the devices either.
> That could be fixed by enlisting devm_add_action_or_reset() in
> sst_acpi_probe() without altering sst_acpi_remove() at all.
>
> Would you mind sending a separate patch updating the function so both
> the error path and the driver-unload clean up the device objects?
>
>
> Kind regards,
> Czarek

I'll update the title to:

ASoC: Intel: atom: Fix platform device leak on probe failure

and trim the commit message as suggested, including the
s/machine drivers/machine board/ change. I'll also add your Reviewed-by.

For the separate cleanup patch, do you mean something like this?

+static void sst_unregister_platform_device(void *data)
+{
+        platform_device_unregister(data);
+}
+
        plat_dev = platform_device_register_data(...);
        if (IS_ERR(plat_dev))
                return PTR_ERR(plat_dev);
+
+       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+                                      plat_dev);
+       if (ret)
+               return ret;

        ...

        mdev = platform_device_register_data(...);
        if (IS_ERR(mdev))
                return PTR_ERR(mdev);
+
+       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+                                      mdev);
+       if (ret)
+               return ret;

This would let devres clean up both devices on later probe failure and on
driver unload, so the explicit unregister error paths from the first patch
would no longer be needed after this patch.

Would this be what you had in mind? If so, I'll follow Krzysztof's
suggestion, organize the related changes into a proper patch series,
and send a two-patch v2.

Thanks,
Guangshuo
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Cezary Rojewski 1 day, 11 hours ago
On 9/22/2026 10:17 AM, Guangshuo Li wrote:
> Hi Czarek,
> 
> Thanks for the review.

>>> @@ -361,15 +362,21 @@ static int sst_acpi_probe(struct platform_device *pdev)
>>>
>>>       ret = sst_platform_get_resources(ctx);
>>>       if (ret)
>>> -             return ret;
>>> +             goto err_unregister_mdev;
>>>
>>>       ret = sst_context_init(ctx);
>>>       if (ret < 0)
>>> -             return ret;
>>> +             goto err_unregister_mdev;
>>>
>>>       sst_configure_runtime_pm(ctx);
>>>       platform_set_drvdata(pdev, ctx);
>>>       return ret;
>>> +
>>> +err_unregister_mdev:
>>> +     platform_device_unregister(mdev);
>>> +err_unregister_plat_dev:
>>> +     platform_device_unregister(plat_dev);
>>> +     return ret;
>>>  }
>>
>> Looks like sst_acpi_remove() does not unregister the devices either.
>> That could be fixed by enlisting devm_add_action_or_reset() in
>> sst_acpi_probe() without altering sst_acpi_remove() at all.
>>
>> Would you mind sending a separate patch updating the function so both
>> the error path and the driver-unload clean up the device objects?
>>
>>
>> Kind regards,
>> Czarek
> 
> I'll update the title to:
> 
> ASoC: Intel: atom: Fix platform device leak on probe failure
> 
> and trim the commit message as suggested, including the
> s/machine drivers/machine board/ change. I'll also add your Reviewed-by.
> 
> For the separate cleanup patch, do you mean something like this?
> 
> +static void sst_unregister_platform_device(void *data)
> +{
> +        platform_device_unregister(data);
> +}
> +
>         plat_dev = platform_device_register_data(...);
>         if (IS_ERR(plat_dev))
>                 return PTR_ERR(plat_dev);
> +
> +       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
> +                                      plat_dev);
> +       if (ret)
> +               return ret;
> 
>         ...
> 
>         mdev = platform_device_register_data(...);
>         if (IS_ERR(mdev))
>                 return PTR_ERR(mdev);
> +
> +       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
> +                                      mdev);
> +       if (ret)
> +               return ret;
> 
> This would let devres clean up both devices on later probe failure and on
> driver unload, so the explicit unregister error paths from the first patch
> would no longer be needed after this patch.
> 
> Would this be what you had in mind? If so, I'll follow Krzysztof's
> suggestion, organize the related changes into a proper patch series,
> and send a two-patch v2.

I do not mind either approach. There are two problems here:
	1) leak on probe() failure
	2) leak on driver remove()

So, two patches-approach IMHO is perfectly fine. And yes, enlisting
devm_add_action_or_reset() closes both 1) and 2) in one go.

Kind regards,
Czarek
Re: [PATCH] ASoC: Intel: SST: fix platform device leak on probe failure
Posted by Guangshuo Li 5 hours ago
Hi Czarek,

Thanks for the clarification.

On Wed, 23 Sept 2026 at 16:15, Cezary Rojewski
<cezary.rojewski@intel.com> wrote:
>
> On 9/22/2026 10:17 AM, Guangshuo Li wrote:
> > Hi Czarek,
> >
> > Thanks for the review.
>
> >>> @@ -361,15 +362,21 @@ static int sst_acpi_probe(struct platform_device *pdev)
> >>>
> >>>       ret = sst_platform_get_resources(ctx);
> >>>       if (ret)
> >>> -             return ret;
> >>> +             goto err_unregister_mdev;
> >>>
> >>>       ret = sst_context_init(ctx);
> >>>       if (ret < 0)
> >>> -             return ret;
> >>> +             goto err_unregister_mdev;
> >>>
> >>>       sst_configure_runtime_pm(ctx);
> >>>       platform_set_drvdata(pdev, ctx);
> >>>       return ret;
> >>> +
> >>> +err_unregister_mdev:
> >>> +     platform_device_unregister(mdev);
> >>> +err_unregister_plat_dev:
> >>> +     platform_device_unregister(plat_dev);
> >>> +     return ret;
> >>>  }
> >>
> >> Looks like sst_acpi_remove() does not unregister the devices either.
> >> That could be fixed by enlisting devm_add_action_or_reset() in
> >> sst_acpi_probe() without altering sst_acpi_remove() at all.
> >>
> >> Would you mind sending a separate patch updating the function so both
> >> the error path and the driver-unload clean up the device objects?
> >>
> >>
> >> Kind regards,
> >> Czarek
> >
> > I'll update the title to:
> >
> > ASoC: Intel: atom: Fix platform device leak on probe failure
> >
> > and trim the commit message as suggested, including the
> > s/machine drivers/machine board/ change. I'll also add your Reviewed-by.
> >
> > For the separate cleanup patch, do you mean something like this?
> >
> > +static void sst_unregister_platform_device(void *data)
> > +{
> > +        platform_device_unregister(data);
> > +}
> > +
> >         plat_dev = platform_device_register_data(...);
> >         if (IS_ERR(plat_dev))
> >                 return PTR_ERR(plat_dev);
> > +
> > +       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
> > +                                      plat_dev);
> > +       if (ret)
> > +               return ret;
> >
> >         ...
> >
> >         mdev = platform_device_register_data(...);
> >         if (IS_ERR(mdev))
> >                 return PTR_ERR(mdev);
> > +
> > +       ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
> > +                                      mdev);
> > +       if (ret)
> > +               return ret;
> >
> > This would let devres clean up both devices on later probe failure and on
> > driver unload, so the explicit unregister error paths from the first patch
> > would no longer be needed after this patch.
> >
> > Would this be what you had in mind? If so, I'll follow Krzysztof's
> > suggestion, organize the related changes into a proper patch series,
> > and send a two-patch v2.
>
> I do not mind either approach. There are two problems here:
>         1) leak on probe() failure
>         2) leak on driver remove()
>
> So, two patches-approach IMHO is perfectly fine. And yes, enlisting
> devm_add_action_or_reset() closes both 1) and 2) in one go.
>
> Kind regards,
> Czarek

I'll use devm_add_action_or_reset() to handle both the probe failure and
driver removal cases, and send the updated change in v2.

Thanks,
Guangshuo