spi: altera-platform: switch to managed controller allocation

Switch to device managed controller allocation for consistency and to
simplify error handling.

Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20260511150408.796155-2-johan@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Johan Hovold 2026-05-11 17:03:57 +02:00 committed by Mark Brown
parent 5200f5f493
commit a7a24f0eaa
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -39,12 +39,12 @@ static int altera_spi_probe(struct platform_device *pdev)
enum altera_spi_type type = ALTERA_SPI_TYPE_UNKNOWN;
struct altera_spi *hw;
struct spi_controller *host;
int err = -ENODEV;
int err;
u16 i;
host = spi_alloc_host(&pdev->dev, sizeof(struct altera_spi));
host = devm_spi_alloc_host(&pdev->dev, sizeof(struct altera_spi));
if (!host)
return err;
return -ENOMEM;
/* setup the host state. */
host->bus_num = -1;
@ -54,8 +54,7 @@ static int altera_spi_probe(struct platform_device *pdev)
dev_err(&pdev->dev,
"Invalid number of chipselect: %u\n",
pdata->num_chipselect);
err = -EINVAL;
goto exit;
return -EINVAL;
}
host->num_chipselect = pdata->num_chipselect;
@ -80,7 +79,7 @@ static int altera_spi_probe(struct platform_device *pdev)
hw->regmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!hw->regmap) {
dev_err(&pdev->dev, "get regmap failed\n");
goto exit;
return -ENODEV;
}
regoff = platform_get_resource(pdev, IORESOURCE_REG, 0);
@ -90,17 +89,14 @@ static int altera_spi_probe(struct platform_device *pdev)
void __iomem *res;
res = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(res)) {
err = PTR_ERR(res);
goto exit;
}
if (IS_ERR(res))
return PTR_ERR(res);
hw->regmap = devm_regmap_init_mmio(&pdev->dev, res,
&spi_altera_config);
if (IS_ERR(hw->regmap)) {
dev_err(&pdev->dev, "regmap mmio init failed\n");
err = PTR_ERR(hw->regmap);
goto exit;
return PTR_ERR(hw->regmap);
}
}
@ -112,12 +108,12 @@ static int altera_spi_probe(struct platform_device *pdev)
err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0,
pdev->name, host);
if (err)
goto exit;
return err;
}
err = devm_spi_register_controller(&pdev->dev, host);
if (err)
goto exit;
return err;
if (pdata) {
for (i = 0; i < pdata->num_devices; i++) {
@ -131,9 +127,6 @@ static int altera_spi_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "regoff %u, irq %d\n", hw->regoff, hw->irq);
return 0;
exit:
spi_controller_put(host);
return err;
}
#ifdef CONFIG_OF