* [PATCHv2] spi: ppc4xx: devm-ify probe and drop manual resource management
@ 2026-07-21 1:02 Rosen Penev
0 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-07-21 1:02 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, open list
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.
Sanity check for devm_platform_ioremap_resource removed as it's
unnecessary.
Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: mention Sanity check removal.
drivers/spi/spi-ppc4xx.c | 107 ++++++++++-----------------------------
1 file changed, 27 insertions(+), 80 deletions(-)
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 46ac58dfb3fc..7823b3814a17 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -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;
+ unsigned int opb_freq;
+ 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);
- if (clk == NULL) {
- dev_err(dev, "OPB: no clock-frequency property set\n");
- of_node_put(opbnp);
- ret = -ENODEV;
- goto free_host;
- }
- hw->opb_freq = *clk;
- hw->opb_freq >>= 2;
+ ret = of_property_read_u32(opbnp, "clock-frequency", &opb_freq);
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;
+ if (ret)
+ dev_err(dev, "OPB: no clock-frequency property set\n");
+ return -ENODEV;
}
- hw->regs = ioremap(hw->mapbase, sizeof(struct spi_ppc4xx_regs));
+ hw->opb_freq = opb_freq;
+ hw->opb_freq >>= 2;
+ hw->regs = regs;
+ hw->irqnum = irqnum;
- 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 ret;
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[] = {
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCHv2] spi: ppc4xx: devm-ify probe and drop manual resource management
@ 2026-07-20 0:30 Rosen Penev
2026-07-20 12:38 ` Mark Brown
2026-07-27 17:44 ` Mark Brown
0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-07-20 0:30 UTC (permalink / raw)
To: linux-spi; +Cc: Mark Brown, open list
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.
Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: handle potential -EPROBE_DEFER first.
drivers/spi/spi-ppc4xx.c | 97 +++++++++-------------------------------
1 file changed, 22 insertions(+), 75 deletions(-)
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 46ac58dfb3fc..95c034cf2336 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -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[] = {
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCHv2] spi: ppc4xx: devm-ify probe and drop manual resource management
2026-07-20 0:30 Rosen Penev
@ 2026-07-20 12:38 ` Mark Brown
2026-07-27 17:44 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-07-20 12:38 UTC (permalink / raw)
To: Rosen Penev; +Cc: linux-spi, open list
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]
On Sun, Jul 19, 2026 at 05:30:43PM -0700, Rosen Penev wrote:
> Replace open-coded resource handling with devm helpers:
> - 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;
> - }
> -
The size validation gets lost here. Not sure that really matters, but
it wasn't mentioned in the changelog.
> + 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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCHv2] spi: ppc4xx: devm-ify probe and drop manual resource management
2026-07-20 0:30 Rosen Penev
2026-07-20 12:38 ` Mark Brown
@ 2026-07-27 17:44 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-07-27 17:44 UTC (permalink / raw)
To: linux-spi, Rosen Penev; +Cc: linux-kernel
On Sun, 19 Jul 2026 17:30:43 -0700, Rosen Penev wrote:
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-27 22:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-21 1:02 [PATCHv2] spi: ppc4xx: devm-ify probe and drop manual resource management Rosen Penev
-- strict thread matches above, loose matches on Subject: below --
2026-07-20 0:30 Rosen Penev
2026-07-20 12:38 ` Mark Brown
2026-07-27 17:44 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox