Skip to contentSkip to conversation

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

PATCH In review Guangshuo Li 3 participants 3 messages Sep 24 – Sep 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ASoC: Intel: atom: Fix platform device leak on probe failure

sst_acpi_probe() registers platform devices for the SST platform and machine board using platform_device_register_data(), but does not unregister them when later probe steps fail.

Fixes caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")

---
v2:
- Use devm_add_action_or_reset() to clean up the platform devices on probe failure and driver removal, as suggested by Cezary Rojewski.
- Update the subsystem prefix and shorten the commit message.

 sound/soc/intel/atom/sst/sst_acpi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
sound/soc/intel/atom/sst/sst_acpi.c +13 -1
index 73624e1b138a..de1ad168008b 100644
@@ -254,6 +254,11 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)
 	return 0;
 }
 
+static void sst_unregister_platform_device(void *data)
+{
+	platform_device_unregister(data);
+}
+
 static int sst_acpi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -342,7 +347,10 @@ static int sst_acpi_probe(struct platform_device *pdev)
 			pdata->platform);
 		return PTR_ERR(plat_dev);
 	}
-
+	ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+				       plat_dev);
+	if (ret)
+		return ret;
 	/*
 	 * Create platform device for sst machine driver,
 	 * pass machine info as pdata
@@ -355,6 +363,10 @@ static int sst_acpi_probe(struct platform_device *pdev)
 		return PTR_ERR(mdev);
 	}
 
+	ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+				       mdev);
+	if (ret)
+		return ret;
 	/* Fill sst platform data */
 	ctx->pdata = pdata;
 	strscpy(ctx->firmware_name, mach->fw_filename);
Signature · 1 line
2.43.0
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Guangshuo Li

sst_acpi_probe() registers platform devices for the SST platform and machine board using platform_device_register_data(), but does not unregister them when later probe steps fail.

Fixes caf94ed8629a ("ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID")

Below nitpicks are not a must. Thank you for the update:

Quoted 26 lines

---
v2:
- Use devm_add_action_or_reset() to clean up the platform devices on probe failure and driver removal, as suggested by Cezary Rojewski.
- Update the subsystem prefix and shorten the commit message.

 sound/soc/intel/atom/sst/sst_acpi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
sound/soc/intel/atom/sst/sst_acpi.c +5 -0
index 73624e1b138a..de1ad168008b 100644
@@ -254,6 +254,11 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)
 	return 0;
 }
 
+static void sst_unregister_platform_device(void *data)
+{
+	platform_device_unregister(data);
+}
+
 static int sst_acpi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;

sound/soc/intel/atom/sst/sst_acpi.c static int sst_acpi_probe(struct platform_device *pdev) · line 351

Quoted 6 lines
sound/soc/intel/atom/sst/sst_acpi.c +2 -1
@@ -342,7 +347,10 @@ static int sst_acpi_probe(struct platform_device *pdev)
 			pdata->platform);
 		return PTR_ERR(plat_dev);
 	}
-
+	ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+				       plat_dev);

Nitpick: No reason for newline here, fits 100-char limit nicely.

sound/soc/intel/atom/sst/sst_acpi.c static int sst_acpi_probe(struct platform_device *pdev) · line 367

Quoted 11 lines
sound/soc/intel/atom/sst/sst_acpi.c +4 -0
+	if (ret)
+		return ret;
 	/*
 	 * Create platform device for sst machine driver,
 	 * pass machine info as pdata
@@ -355,6 +363,10 @@ static int sst_acpi_probe(struct platform_device *pdev)
 		return PTR_ERR(mdev);
 	}
 
+	ret = devm_add_action_or_reset(dev, sst_unregister_platform_device,
+				       mdev);

Ditto.

Quoted 5 lines
sound/soc/intel/atom/sst/sst_acpi.c +2 -0
+	if (ret)
+		return ret;
 	/* Fill sst platform data */
 	ctx->pdata = pdata;
 	strscpy(ctx->firmware_name, mach->fw_filename);
maintainer
#2 lore raw
In reply to Guangshuo Li
Quoted 1 line · Guangshuo Li

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

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/1] ASoC: Intel: atom: Fix platform device leak on probe failure

      https://git.kernel.org/broonie/sound/c/dcc36d766dc8

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark