spi: ppc4xx: devm-ify probe and drop manual resource management
PATCH v2 1/1 spi: ppc4xx: devm-ify probe and drop manual resource management
Replace open-coded resource handling with devm helpers:
- spi_alloc_host -> devm_spi_alloc_host
- of_address_to_resource + ioremap + request_mem_region
-> devm_platform_ioremap_resource
- request_irq -> devm_request_irq
- remove now-unused mapbase/mapsize fields from struct ppc4xx_spi
- move of_node_put(opbnp) earlier to simplify error paths
- delete the entire error-unwinding goto chain
Move devm_platform_ioremap_resource() and platform_get_irq() up in order to avoid doing work if -EPROBE_DEFER is returned.
---
v2: handle potential -EPROBE_DEFER first.
drivers/spi/spi-ppc4xx.c | 97 +++++++++------------------------------- 1 file changed, 22 insertions(+), 75 deletions(-)
drivers/spi/spi-ppc4xx.c +22 -75
@@ -112,8 +112,6 @@ struct ppc4xx_spi {struct spi_bitbang bitbang;struct completion done; -u64 mapbase; -u64 mapsize;int irqnum;/* need this to set the SPI clock */ unsigned int opb_freq;
@@ -337,14 +335,24 @@ static int spi_ppc4xx_of_probe(struct platform_device *op)struct ppc4xx_spi *hw;struct spi_controller *host;struct spi_bitbang *bbp; -struct resource resource;struct device_node *np = op->dev.of_node;struct device *dev = &op->dev;struct device_node *opbnp;int ret;const unsigned int *clk; +void __iomem *regs; +int irqnum; + + regs =devm_platform_ioremap_resource (op,0 ); +if (IS_ERR (regs)) +return PTR_ERR (regs); - host =spi_alloc_host (dev,sizeof (*hw)); +/* Request IRQ */ + irqnum =platform_get_irq (op,0 ); +if (irqnum <0 ) +return irqnum; + + host =devm_spi_alloc_host (dev,sizeof (*hw));if (host ==NULL )return -ENOMEM ; host->dev.of_node = np;
@@ -379,88 +387,31 @@ static int spi_ppc4xx_of_probe(struct platform_device *op) opbnp =of_find_compatible_node (NULL ,NULL ,"ibm,opb" );if (opbnp ==NULL ) {dev_err (dev,"OPB: cannot find node\n" ); - ret = -ENODEV ; - goto free_host; +return -ENODEV ; }/* Get the clock (Hz) for the OPB */ clk =of_get_property (opbnp,"clock-frequency" ,NULL ); +of_node_put (opbnp);if (clk ==NULL ) {dev_err (dev,"OPB: no clock-frequency property set\n" ); -of_node_put (opbnp); - ret = -ENODEV ; - goto free_host; +return -ENODEV ; } hw->opb_freq = *clk; hw->opb_freq >>=2 ; -of_node_put (opbnp); - - ret =of_address_to_resource (np,0 , &resource); -if (ret) { -dev_err (dev,"error while parsing device node resource\n" ); - goto free_host; - } - hw->mapbase = resource.start; - hw->mapsize =resource_size (&resource); - -/* Sanity check */ -if (hw->mapsize <sizeof (struct spi_ppc4xx_regs )) { -dev_err (dev,"too small to map registers\n" ); - ret = -EINVAL ; - goto free_host; - } - -/* Request IRQ */ - ret =platform_get_irq (op,0 ); -if (ret <0 ) - goto free_host; - hw->irqnum = ret; - - ret =request_irq (hw->irqnum, spi_ppc4xx_int, -0 ,"spi_ppc4xx_of" , (void *)hw); -if (ret) { -dev_err (dev,"unable to allocate interrupt\n" ); - goto free_host; - } -if (!request_mem_region (hw->mapbase, hw->mapsize,DRIVER_NAME )) { -dev_err (dev,"resource unavailable\n" ); - ret = -EBUSY ; - goto request_mem_error; - } + hw->regs = regs; + hw->irqnum = irqnum; - hw->regs =ioremap (hw->mapbase,sizeof (struct spi_ppc4xx_regs )); - -if (!hw->regs) { -dev_err (dev,"unable to memory map registers\n" ); - ret = -ENXIO ; - goto map_io_error; - } + ret =devm_request_irq (&op->dev, hw->irqnum, spi_ppc4xx_int, +0 ,"spi_ppc4xx_of" , hw); +if (ret) +return dev_err_probe (dev, ret,"unable to allocate interrupt\n" );spi_ppc4xx_enable (hw);/* Finally register our spi controller */ dev->dma_mask =0 ; - ret =spi_bitbang_start (bbp); -if (ret) { -dev_err (dev,"failed to register SPI host\n" ); - goto unmap_regs; - } - -dev_info (dev,"driver initialized\n" ); - -return 0 ; - -unmap_regs: -iounmap (hw->regs); -map_io_error: -release_mem_region (hw->mapbase, hw->mapsize); -request_mem_error: -free_irq (hw->irqnum, hw); -free_host: -spi_controller_put (host); - -dev_err (dev,"initialization failed\n" ); -return ret; +return spi_bitbang_start (bbp); }static void spi_ppc4xx_of_remove (struct platform_device *op)
@@ -469,10 +420,6 @@ static void spi_ppc4xx_of_remove(struct platform_device *op)struct ppc4xx_spi *hw =spi_controller_get_devdata (host);spi_bitbang_stop (&hw->bitbang); -release_mem_region (hw->mapbase, hw->mapsize); -free_irq (hw->irqnum, hw); -iounmap (hw->regs); -spi_controller_put (host); }static const struct of_device_id spi_ppc4xx_of_match[] = {
Signature · 1 line
2.55.0
Mark Brown
maintainerQuoted 7 lines · Rosen Penev
Replace open-coded resource handling with devm helpers:
drivers/spi/spi-ppc4xx.c +0
-5- ret =of_address_to_resource (np,0 , &resource); -if (ret) { -dev_err (dev,"error while parsing device node resource\n" ); - goto free_host; - }
drivers/spi/spi-ppc4xx.c static int spi_ppc4xx_of_probe(struct platform_device *op) · line 411
Quoted 10 lines
drivers/spi/spi-ppc4xx.c +0
-10- hw->mapbase = resource.start; - hw->mapsize =resource_size (&resource); - -/* Sanity check */ -if (hw->mapsize <sizeof (struct spi_ppc4xx_regs )) { -dev_err (dev,"too small to map registers\n" ); - ret = -EINVAL ; - goto free_host; - } -
The size validation gets lost here. Not sure that really matters, but it wasn't mentioned in the changelog.
drivers/spi/spi-ppc4xx.c static int spi_ppc4xx_of_probe(struct platform_device *op) · line 408
Quoted 4 lines
drivers/spi/spi-ppc4xx.c +4
-0+ ret =devm_request_irq (&op->dev, hw->irqnum, spi_ppc4xx_int, +0 ,"spi_ppc4xx_of" , hw); +if (ret) +return dev_err_probe (dev, ret,"unable to allocate interrupt\n" );
devm_request_irq() has it's own logging so we don't need to duplicate.
Mark Brown
maintainerQuoted 1 line · Rosen Penev
spi: ppc4xx: devm-ify probe and drop manual resource management
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.3
Thanks!
[1/1] spi: ppc4xx: devm-ify probe and drop manual resource management
https://git.kernel.org/broonie/spi/c/fd741c46ae03
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark