* [PATCH v1 0/2] add edma src ID check at request channel @ 2024-06-21 10:49 Joy Zou 2024-06-21 10:49 ` [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() Joy Zou 2024-06-21 10:49 ` [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel Joy Zou 0 siblings, 2 replies; 7+ messages in thread From: Joy Zou @ 2024-06-21 10:49 UTC (permalink / raw) To: Frank.Li, vkoul; +Cc: imx, dmaengine, linux-kernel For the details, please check the patch commit log. Joy Zou (2): dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() dmaengine: fsl-edma: add edma src ID check at request channel drivers/dma/fsl-edma-main.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) -- 2.37.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() 2024-06-21 10:49 [PATCH v1 0/2] add edma src ID check at request channel Joy Zou @ 2024-06-21 10:49 ` Joy Zou 2024-06-21 14:48 ` Frank Li 2024-06-21 10:49 ` [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel Joy Zou 1 sibling, 1 reply; 7+ messages in thread From: Joy Zou @ 2024-06-21 10:49 UTC (permalink / raw) To: Frank.Li, vkoul; +Cc: imx, dmaengine, linux-kernel Introduce a scope guard to automatically unlock the mutex within fsl_edma3_xlate() to simplify the code. Prepare to add source ID checks in the future. Signed-off-by: Joy Zou <joy.zou@nxp.com> --- drivers/dma/fsl-edma-main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index c66185c5a199..d4f29ece69f5 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -153,7 +153,7 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, b_chmux = !!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHMUX); - mutex_lock(&fsl_edma->fsl_edma_mutex); + guard(mutex)(&fsl_edma->fsl_edma_mutex); list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, device_node) { @@ -177,18 +177,15 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, if (!b_chmux && i == dma_spec->args[0]) { chan = dma_get_slave_channel(chan); chan->device->privatecnt++; - mutex_unlock(&fsl_edma->fsl_edma_mutex); return chan; } else if (b_chmux && !fsl_chan->srcid) { /* if controller support channel mux, choose a free channel */ chan = dma_get_slave_channel(chan); chan->device->privatecnt++; fsl_chan->srcid = dma_spec->args[0]; - mutex_unlock(&fsl_edma->fsl_edma_mutex); return chan; } } - mutex_unlock(&fsl_edma->fsl_edma_mutex); return NULL; } -- 2.37.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() 2024-06-21 10:49 ` [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() Joy Zou @ 2024-06-21 14:48 ` Frank Li 0 siblings, 0 replies; 7+ messages in thread From: Frank Li @ 2024-06-21 14:48 UTC (permalink / raw) To: Joy Zou; +Cc: vkoul, imx, dmaengine, linux-kernel On Fri, Jun 21, 2024 at 06:49:31PM +0800, Joy Zou wrote: > Introduce a scope guard to automatically unlock the mutex within > fsl_edma3_xlate() to simplify the code. > > Prepare to add source ID checks in the future. > > Signed-off-by: Joy Zou <joy.zou@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/dma/fsl-edma-main.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c > index c66185c5a199..d4f29ece69f5 100644 > --- a/drivers/dma/fsl-edma-main.c > +++ b/drivers/dma/fsl-edma-main.c > @@ -153,7 +153,7 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, > > b_chmux = !!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHMUX); > > - mutex_lock(&fsl_edma->fsl_edma_mutex); > + guard(mutex)(&fsl_edma->fsl_edma_mutex); > list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, > device_node) { > > @@ -177,18 +177,15 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, > if (!b_chmux && i == dma_spec->args[0]) { > chan = dma_get_slave_channel(chan); > chan->device->privatecnt++; > - mutex_unlock(&fsl_edma->fsl_edma_mutex); > return chan; > } else if (b_chmux && !fsl_chan->srcid) { > /* if controller support channel mux, choose a free channel */ > chan = dma_get_slave_channel(chan); > chan->device->privatecnt++; > fsl_chan->srcid = dma_spec->args[0]; > - mutex_unlock(&fsl_edma->fsl_edma_mutex); > return chan; > } > } > - mutex_unlock(&fsl_edma->fsl_edma_mutex); > return NULL; > } > > -- > 2.37.1 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel 2024-06-21 10:49 [PATCH v1 0/2] add edma src ID check at request channel Joy Zou 2024-06-21 10:49 ` [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() Joy Zou @ 2024-06-21 10:49 ` Joy Zou 2024-06-21 14:47 ` Frank Li 2024-06-28 7:31 ` Vinod Koul 1 sibling, 2 replies; 7+ messages in thread From: Joy Zou @ 2024-06-21 10:49 UTC (permalink / raw) To: Frank.Li, vkoul; +Cc: imx, dmaengine, linux-kernel Check src ID to detect misuse of same src ID for multiple DMA channels. Signed-off-by: Joy Zou <joy.zou@nxp.com> --- drivers/dma/fsl-edma-main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index d4f29ece69f5..47939d010e59 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -100,6 +100,22 @@ static irqreturn_t fsl_edma_irq_handler(int irq, void *dev_id) return fsl_edma_err_handler(irq, dev_id); } +static bool fsl_edma_srcid_in_use(struct fsl_edma_engine *fsl_edma, u32 srcid) +{ + struct fsl_edma_chan *fsl_chan; + int i; + + for (i = 0; i < fsl_edma->n_chans; i++) { + fsl_chan = &fsl_edma->chans[i]; + + if (fsl_chan->srcid && srcid == fsl_chan->srcid) { + dev_err(&fsl_chan->pdev->dev, "The srcid is using! Can't use repeatly."); + return true; + } + } + return false; +} + static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, struct of_dma *ofdma) { @@ -117,6 +133,10 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, device_node) { if (chan->client_count) continue; + + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[1])) + return NULL; + if ((chan->chan_id / chans_per_mux) == dma_spec->args[0]) { chan = dma_get_slave_channel(chan); if (chan) { @@ -161,6 +181,8 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, continue; fsl_chan = to_fsl_edma_chan(chan); + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[0])) + return NULL; i = fsl_chan - fsl_edma->chans; fsl_chan->priority = dma_spec->args[1]; -- 2.37.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel 2024-06-21 10:49 ` [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel Joy Zou @ 2024-06-21 14:47 ` Frank Li 2024-06-28 7:31 ` Vinod Koul 1 sibling, 0 replies; 7+ messages in thread From: Frank Li @ 2024-06-21 14:47 UTC (permalink / raw) To: Joy Zou; +Cc: vkoul, imx, dmaengine, linux-kernel On Fri, Jun 21, 2024 at 06:49:32PM +0800, Joy Zou wrote: > Check src ID to detect misuse of same src ID for multiple DMA channels. > > Signed-off-by: Joy Zou <joy.zou@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/dma/fsl-edma-main.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c > index d4f29ece69f5..47939d010e59 100644 > --- a/drivers/dma/fsl-edma-main.c > +++ b/drivers/dma/fsl-edma-main.c > @@ -100,6 +100,22 @@ static irqreturn_t fsl_edma_irq_handler(int irq, void *dev_id) > return fsl_edma_err_handler(irq, dev_id); > } > > +static bool fsl_edma_srcid_in_use(struct fsl_edma_engine *fsl_edma, u32 srcid) > +{ > + struct fsl_edma_chan *fsl_chan; > + int i; > + > + for (i = 0; i < fsl_edma->n_chans; i++) { > + fsl_chan = &fsl_edma->chans[i]; > + > + if (fsl_chan->srcid && srcid == fsl_chan->srcid) { > + dev_err(&fsl_chan->pdev->dev, "The srcid is using! Can't use repeatly."); > + return true; > + } > + } > + return false; > +} > + > static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, > struct of_dma *ofdma) > { > @@ -117,6 +133,10 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, > list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, device_node) { > if (chan->client_count) > continue; > + > + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[1])) > + return NULL; > + > if ((chan->chan_id / chans_per_mux) == dma_spec->args[0]) { > chan = dma_get_slave_channel(chan); > if (chan) { > @@ -161,6 +181,8 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, > continue; > > fsl_chan = to_fsl_edma_chan(chan); > + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[0])) > + return NULL; > i = fsl_chan - fsl_edma->chans; > > fsl_chan->priority = dma_spec->args[1]; > -- > 2.37.1 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel 2024-06-21 10:49 ` [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel Joy Zou 2024-06-21 14:47 ` Frank Li @ 2024-06-28 7:31 ` Vinod Koul 2024-06-28 7:37 ` Joy Zou 1 sibling, 1 reply; 7+ messages in thread From: Vinod Koul @ 2024-06-28 7:31 UTC (permalink / raw) To: Joy Zou; +Cc: Frank.Li, imx, dmaengine, linux-kernel On 21-06-24, 18:49, Joy Zou wrote: > Check src ID to detect misuse of same src ID for multiple DMA channels. > > Signed-off-by: Joy Zou <joy.zou@nxp.com> > --- > drivers/dma/fsl-edma-main.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c > index d4f29ece69f5..47939d010e59 100644 > --- a/drivers/dma/fsl-edma-main.c > +++ b/drivers/dma/fsl-edma-main.c > @@ -100,6 +100,22 @@ static irqreturn_t fsl_edma_irq_handler(int irq, void *dev_id) > return fsl_edma_err_handler(irq, dev_id); > } > > +static bool fsl_edma_srcid_in_use(struct fsl_edma_engine *fsl_edma, u32 srcid) > +{ > + struct fsl_edma_chan *fsl_chan; > + int i; > + > + for (i = 0; i < fsl_edma->n_chans; i++) { > + fsl_chan = &fsl_edma->chans[i]; > + > + if (fsl_chan->srcid && srcid == fsl_chan->srcid) { > + dev_err(&fsl_chan->pdev->dev, "The srcid is using! Can't use repeatly."); Better message would be: "The srcid is in use, cant use!" wdyt? > + return true; > + } > + } > + return false; > +} > + > static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, > struct of_dma *ofdma) > { > @@ -117,6 +133,10 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec, > list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels, device_node) { > if (chan->client_count) > continue; > + > + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[1])) > + return NULL; > + > if ((chan->chan_id / chans_per_mux) == dma_spec->args[0]) { > chan = dma_get_slave_channel(chan); > if (chan) { > @@ -161,6 +181,8 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec, > continue; > > fsl_chan = to_fsl_edma_chan(chan); > + if (fsl_edma_srcid_in_use(fsl_edma, dma_spec->args[0])) > + return NULL; > i = fsl_chan - fsl_edma->chans; > > fsl_chan->priority = dma_spec->args[1]; > -- > 2.37.1 -- ~Vinod ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel 2024-06-28 7:31 ` Vinod Koul @ 2024-06-28 7:37 ` Joy Zou 0 siblings, 0 replies; 7+ messages in thread From: Joy Zou @ 2024-06-28 7:37 UTC (permalink / raw) To: Vinod Koul Cc: Frank Li, imx@lists.linux.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org > -----Original Message----- > From: Vinod Koul <vkoul@kernel.org> > Sent: 2024年6月28日 15:32 > To: Joy Zou <joy.zou@nxp.com> > Cc: Frank Li <frank.li@nxp.com>; imx@lists.linux.dev; > dmaengine@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: [EXT] Re: [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID > check at request channel > On 21-06-24, 18:49, Joy Zou wrote: > > Check src ID to detect misuse of same src ID for multiple DMA channels. > > > > Signed-off-by: Joy Zou <joy.zou@nxp.com> > > --- > > drivers/dma/fsl-edma-main.c | 22 ++++++++++++++++++++++ > > 1 file changed, 22 insertions(+) > > > > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c > > index d4f29ece69f5..47939d010e59 100644 > > --- a/drivers/dma/fsl-edma-main.c > > +++ b/drivers/dma/fsl-edma-main.c > > @@ -100,6 +100,22 @@ static irqreturn_t fsl_edma_irq_handler(int irq, > void *dev_id) > > return fsl_edma_err_handler(irq, dev_id); } > > > > +static bool fsl_edma_srcid_in_use(struct fsl_edma_engine *fsl_edma, > > +u32 srcid) { > > + struct fsl_edma_chan *fsl_chan; > > + int i; > > + > > + for (i = 0; i < fsl_edma->n_chans; i++) { > > + fsl_chan = &fsl_edma->chans[i]; > > + > > + if (fsl_chan->srcid && srcid == fsl_chan->srcid) { > > + dev_err(&fsl_chan->pdev->dev, "The srcid is > > + using! Can't use repeatly."); > > Better message would be: "The srcid is in use, cant use!" > > wdyt? Thanks your for comments! It's better. Will change it. BR Joy Zou ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-06-28 7:37 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-06-21 10:49 [PATCH v1 0/2] add edma src ID check at request channel Joy Zou 2024-06-21 10:49 ` [PATCH v1 1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate() Joy Zou 2024-06-21 14:48 ` Frank Li 2024-06-21 10:49 ` [PATCH v1 2/2] dmaengine: fsl-edma: add edma src ID check at request channel Joy Zou 2024-06-21 14:47 ` Frank Li 2024-06-28 7:31 ` Vinod Koul 2024-06-28 7:37 ` Joy Zou
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox