Skip to contentSkip to conversation

ALSA: atmel: ac97c: fix reset GPIO error handling

PATCH Superseded Sreeraj S Kurup 3 participants 5 messages Nov 27 – Nov 28

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

PATCH 1/1 ALSA: atmel: ac97c: fix reset GPIO error handling

The driver currently ignores errors returned by devm_gpiod_get_index() and continues probing. This can cause problems when the GPIO provider is not ready and the function returns -EPROBE_DEFER.

Use devm_gpiod_get_index_optional() to handle the reset GPIO as optional. If the GPIO is not available, the driver can continue using the internal reset mechanism. If GPIO acquisition fails for another reason, return the error using dev_err_probe().

Also, check the GPIO descriptor for NULL in atmel_ac97c_reset(), because the optional GPIO API returns NULL when no GPIO is assigned.

---
 sound/atmel/ac97c.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
sound/atmel/ac97c.c +7 -3
index 234549e17351..3ab6ddb3259f 100644
@@ -670,7 +670,7 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip)
 	ac97c_writel(chip, CAMR, 0);
 	ac97c_writel(chip, COMR, 0);
 
-	if (!IS_ERR(chip->reset_pin)) {
+	if (chip->reset_pin) {
 		gpiod_set_value(chip->reset_pin, 0);
 		/* AC97 v2.2 specifications says minimum 1 us. */
 		udelay(2);
@@ -743,9 +743,13 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	chip->pdev = pdev;
 	chip->regs = regs;
 
-	chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
+	chip->reset_pin = devm_gpiod_get_index_optional(dev,
+							"ac97", 2,
+							GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_pin))
-		dev_dbg(dev, "reset pin not available\n");
+		return dev_err_probe(dev,
+				     PTR_ERR(chip->reset_pin),
+				     "failed to get reset GPIO\n");
 
 	atmel_ac97c_reset(chip);
 
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ALSA: atmel: ac97c: missing Fixes trailer for reset GPIO error handling fix --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ALSA: atmel: ac97c: missing Fixes trailer for reset GPIO error handling fix
--

commit 656d7dbe132930b3438ef77f14be3d7acdf72afa
Author: Sreeraj S Kurup <[email protected]>

Quoted 12 lines

ALSA: atmel: ac97c: fix reset GPIO error handling

The driver currently ignores errors returned by devm_gpiod_get_index() and continues probing. This can cause problems when the GPIO provider is not ready and the function returns -EPROBE_DEFER.

Use devm_gpiod_get_index_optional() to handle the reset GPIO as optional. If the GPIO is not available, the driver can continue using the internal reset mechanism. If GPIO acquisition fails for another reason, return the error using dev_err_probe().

Quoted 4 lines

Also, check the GPIO descriptor for NULL in atmel_ac97c_reset(), because the optional GPIO API returns NULL when no GPIO is assigned.

[Severity: Low]
This fixes the devm_gpiod_get_index() call and ignored error return introduced during the gpiod conversion. Should the commit message include:

Fixes 5f10e84934e4 ("ALSA: atmel: convert AC97c driver to GPIO descriptor API")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 ALSA: atmel: ac97c: fix reset GPIO error handling

In reply to Sreeraj S Kurup

The driver currently ignores errors returned by devm_gpiod_get_index() and continues probing. This can cause problems when the GPIO provider is not ready and the function returns -EPROBE_DEFER.

Use devm_gpiod_get_index_optional() to handle the reset GPIO as optional. If the GPIO is not available, the driver can continue using the internal reset mechanism. If GPIO acquisition fails for another reason, return the error using dev_err_probe().

Also, check the GPIO descriptor for NULL in atmel_ac97c_reset(), because the optional GPIO API returns NULL when no GPIO is assigned.

Fixes 5f10e84934e4 ("ALSA: atmel: convert AC97c driver to GPIO descriptor API")

---
v2:
- Add Fixes trailer.

 sound/atmel/ac97c.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
sound/atmel/ac97c.c +7 -3
index 234549e17351..3ab6ddb3259f 100644
@@ -670,7 +670,7 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip)
 	ac97c_writel(chip, CAMR, 0);
 	ac97c_writel(chip, COMR, 0);
 
-	if (!IS_ERR(chip->reset_pin)) {
+	if (chip->reset_pin) {
 		gpiod_set_value(chip->reset_pin, 0);
 		/* AC97 v2.2 specifications says minimum 1 us. */
 		udelay(2);
@@ -743,9 +743,13 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
 	chip->pdev = pdev;
 	chip->regs = regs;
 
-	chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
+	chip->reset_pin = devm_gpiod_get_index_optional(dev,
+							"ac97", 2,
+							GPIOD_OUT_HIGH);
 	if (IS_ERR(chip->reset_pin))
-		dev_dbg(dev, "reset pin not available\n");
+		return dev_err_probe(dev,
+				     PTR_ERR(chip->reset_pin),
+				     "failed to get reset GPIO\n");
 
 	atmel_ac97c_reset(chip);
 
Signature · 1 line
2.55.0
Applied
#3 lore raw
Quoted 11 lines · Sreeraj S Kurup

The driver currently ignores errors returned by devm_gpiod_get_index() and continues probing. This can cause problems when the GPIO provider is not ready and the function returns -EPROBE_DEFER.

Use devm_gpiod_get_index_optional() to handle the reset GPIO as optional. If the GPIO is not available, the driver can continue using the internal reset mechanism. If GPIO acquisition fails for another reason, return the error using dev_err_probe().

Quoted 5 lines

Also, check the GPIO descriptor for NULL in atmel_ac97c_reset(), because the optional GPIO API returns NULL when no GPIO is assigned.

Fixes 5f10e84934e4 ("ALSA: atmel: convert AC97c driver to GPIO descriptor API")

Applied to for-next branch. Thanks.

Takashi