Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: spi-altera-dfl: Fix an error handling path

The spi_alloc_master() call is not undone in all error handling paths.
Moreover, there is no .remove function to release the allocated memory.

In order to fix both this issues, switch to devm_spi_alloc_master().

This allows further simplification of the probe.

Fixes: ba2fc167e944 ("spi: altera: Add DFL bus driver for Altera API Controller")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/0607bb59f4073f86abe5c585d35245aef0b045c6.1653805901.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Christophe JAILLET and committed by
Mark Brown
8e3ca32f f2906aa8

+5 -9
+5 -9
drivers/spi/spi-altera-dfl.c
··· 128 128 struct spi_master *master; 129 129 struct altera_spi *hw; 130 130 void __iomem *base; 131 - int err = -ENODEV; 131 + int err; 132 132 133 - master = spi_alloc_master(dev, sizeof(struct altera_spi)); 133 + master = devm_spi_alloc_master(dev, sizeof(struct altera_spi)); 134 134 if (!master) 135 135 return -ENOMEM; 136 136 ··· 159 159 altera_spi_init_master(master); 160 160 161 161 err = devm_spi_register_master(dev, master); 162 - if (err) { 163 - dev_err(dev, "%s failed to register spi master %d\n", __func__, err); 164 - goto exit; 165 - } 162 + if (err) 163 + return dev_err_probe(dev, err, "%s failed to register spi master\n", 164 + __func__); 166 165 167 166 if (dfl_dev->revision == FME_FEATURE_REV_MAX10_SPI_N5010) 168 167 strscpy(board_info.modalias, "m10-n5010", SPI_NAME_SIZE); ··· 178 179 } 179 180 180 181 return 0; 181 - exit: 182 - spi_master_put(master); 183 - return err; 184 182 } 185 183 186 184 static const struct dfl_device_id dfl_spi_altera_ids[] = {