* [PATCH v6 1/2] dma: Add devm_dma_request_chan()
2025-05-15 8:31 [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
@ 2025-05-15 8:31 ` Bence Csókás
2025-05-15 8:31 ` [PATCH v6 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()` Bence Csókás
2025-05-15 8:45 ` [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
2 siblings, 0 replies; 8+ messages in thread
From: Bence Csókás @ 2025-05-15 8:31 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 [flat|nested] 8+ messages in thread* [PATCH v6 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()`
2025-05-15 8:31 [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
2025-05-15 8:31 ` [PATCH v6 1/2] dma: Add devm_dma_request_chan() Bence Csókás
@ 2025-05-15 8:31 ` Bence Csókás
2025-05-15 8:45 ` [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
2 siblings, 0 replies; 8+ messages in thread
From: Bence Csókás @ 2025-05-15 8:31 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 [flat|nested] 8+ messages in thread* Re: [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-05-15 8:31 [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Bence Csókás
2025-05-15 8:31 ` [PATCH v6 1/2] dma: Add devm_dma_request_chan() Bence Csókás
2025-05-15 8:31 ` [PATCH v6 2/2] spi: atmel-quadspi: Use `devm_dma_request_chan()` Bence Csókás
@ 2025-05-15 8:45 ` Mark Brown
2025-05-15 9:14 ` Csókás Bence
2 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2025-05-15 8:45 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: 773 bytes --]
On Thu, May 15, 2025 at 10:31:28AM +0200, Bence Csókás wrote:
> Change in v4:
> * split PM imbalance fix (now merged) and DMA cleanup (this series)
> Change in v6:
> * rebase to spi/for-next, see note below:
>
> There is currently no difference in drivers/dma/dmaengine.c between it and
> dma/next [1], therefore PATCH 1/2 should be safe for Vinod to apply. But
> this way PATCH 2/2 is trivial to apply. I didn't want to pull the whole
> linux-next tree, but if any ofyou run into problems, let me know, and I'll
> rebase the series on it instead.
I can't tell what the plan is here, or what the status is for the first
patch (since I'm not CCed). The second patch depends on a new API
introduced in the first patch so it can't be merged independently.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-05-15 8:45 ` [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c Mark Brown
@ 2025-05-15 9:14 ` Csókás Bence
2025-05-15 9:22 ` Mark Brown
0 siblings, 1 reply; 8+ messages in thread
From: Csókás Bence @ 2025-05-15 9:14 UTC (permalink / raw)
To: Mark Brown
Cc: dmaengine, linux-kernel, linux-spi, linux-arm-kernel, Vinod Koul,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
Hi,
On 2025. 05. 15. 10:45, Mark Brown wrote:
> On Thu, May 15, 2025 at 10:31:28AM +0200, Bence Csókás wrote:
>
>> Change in v4:
>> * split PM imbalance fix (now merged) and DMA cleanup (this series)
>> Change in v6:
>> * rebase to spi/for-next, see note below:
>>
>> There is currently no difference in drivers/dma/dmaengine.c between it and
>> dma/next [1], therefore PATCH 1/2 should be safe for Vinod to apply. But
>> this way PATCH 2/2 is trivial to apply. I didn't want to pull the whole
>> linux-next tree, but if any ofyou run into problems, let me know, and I'll
>> rebase the series on it instead.
>
> I can't tell what the plan is here, or what the status is for the first
> patch (since I'm not CCed). The second patch depends on a new API
> introduced in the first patch so it can't be merged independently.
Yes, the situation is a bit convoluted. Obviously 2/2 will be applied
after 1/2, in a similar vein than the former PM series.
So what I was trying to say: Vinod should be able to apply 1/2 to his
branch (dma/next) right now, which can then be merged to spi/for-next.
This merged branch should be able to then cleanly apply 2/2.
Bence
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-05-15 9:14 ` Csókás Bence
@ 2025-05-15 9:22 ` Mark Brown
2025-05-15 9:26 ` Csókás Bence
0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2025-05-15 9:22 UTC (permalink / raw)
To: Csókás Bence
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: 981 bytes --]
On Thu, May 15, 2025 at 11:14:22AM +0200, Csókás Bence wrote:
> On 2025. 05. 15. 10:45, Mark Brown wrote:
> > I can't tell what the plan is here, or what the status is for the first
> > patch (since I'm not CCed). The second patch depends on a new API
> > introduced in the first patch so it can't be merged independently.
> Yes, the situation is a bit convoluted. Obviously 2/2 will be applied after
> 1/2, in a similar vein than the former PM series.
> So what I was trying to say: Vinod should be able to apply 1/2 to his branch
> (dma/next) right now, which can then be merged to spi/for-next. This merged
> branch should be able to then cleanly apply 2/2.
I wouldn't expect to pull the whole DMA tree in, that'll have a huge
amount of extra stuff in it - if I was going to pull something I'd
expect a topic branch. Wouldn't it be simpler for me to just apply both
patches at this point if there's no conflicts with the DMA tree? We're
at -rc6 now...
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-05-15 9:22 ` Mark Brown
@ 2025-05-15 9:26 ` Csókás Bence
2025-05-15 9:36 ` Mark Brown
0 siblings, 1 reply; 8+ messages in thread
From: Csókás Bence @ 2025-05-15 9:26 UTC (permalink / raw)
To: Mark Brown
Cc: dmaengine, linux-kernel, linux-spi, linux-arm-kernel, Vinod Koul,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
Rafael J. Wysocki, Tudor Ambarus
Hi,
On 2025. 05. 15. 11:22, Mark Brown wrote:
> On Thu, May 15, 2025 at 11:14:22AM +0200, Csókás Bence wrote:
>> On 2025. 05. 15. 10:45, Mark Brown wrote:
>
>>> I can't tell what the plan is here, or what the status is for the first
>>> patch (since I'm not CCed). The second patch depends on a new API
>>> introduced in the first patch so it can't be merged independently.
>
>> Yes, the situation is a bit convoluted. Obviously 2/2 will be applied after
>> 1/2, in a similar vein than the former PM series.
>
>> So what I was trying to say: Vinod should be able to apply 1/2 to his branch
>> (dma/next) right now, which can then be merged to spi/for-next. This merged
>> branch should be able to then cleanly apply 2/2.
>
> I wouldn't expect to pull the whole DMA tree in, that'll have a huge
> amount of extra stuff in it - if I was going to pull something I'd
> expect a topic branch.
Fair point.
> Wouldn't it be simpler for me to just apply both
> patches at this point if there's no conflicts with the DMA tree? We're
> at -rc6 now...
That also works for me. I should send 1/2 to you as well, correct?
Bence
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/2] Add `devm_dma_request_chan()` to simplify probe path in atmel-quadspi.c
2025-05-15 9:26 ` Csókás Bence
@ 2025-05-15 9:36 ` Mark Brown
0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2025-05-15 9:36 UTC (permalink / raw)
To: Csókás Bence
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: 600 bytes --]
On Thu, May 15, 2025 at 11:26:57AM +0200, Csókás Bence wrote:
> On 2025. 05. 15. 11:22, Mark Brown wrote:
> > Wouldn't it be simpler for me to just apply both
> > patches at this point if there's no conflicts with the DMA tree? We're
> > at -rc6 now...
> That also works for me. I should send 1/2 to you as well, correct?
I think at this point with the merge window likely to open on Sunday
it's probably easiest to just resend the SPI patch after the merge
window, it'll likely take more time/effort to work out what to do than
it will for the reset changes to land in Linus' tree.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread