Skip to content

Commit 6aa96f7

Browse files
committed
ALSA: hda: tas2781-spi: Fix bogus error handling in tas2781_hda_spi_probe()
The error handling in tas2781_hda_spi_probe() has quite a few problems, as reported by Dan Carpenter. The code jumps to err label and calls tas2781_hda_remove(), but this call would rather crash. In some places, no error code is set properly, and the runtime PM setup is doubly done. This patch tries to address those bogus error handling. Basically we can return immediately at each error before adding the component. Also, the error code should be set properly for the unmatched SPI device name. And finally, component_add() should be added before enabling the runtime PM. Fixes: bb5f86e ("ALSA: hda/tas2781: Add tas2781 hda SPI driver") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/[email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 807563c commit 6aa96f7

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

sound/pci/hda/tas2781_hda_spi.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,22 +1101,24 @@ static int tas2781_hda_spi_probe(struct spi_device *spi)
11011101

11021102
tas_priv = devm_kzalloc(&spi->dev, sizeof(*tas_priv), GFP_KERNEL);
11031103
if (!tas_priv)
1104-
goto err;
1104+
return -ENOMEM;
11051105
tas_priv->dev = &spi->dev;
11061106
tas_hda->priv = tas_priv;
11071107
tas_priv->regmap = devm_regmap_init_spi(spi, &tasdevice_regmap);
11081108
if (IS_ERR(tas_priv->regmap)) {
11091109
ret = PTR_ERR(tas_priv->regmap);
11101110
dev_err(tas_priv->dev, "Failed to allocate regmap: %d\n",
11111111
ret);
1112-
goto err;
1112+
return ret;
11131113
}
11141114
if (strstr(dev_name(&spi->dev), "TXNW2781")) {
11151115
device_name = "TXNW2781";
11161116
tas_priv->save_calibration = tas2781_save_calibration;
11171117
tas_priv->apply_calibration = tas2781_apply_calib;
11181118
} else {
1119-
goto err;
1119+
dev_err(tas_priv->dev, "Unmatched spi dev %s\n",
1120+
dev_name(&spi->dev));
1121+
return -ENODEV;
11201122
}
11211123

11221124
tas_priv->irq = spi->irq;
@@ -1129,6 +1131,12 @@ static int tas2781_hda_spi_probe(struct spi_device *spi)
11291131

11301132
tasdevice_spi_init(tas_priv);
11311133

1134+
ret = component_add(tas_priv->dev, &tas2781_hda_comp_ops);
1135+
if (ret) {
1136+
dev_err(tas_priv->dev, "Register component fail: %d\n", ret);
1137+
return ret;
1138+
}
1139+
11321140
pm_runtime_set_autosuspend_delay(tas_priv->dev, 3000);
11331141
pm_runtime_use_autosuspend(tas_priv->dev);
11341142
pm_runtime_mark_last_busy(tas_priv->dev);
@@ -1138,17 +1146,7 @@ static int tas2781_hda_spi_probe(struct spi_device *spi)
11381146

11391147
pm_runtime_put_autosuspend(tas_priv->dev);
11401148

1141-
ret = component_add(tas_priv->dev, &tas2781_hda_comp_ops);
1142-
if (ret) {
1143-
dev_err(tas_priv->dev, "Register component fail: %d\n", ret);
1144-
pm_runtime_disable(tas_priv->dev);
1145-
}
1146-
1147-
err:
1148-
if (ret)
1149-
tas2781_hda_remove(&spi->dev);
1150-
1151-
return ret;
1149+
return 0;
11521150
}
11531151

11541152
static void tas2781_hda_spi_remove(struct spi_device *spi)

0 commit comments

Comments
 (0)