* [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
@ 2025-06-10 8:22 Bence Csókás
2025-06-10 8:22 ` [PATCH v7 1/2] dma: Add devm_dma_request_chan() Bence Csókás
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Bence Csókás @ 2025-06-10 8:22 UTC (permalink / raw)
To: dmaengine, linux-kernel, linux-spi, linux-arm-kernel
Cc: Bence Csókás, Vinod Koul, Mark Brown, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Rafael J. Wysocki,
Tudor Ambarus
The probe function of the atmel-quadspi driver got quite convoluted,
especially since the addition of SAMA7G5 support, that was forward-ported
from an older vendor kernel. To alleivate this - and similar problems in
the future - an effort was made to migrate as many functions as possible,
to their devm_ managed counterparts. Patch 1/2 adds the new
`devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
simplify the probe() function.
Change in v4:
* split PM imbalance fix (now merged) and DMA cleanup (this series)
Change in v6:
* rebase to spi/for-next
Change in v7:
* rebase to dma/next
[1]
commit 3c018bf5a0ee ("dmaengine: idxd: Remove unused pointer and macro")
Links to previous versions:
pre-series:
https://lore.kernel.org/linux-kernel/20241222141427.819222-1-csokas.bence@prolan.hu/
https://lore.kernel.org/linux-kernel/20250114222851.1023194-1-csokas.bence@prolan.hu/
v1:
https://lore.kernel.org/linux-kernel/20250115160244.1102881-1-csokas.bence@prolan.hu/
v2:
https://lore.kernel.org/linux-kernel/20250124085221.766303-8-csokas.bence@prolan.hu/
v3:
https://lore.kernel.org/linux-kernel/20250207124802.165408-1-csokas.bence@prolan.hu/
v4:
https://lore.kernel.org/lkml/20250317135340.382532-1-csokas.bence@prolan.hu/
v5:
https://lore.kernel.org/lkml/20250505184936.312274-1-csokas.bence@prolan.hu
v6:
https://lore.kernel.org/lkml/20250515083132.255410-1-csokas.bence@prolan.hu
Bence Csókás (2):
dma: Add devm_dma_request_chan()
spi: atmel-quadspi: Use `devm_dma_request_chan()`
drivers/dma/dmaengine.c | 30 +++++++++++++++++++++++
drivers/spi/atmel-quadspi.c | 48 ++++++++++---------------------------
include/linux/dmaengine.h | 7 ++++++
3 files changed, 50 insertions(+), 35 deletions(-)
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v7 1/2] dma: Add devm_dma_request_chan()
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
@ 2025-06-10 8:22 ` Bence Csókás
2025-08-26 8:21 ` Andy Shevchenko
2025-06-10 8:22 ` [PATCH v7 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()` Bence Csókás
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Bence Csókás @ 2025-06-10 8:22 UTC (permalink / raw)
To: dmaengine, linux-kernel; +Cc: Bence Csókás, Vinod Koul
Expand the arsenal of devm functions for DMA devices, this time for
requesting channels.
Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
---
drivers/dma/dmaengine.c | 30 ++++++++++++++++++++++++++++++
include/linux/dmaengine.h | 7 +++++++
2 files changed, 37 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 758fcd0546d8..ca13cd39330b 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -926,6 +926,36 @@ void dma_release_channel(struct dma_chan *chan)
}
EXPORT_SYMBOL_GPL(dma_release_channel);
+static void dmaenginem_release_channel(void *chan)
+{
+ dma_release_channel(chan);
+}
+
+/**
+ * devm_dma_request_chan - try to allocate an exclusive slave channel
+ * @dev: pointer to client device structure
+ * @name: slave channel name
+ *
+ * Returns pointer to appropriate DMA channel on success or an error pointer.
+ *
+ * The operation is managed and will be undone on driver detach.
+ */
+
+struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
+{
+ struct dma_chan *chan = dma_request_chan(dev, name);
+ int ret = 0;
+
+ if (!IS_ERR(chan))
+ ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
+
+ if (ret)
+ return ERR_PTR(ret);
+
+ return chan;
+}
+EXPORT_SYMBOL_GPL(devm_dma_request_chan);
+
/**
* dmaengine_get - register interest in dma_channels
*/
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index bb146c5ac3e4..6de7c05d6bd8 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1524,6 +1524,7 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
struct dma_chan *dma_request_chan(struct device *dev, const char *name);
struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
+struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name);
void dma_release_channel(struct dma_chan *chan);
int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
@@ -1560,6 +1561,12 @@ static inline struct dma_chan *dma_request_chan_by_mask(
{
return ERR_PTR(-ENODEV);
}
+
+static inline struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
+{
+ return ERR_PTR(-ENODEV);
+}
+
static inline void dma_release_channel(struct dma_chan *chan)
{
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v7 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()`
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
2025-06-10 8:22 ` [PATCH v7 1/2] dma: Add devm_dma_request_chan() Bence Csókás
@ 2025-06-10 8:22 ` Bence Csókás
2025-06-10 11:49 ` [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Bence Csókás @ 2025-06-10 8:22 UTC (permalink / raw)
To: linux-spi, linux-arm-kernel, linux-kernel
Cc: Bence Csókás, Mark Brown, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea
Leave releasing of DMA channels up to the devm facilities. This way we can
eliminate the rest of the "goto ladder".
Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
---
drivers/spi/atmel-quadspi.c | 48 ++++++++++---------------------------
1 file changed, 13 insertions(+), 35 deletions(-)
diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index 2f6797324227..fc555c0ce52e 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -1285,18 +1285,21 @@ static int atmel_qspi_dma_init(struct spi_controller *ctrl)
struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
int ret;
- aq->rx_chan = dma_request_chan(&aq->pdev->dev, "rx");
+ aq->rx_chan = devm_dma_request_chan(&aq->pdev->dev, "rx");
if (IS_ERR(aq->rx_chan)) {
ret = dev_err_probe(&aq->pdev->dev, PTR_ERR(aq->rx_chan),
"RX DMA channel is not available\n");
- goto null_rx_chan;
+ aq->rx_chan = NULL;
+ return ret;
}
- aq->tx_chan = dma_request_chan(&aq->pdev->dev, "tx");
+ aq->tx_chan = devm_dma_request_chan(&aq->pdev->dev, "tx");
if (IS_ERR(aq->tx_chan)) {
ret = dev_err_probe(&aq->pdev->dev, PTR_ERR(aq->tx_chan),
"TX DMA channel is not available\n");
- goto release_rx_chan;
+ aq->rx_chan = NULL;
+ aq->tx_chan = NULL;
+ return ret;
}
ctrl->dma_rx = aq->rx_chan;
@@ -1307,21 +1310,6 @@ static int atmel_qspi_dma_init(struct spi_controller *ctrl)
dma_chan_name(aq->tx_chan), dma_chan_name(aq->rx_chan));
return 0;
-
-release_rx_chan:
- dma_release_channel(aq->rx_chan);
- aq->tx_chan = NULL;
-null_rx_chan:
- aq->rx_chan = NULL;
- return ret;
-}
-
-static void atmel_qspi_dma_release(struct atmel_qspi *aq)
-{
- if (aq->rx_chan)
- dma_release_channel(aq->rx_chan);
- if (aq->tx_chan)
- dma_release_channel(aq->tx_chan);
}
static const struct atmel_qspi_ops atmel_qspi_ops = {
@@ -1426,14 +1414,13 @@ static int atmel_qspi_probe(struct platform_device *pdev)
/* Request the IRQ */
irq = platform_get_irq(pdev, 0);
- if (irq < 0) {
- err = irq;
- goto dma_release;
- }
+ if (irq < 0)
+ return irq;
+
err = devm_request_irq(&pdev->dev, irq, atmel_qspi_interrupt,
0, dev_name(&pdev->dev), aq);
if (err)
- goto dma_release;
+ return err;
pm_runtime_set_autosuspend_delay(&pdev->dev, 500);
pm_runtime_use_autosuspend(&pdev->dev);
@@ -1442,22 +1429,16 @@ static int atmel_qspi_probe(struct platform_device *pdev)
err = atmel_qspi_init(aq);
if (err)
- goto dma_release;
+ return err;
err = spi_register_controller(ctrl);
if (err)
- goto dma_release;
+ return err;
pm_runtime_mark_last_busy(&pdev->dev);
pm_runtime_put_autosuspend(&pdev->dev);
return 0;
-
-dma_release:
- if (aq->caps->has_dma)
- atmel_qspi_dma_release(aq);
-
- return err;
}
static int atmel_qspi_sama7g5_suspend(struct atmel_qspi *aq)
@@ -1507,9 +1488,6 @@ static void atmel_qspi_remove(struct platform_device *pdev)
ret = pm_runtime_get_sync(&pdev->dev);
if (ret >= 0) {
- if (aq->caps->has_dma)
- atmel_qspi_dma_release(aq);
-
if (aq->caps->has_gclk) {
ret = atmel_qspi_sama7g5_suspend(aq);
if (ret)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
2025-06-10 8:22 ` [PATCH v7 1/2] dma: Add devm_dma_request_chan() Bence Csókás
2025-06-10 8:22 ` [PATCH v7 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()` Bence Csókás
@ 2025-06-10 11:49 ` Mark Brown
2025-06-26 22:20 ` Vinod Koul
2025-06-26 22:14 ` (subset) " Vinod Koul
` (2 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2025-06-10 11:49 UTC (permalink / raw)
To: Bence Csókás
Cc: dmaengine, linux-kernel, linux-spi, linux-arm-kernel, Vinod Koul,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
[-- Attachment #1: Type: text/plain, Size: 321 bytes --]
On Tue, Jun 10, 2025 at 10:22:52AM +0200, Bence Csókás wrote:
> to their devm_ managed counterparts. Patch 1/2 adds the new
> `devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
> simplify the probe() function.
I'm not copied on patch 1, please let me know if/when there's some
progress there.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: (subset) [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
` (2 preceding siblings ...)
2025-06-10 11:49 ` [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
@ 2025-06-26 22:14 ` Vinod Koul
2025-06-26 22:48 ` Vinod Koul
2025-06-27 12:51 ` Mark Brown
5 siblings, 0 replies; 9+ messages in thread
From: Vinod Koul @ 2025-06-26 22:14 UTC (permalink / raw)
To: dmaengine, linux-kernel, linux-spi, linux-arm-kernel,
Bence Csókás
Cc: Mark Brown, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
On Tue, 10 Jun 2025 10:22:52 +0200, Bence Csókás wrote:
> The probe function of the atmel-quadspi driver got quite convoluted,
> especially since the addition of SAMA7G5 support, that was forward-ported
> from an older vendor kernel. To alleivate this - and similar problems in
> the future - an effort was made to migrate as many functions as possible,
> to their devm_ managed counterparts. Patch 1/2 adds the new
> `devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
> simplify the probe() function.
>
> [...]
Applied, thanks!
[1/2] dma: Add devm_dma_request_chan()
commit: 56137a53f8ebb400f4098ca26ef18934e9a4de45
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-06-10 11:49 ` [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
@ 2025-06-26 22:20 ` Vinod Koul
0 siblings, 0 replies; 9+ messages in thread
From: Vinod Koul @ 2025-06-26 22:20 UTC (permalink / raw)
To: Mark Brown
Cc: Bence Csókás, dmaengine, linux-kernel, linux-spi,
linux-arm-kernel, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Rafael J. Wysocki, Tudor Ambarus
On 10-06-25, 12:49, Mark Brown wrote:
> On Tue, Jun 10, 2025 at 10:22:52AM +0200, Bence Csókás wrote:
>
> > to their devm_ managed counterparts. Patch 1/2 adds the new
> > `devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
> > simplify the probe() function.
>
> I'm not copied on patch 1, please let me know if/when there's some
> progress there.
You can pull in this tag for the dependency
The following changes since commit 19272b37aa4f83ca52bdf9c16d5d81bdd1354494:
Linux 6.16-rc1 (2025-06-08 13:44:43 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git tags/dmaengine_devm_api
for you to fetch changes up to 08bf1663c21a3e815eda28fa242d84c945ca3b94:
dmaengine: Add devm_dma_request_chan() (2025-06-26 15:18:04 -0700)
----------------------------------------------------------------
dmaengine: tag for devm api
----------------------------------------------------------------
Bence Csókás (1):
dmaengine: Add devm_dma_request_chan()
drivers/dma/dmaengine.c | 30 ++++++++++++++++++++++++++++++
include/linux/dmaengine.h | 7 +++++++
2 files changed, 37 insertions(+)
Thanks
--
~Vinod
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
` (3 preceding siblings ...)
2025-06-26 22:14 ` (subset) " Vinod Koul
@ 2025-06-26 22:48 ` Vinod Koul
2025-06-27 12:51 ` Mark Brown
5 siblings, 0 replies; 9+ messages in thread
From: Vinod Koul @ 2025-06-26 22:48 UTC (permalink / raw)
To: dmaengine, linux-kernel, linux-spi, linux-arm-kernel,
Bence Csókás
Cc: Mark Brown, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
On Tue, 10 Jun 2025 10:22:52 +0200, Bence Csókás wrote:
> The probe function of the atmel-quadspi driver got quite convoluted,
> especially since the addition of SAMA7G5 support, that was forward-ported
> from an older vendor kernel. To alleivate this - and similar problems in
> the future - an effort was made to migrate as many functions as possible,
> to their devm_ managed counterparts. Patch 1/2 adds the new
> `devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
> simplify the probe() function.
>
> [...]
Applied, thanks!
[1/2] dma: Add devm_dma_request_chan()
commit: 08bf1663c21a3e815eda28fa242d84c945ca3b94
[2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()`
(no commit info)
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
` (4 preceding siblings ...)
2025-06-26 22:48 ` Vinod Koul
@ 2025-06-27 12:51 ` Mark Brown
5 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2025-06-27 12:51 UTC (permalink / raw)
To: dmaengine, linux-kernel, linux-spi, linux-arm-kernel,
Bence Csókás
Cc: Vinod Koul, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
On Tue, 10 Jun 2025 10:22:52 +0200, Bence Csókás wrote:
> The probe function of the atmel-quadspi driver got quite convoluted,
> especially since the addition of SAMA7G5 support, that was forward-ported
> from an older vendor kernel. To alleivate this - and similar problems in
> the future - an effort was made to migrate as many functions as possible,
> to their devm_ managed counterparts. Patch 1/2 adds the new
> `devm_dma_request_chan()` function. Patch 2/2 then uses this APIs to
> simplify the probe() function.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/2] dma: Add devm_dma_request_chan()
(no commit info)
[2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()`
commit: 2555691165a0285a4617230fed859f20dcc51608
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] 9+ messages in thread
* Re: [PATCH v7 1/2] dma: Add devm_dma_request_chan()
2025-06-10 8:22 ` [PATCH v7 1/2] dma: Add devm_dma_request_chan() Bence Csókás
@ 2025-08-26 8:21 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2025-08-26 8:21 UTC (permalink / raw)
To: Bence Csókás; +Cc: dmaengine, linux-kernel, Vinod Koul
Tue, Jun 10, 2025 at 10:22:53AM +0200, Bence Csókás kirjoitti:
> Expand the arsenal of devm functions for DMA devices, this time for
> requesting channels.
...
> +/**
> + * devm_dma_request_chan - try to allocate an exclusive slave channel
> + * @dev: pointer to client device structure
> + * @name: slave channel name
> + *
> + * Returns pointer to appropriate DMA channel on success or an error pointer.
> + *
> + * The operation is managed and will be undone on driver detach.
This introduced a kernel-doc validation issue (Missing Return section).
> + */
> +
Unneeded blank line.
> +struct dma_chan *devm_dma_request_chan(struct device *dev, const char *name)
> + struct dma_chan *chan = dma_request_chan(dev, name);
> + int ret = 0;
> +
> + if (!IS_ERR(chan))
> + ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
> +
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return chan;
Hmm... We usually use "error check" pattern
Compare to
struct dma_chan *chan;
int ret;
chan = dma_request_chan(dev, name);
if (IS_ERR(chan))
return chan;
ret = devm_add_action_or_reset(dev, dmaenginem_release_channel, chan);
if (ret)
return ERR_PTR(ret);
return chan;
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-08-26 8:21 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 8:22 [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
2025-06-10 8:22 ` [PATCH v7 1/2] dma: Add devm_dma_request_chan() Bence Csókás
2025-08-26 8:21 ` Andy Shevchenko
2025-06-10 8:22 ` [PATCH v7 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()` Bence Csókás
2025-06-10 11:49 ` [PATCH v7 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
2025-06-26 22:20 ` Vinod Koul
2025-06-26 22:14 ` (subset) " Vinod Koul
2025-06-26 22:48 ` Vinod Koul
2025-06-27 12:51 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).