From: Vinod Koul <vkoul@kernel.org>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] dma: sh: usb-dmac: Fix residue after the commit 24461d9792c2
Date: Tue, 16 Jun 2020 22:25:50 +0530 [thread overview]
Message-ID: <20200616165550.GP2324254@vkoul-mobl> (raw)
In-Reply-To: <1590061573-12576-1-git-send-email-yoshihiro.shimoda.uh@renesas.com>
On 21-05-20, 20:46, Yoshihiro Shimoda wrote:
> This driver assumed that freed descriptors have "done_cookie".
> But, after the commit 24461d9792c2 ("dmaengine: virt-dma: Fix
> access after free in vchan_complete()"), since the desc is freed
> after callback function was called, this driver could not
> match any done_cookie when a client driver (renesas_usbhs driver)
> calls dmaengine_tx_status() in the callback function.
Hmmm, I am not sure about this, why should we try to match! cookie is
monotonically increasing number so if you see that current cookie
completed is > requested you should return DMA_COMPLETE
The below case of checking residue should not even get executed
> So, add to check both descriptor types (freed and got) to fix
> the issue.
>
> Reported-by: Hien Dang <hien.dang.eb@renesas.com>
> Fixes: 24461d9792c2 ("dmaengine: virt-dma: Fix access after free in vchan_complete()")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
> drivers/dma/sh/usb-dmac.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma/sh/usb-dmac.c b/drivers/dma/sh/usb-dmac.c
> index b218a01..c0adc1c8 100644
> --- a/drivers/dma/sh/usb-dmac.c
> +++ b/drivers/dma/sh/usb-dmac.c
> @@ -488,16 +488,17 @@ static u32 usb_dmac_chan_get_residue_if_complete(struct usb_dmac_chan *chan,
> dma_cookie_t cookie)
> {
> struct usb_dmac_desc *desc;
> - u32 residue = 0;
>
> + list_for_each_entry_reverse(desc, &chan->desc_got, node) {
> + if (desc->done_cookie == cookie)
> + return desc->residue;
> + }
> list_for_each_entry_reverse(desc, &chan->desc_freed, node) {
> - if (desc->done_cookie == cookie) {
> - residue = desc->residue;
> - break;
> - }
> + if (desc->done_cookie == cookie)
> + return desc->residue;
> }
>
> - return residue;
> + return 0;
> }
>
> static u32 usb_dmac_chan_get_residue(struct usb_dmac_chan *chan,
> --
> 2.7.4
--
~Vinod
next prev parent reply other threads:[~2020-06-16 16:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-21 11:46 [PATCH] dma: sh: usb-dmac: Fix residue after the commit 24461d9792c2 Yoshihiro Shimoda
2020-06-16 6:31 ` Yoshihiro Shimoda
2020-06-16 16:55 ` Vinod Koul [this message]
2020-06-18 0:56 ` Yoshihiro Shimoda
2020-06-24 6:02 ` Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200616165550.GP2324254@vkoul-mobl \
--to=vkoul@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=yoshihiro.shimoda.uh@renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).