Skip to contentSkip to conversation

ALSA: hda: aw88399: Use auto-cleanup for put_device()

PATCH In review Takashi Iwai 2 participants 4 messages Aug 3

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

PATCH 1/3 ALSA: hda: aw88399: Use auto-cleanup for put_device()

A temporary refcount management of a struct device can be done gracefully with __clean(put_device) for avoiding potential leaks.

No functional change but just a code cleanup.

---
 sound/hda/codecs/side-codecs/aw88399_hda.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/hda/codecs/side-codecs/aw88399_hda.c +2 -3
index 42de68faddbc..5175d341ecbe 100644
@@ -194,7 +194,6 @@ static const struct aw88399_prop_model aw88399_prop_model_table[] = {
 static int aw88399_hda_acpi_probe(struct aw88399_hda *aw88399)
 {
 	struct acpi_device *adev;
-	struct device *physdev;
 	const char *sub;
 	const struct aw88399_prop_model *model;
 
@@ -208,13 +207,13 @@ static int aw88399_hda_acpi_probe(struct aw88399_hda *aw88399)
 		return -ENODEV;
 	}
 
-	physdev = get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) =
+		get_device(acpi_get_first_physical_node(adev));
 	acpi_dev_put(adev);
 	if (!physdev)
 		return -ENODEV;
 
 	sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev));
-	put_device(physdev);
 	if (IS_ERR_OR_NULL(sub))
 		return 0;
 
Signature · 1 line
2.55.0
#1 lore raw

PATCH 2/3 ALSA: hda: tas2781: Use auto-cleanup for put_device()

A temporary refcount management of a struct device can be done gracefully with __clean(put_device) for avoiding potential leaks.

No functional change but just a code cleanup.

Cc Shenghao Ding <[email protected]>
Cc Kevin Lu <[email protected]>
Cc Baojun Xu <[email protected]>
Cc Sen Wang <[email protected]>
---
 sound/hda/codecs/side-codecs/tas2781_hda_i2c.c | 6 ++----
 sound/hda/codecs/side-codecs/tas2781_hda_spi.c | 9 ++++-----
 2 files changed, 6 insertions(+), 9 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda_i2c.c +2 -4
index 624db967f17b..6c502c34e015 100644
@@ -88,7 +88,6 @@ static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
 {
 	struct gpio_desc *speaker_id;
 	struct acpi_device *adev;
-	struct device *physdev;
 	LIST_HEAD(resources);
 	const char *sub;
 	uint32_t subid;
@@ -101,7 +100,8 @@ static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
 		return -ENODEV;
 	}
 
-	physdev = get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) =
+		get_device(acpi_get_first_physical_node(adev));
 	ret = acpi_dev_get_resources(adev, &resources, tas2781_get_i2c_res, p);
 	if (ret < 0) {
 		dev_err(p->dev, "Failed to get ACPI resource.\n");
@@ -151,14 +151,12 @@ static int tas2781_read_acpi(struct tasdevice_priv *p, const char *hid)
 end_2563:
 	acpi_dev_free_resource_list(&resources);
 	strscpy(p->dev_name, hid, sizeof(p->dev_name));
-	put_device(physdev);
 	acpi_dev_put(adev);
 
 	return 0;
 
 err:
 	dev_err(p->dev, "read acpi error, ret: %d\n", ret);
-	put_device(physdev);
 	acpi_dev_put(adev);
 
 	return ret;
sound/hda/codecs/side-codecs/tas2781_hda_spi.c +4 -5
index 271c56a79c32..d3b2a746e1a7 100644
@@ -328,7 +328,6 @@ static int tas2781_read_acpi(struct tas2781_hda *tas_hda,
 {
 	struct tasdevice_priv *p = tas_hda->priv;
 	struct acpi_device *adev;
-	struct device *physdev;
 	u32 values[HDA_MAX_COMPONENTS];
 	const char *property;
 	size_t nval;
@@ -341,7 +340,9 @@ static int tas2781_read_acpi(struct tas2781_hda *tas_hda,
 	}
 
 	strscpy(p->dev_name, hid, sizeof(p->dev_name));
-	physdev = get_device(acpi_get_first_physical_node(adev));
+
+	struct device *physdev __free(put_device) =
+		get_device(acpi_get_first_physical_node(adev));
 	acpi_dev_put(adev);
 	if (!physdev)
 		return -ENODEV;
@@ -381,13 +382,11 @@ static int tas2781_read_acpi(struct tas2781_hda *tas_hda,
 			goto err;
 		}
 	}
-	put_device(physdev);
 
 	return 0;
+
 err:
 	dev_err(p->dev, "read acpi error, ret: %d\n", ret);
-	put_device(physdev);
-
 	return ret;
 }
 
Signature · 1 line
2.55.0
#2 lore raw

PATCH 3/3 ALSA: hda: cs35l41: Use auto-cleanup for put_device()

In reply to Takashi Iwai

A temporary refcount management of a struct device can be done gracefully with __clean(put_device) for avoiding potential leaks.

No functional change but just a code cleanup.

---
 sound/hda/codecs/side-codecs/cs35l41_hda.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +3 -7
index c8eba0638ada..62296be45c55 100644
@@ -1915,7 +1915,6 @@ int cs35l41_hda_parse_acpi(struct cs35l41_hda *cs35l41, struct device *physdev,
 static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id)
 {
 	struct acpi_device *adev;
-	struct device *physdev;
 	struct spi_device *spi;
 	const char *sub;
 	int ret;
@@ -1927,7 +1926,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
 	}
 
 	cs35l41->dacpi = adev;
-	physdev = get_device(acpi_get_first_physical_node(adev));
+	struct device *physdev __free(put_device) =
+		get_device(acpi_get_first_physical_node(adev));
 	if (!physdev) {
 		acpi_dev_put(adev);
 		return -ENODEV;
@@ -1945,13 +1945,9 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
 	}
 
 	ret = cs35l41_hda_parse_acpi(cs35l41, physdev, id);
-	if (ret) {
-		put_device(physdev);
+	if (ret)
 		return ret;
-	}
 out:
-	put_device(physdev);
-
 	cs35l41->bypass_fw = false;
 	if (cs35l41->control_bus == SPI) {
 		spi = to_spi_device(cs35l41->dev);
Signature · 1 line
2.55.0