Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756361AbcKCIxG (ORCPT ); Thu, 3 Nov 2016 04:53:06 -0400 Received: from mga14.intel.com ([192.55.52.115]:57907 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755682AbcKCIxE (ORCPT ); Thu, 3 Nov 2016 04:53:04 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,585,1473145200"; d="asc'?scan'208";a="781844784" From: Felipe Balbi To: Alexey Khoroshilov Cc: Alexey Khoroshilov , Greg Kroah-Hartman , 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 In-Reply-To: <1477696334-11237-1-git-send-email-khoroshilov@ispras.ru> References: <1477696334-11237-1-git-send-email-khoroshilov@ispras.ru> Date: Thu, 03 Nov 2016 10:52:39 +0200 Message-ID: <871sytndwo.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3609 Lines: 121 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Alexey Khoroshilov 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=20 > hardcoded -ENOMEM. cleanups and fixes should be done separately. > Found by Linux Driver Verification project (linuxtesting.org). > > Signed-off-by: Alexey Khoroshilov > --- > 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/ud= c/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; > + } >=20=20 > req->chain =3D 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 =3D usb_gadget_map_request(&u3d->gadget, &req->req, > mv_u3d_ep_dir(ep)); > if (ret) > - return ret; > + goto break_processing; >=20=20 > req->req.status =3D -EINPROGRESS; > req->req.actual =3D 0; > req->trb_count =3D 0; >=20=20 > - /* build trbs and push them to device queue */ > - if (!mv_u3d_req_to_trb(req)) { > - ret =3D mv_u3d_queue_trb(ep, req); > - if (ret) { > - ep->processing =3D 0; > - return ret; > - } > - } else { > - ep->processing =3D 0; > + /* build trbs */ > + ret =3D 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; > } >=20=20 > + /* and push them to device queue */ > + ret =3D 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); >=20=20 > return 0; > + > +break_processing: > + ep->processing =3D 0; > + return ret; > } >=20=20 > static int mv_u3d_ep_enable(struct usb_ep *_ep, this is another, unrelated patch. Please split =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJYGvrXAAoJEMy+uJnhGpkGMTMP/RKGBbbQiTrrztvk7HavU0KN aU2wKTTNr3W7abzGk9/ebmh7DLSDnxF8gk2XE3NTuYoO+YsC6s7Gu6w59BJOFtsr ndaoPeJTjj5ejrqqhnolRgojwIp/PCK0KZ6HkXZFNFArMLjii712Si2C34nSMZ0L ZaDP1MiUUWmZCaDQ1XlAGb7YaXoKAIiN1ovlXe0wNUC86FMQ/C8GVZROkcbVqlX2 2m0DbesMBeFXWKfPmZWrgZLtaKnvzEyb557Ltgzrc8OToHVZa+W/ngZ0zjoDrvKW l1djfNEUgE6+mxjsIIjF8IKu5mdfq5qA4taCjlJ+o/TSv+Y9JCl5/WYMQzUbkslZ iuK2ku4rwBXafWsSLAsVJe2a17Qi5xHxxW1cdlhJQjuZsn1dxKfaanXWc508Y2hk 60rekSmeOxc+LWm9O3v9zriuLVcnkNuKr6gyxvnkZrB6N7jppzCbx6eEU3++beBN pxIPwPcHrRevDpY3VAZlcrjTtk25GZPG0Z/KtDP7QthDH/NqMNvJ8c7SfWXeBZOL JUSoF5VfzEjD1QSE33S5EhzgGMDnvMoobeizUCUwU0BU9C0Jf84YU6NMHKNLZ1r1 8cj4ML/k89/fAUzVLSZIYkx3kq4Gczic7iAkQG/eMPxjZu62VYxLyp7AZB+D2fIJ S0FYoYRPS5KO7Oj0tt4m =v0W/ -----END PGP SIGNATURE----- --=-=-=--