mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	ldv-project@linuxtesting.org
Subject: Re: [PATCH] usb: gadget: mv_u3d: add check for dma mapping error
Date: Thu, 03 Nov 2016 10:52:39 +0200	[thread overview]
Message-ID: <871sytndwo.fsf@linux.intel.com> (raw)
In-Reply-To: <1477696334-11237-1-git-send-email-khoroshilov@ispras.ru>

[-- Attachment #1: Type: text/plain, Size: 2686 bytes --]


Hi,

Alexey Khoroshilov <khoroshilov@ispras.ru> writes:
> mv_u3d_req_to_trb() does not check for dma mapping errors.
>
> By the way, the patch improves readability of mv_u3d_start_queue()
> by rearranging its code with two semantic modifications:
> - assignment zero to ep->processing if usb_gadget_map_request() fails;
> - propagation of error code from mv_u3d_req_to_trb() instead of 
>   hardcoded -ENOMEM.

cleanups and fixes should be done separately.

> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  drivers/usb/gadget/udc/mv_u3d_core.c | 34 +++++++++++++++++++++-------------
>  1 file changed, 21 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c
> index b9e19a591322..8d726bd767fd 100644
> --- a/drivers/usb/gadget/udc/mv_u3d_core.c
> +++ b/drivers/usb/gadget/udc/mv_u3d_core.c
> @@ -462,6 +462,12 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
>  					req->trb_head->trb_hw,
>  					trb_num * sizeof(*trb_hw),
>  					DMA_BIDIRECTIONAL);
> +		if (dma_mapping_error(u3d->gadget.dev.parent,
> +					req->trb_head->trb_dma)) {
> +			kfree(req->trb_head->trb_hw);
> +			kfree(req->trb_head);
> +			return -EFAULT;
> +		}
>  
>  		req->chain = 1;
>  	}

this is one patch: add dma_mapping_error() check

AKA $subject :-p

> @@ -487,30 +493,32 @@ mv_u3d_start_queue(struct mv_u3d_ep *ep)
>  	ret = usb_gadget_map_request(&u3d->gadget, &req->req,
>  					mv_u3d_ep_dir(ep));
>  	if (ret)
> -		return ret;
> +		goto break_processing;
>  
>  	req->req.status = -EINPROGRESS;
>  	req->req.actual = 0;
>  	req->trb_count = 0;
>  
> -	/* build trbs and push them to device queue */
> -	if (!mv_u3d_req_to_trb(req)) {
> -		ret = mv_u3d_queue_trb(ep, req);
> -		if (ret) {
> -			ep->processing = 0;
> -			return ret;
> -		}
> -	} else {
> -		ep->processing = 0;
> +	/* build trbs */
> +	ret = mv_u3d_req_to_trb(req);
> +	if (ret) {
>  		dev_err(u3d->dev, "%s, mv_u3d_req_to_trb fail\n", __func__);
> -		return -ENOMEM;
> +		goto break_processing;
>  	}
>  
> +	/* and push them to device queue */
> +	ret = mv_u3d_queue_trb(ep, req);
> +	if (ret)
> +		goto break_processing;
> +
>  	/* irq handler advances the queue */
> -	if (req)
> -		list_add_tail(&req->queue, &ep->queue);
> +	list_add_tail(&req->queue, &ep->queue);
>  
>  	return 0;
> +
> +break_processing:
> +	ep->processing = 0;
> +	return ret;
>  }
>  
>  static int mv_u3d_ep_enable(struct usb_ep *_ep,

this is another, unrelated patch. Please split

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

  reply	other threads:[~2016-11-03  8:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-28 23:12 Alexey Khoroshilov
2016-11-03  8:52 ` Felipe Balbi [this message]
2016-11-03 13:16   ` [PATCH v2 1/2] " Alexey Khoroshilov
2016-11-03 13:16     ` [PATCH v2 2/2] usb: gadget: mv_u3d: mv_u3d_start_queue() refactoring Alexey Khoroshilov
2016-11-03 13:34     ` [PATCH v2 1/2] usb: gadget: mv_u3d: add check for dma mapping error Felipe Balbi
2016-11-03 18:09       ` Alexey Khoroshilov

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=871sytndwo.fsf@linux.intel.com \
    --to=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=khoroshilov@ispras.ru \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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

Powered by JetHome