Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbdITLyF (ORCPT ); Wed, 20 Sep 2017 07:54:05 -0400 Received: from mga07.intel.com ([134.134.136.100]:34418 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751488AbdITLyE (ORCPT ); Wed, 20 Sep 2017 07:54:04 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,421,1500966000"; d="asc'?scan'208";a="314194361" From: Felipe Balbi To: Alexey Khoroshilov , Jack Pham Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: Re: [PATCH] usb: gadget: pch_udc: add checks for dma mapping errors In-Reply-To: References: <1503528428-16901-1-git-send-email-khoroshilov@ispras.ru> <20170824010227.GC30841@usblab-sd-06.qualcomm.com> Date: Wed, 20 Sep 2017 14:53:30 +0300 Message-ID: <87poalmvr9.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2931 Lines: 81 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Alexey Khoroshilov writes: >>> diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/= pch_udc.c >>> index 84dcbcd756f0..a305f8392082 100644 >>> --- a/drivers/usb/gadget/udc/pch_udc.c >>> +++ b/drivers/usb/gadget/udc/pch_udc.c >>> @@ -1767,7 +1767,7 @@ static struct usb_request *pch_udc_alloc_request(= struct usb_ep *usbep, >>> req->req.dma =3D DMA_ADDR_INVALID; >>> req->dma =3D DMA_ADDR_INVALID; >>> INIT_LIST_HEAD(&req->queue); >>> - if (!ep->dev->dma_addr) >>> + if (ep->dev->dma_addr !=3D DMA_ADDR_INVALID) >>> return &req->req; >>> /* ep0 in requests are allocated from data pool here */ >>> dma_desc =3D dma_pool_alloc(ep->dev->data_requests, gfp, >>> @@ -1879,6 +1879,13 @@ static int pch_udc_pcd_queue(struct usb_ep *usbe= p, struct usb_request *usbreq, >>> usbreq->length, >>> DMA_FROM_DEVICE); >>> } >>> + if (dma_mapping_error(&dev->pdev->dev, req->dma)) { >>> + req->dma =3D DMA_ADDR_INVALID; >>> + retval =3D -ENOMEM; >>> + if ((unsigned long)(usbreq->buf) & 0x03) >>> + kfree(req->buf); >>> + goto probe_end; >>> + } >>> req->dma_mapped =3D 1; >>> } >>> if (usbreq->length > 0) { >>> @@ -2961,6 +2968,10 @@ static int init_dma_pools(struct pch_udc_dev *de= v) >>> dev->dma_addr =3D dma_map_single(&dev->pdev->dev, ep0out_buf, >>> UDC_EP0OUT_BUFF_SIZE * 4, >>> DMA_FROM_DEVICE); >>> + if (dma_mapping_error(&dev->pdev->dev, dev->dma_addr)) { >>> + dev->dma_addr =3D DMA_ADDR_INVALID; >>> + return -ENOMEM; >>> + } >>=20 >> Wouldn't this driver be better off using the >> usb_gadget_{map,unmap}_request() functions provided by UDC core.c? >> dma_mapping_error() is provided for free that way. >>=20 > > I think so, but it requires quite significant rework of the driver. > I would not do that without access to hardware. I'd prefer to see a conversion to the generic helpers. =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEElLzh7wn96CXwjh2IzL64meEamQYFAlnCVroACgkQzL64meEa mQYbFQ/+PM5KjhsGa6Df0CemkQU8iTnnumI5ZF/1luQNVP79XjDCLMA5XfJpCoiU uOIocihZWFvLpcbzghrymWK3QZxeqaoziImLTeLiGhK59zIb1BqMfK4HF6bs+QDa F2sGidamOhfT+t4vDoCSQHr7CBmCchbyCH+5Jk04ct/0RCRqo5fSNJuovZkA7vc9 Cb7ySo1bLmV0tPkJt3asJ51GMG7KIva7MjonEGuqP5iunMjmdUE6BKkgi2NM8Osl l2iRcAAsM/MoqlbKJQCwIp+cE+CrwYHtpAk92VVBf1pwXCJ8PITNSIi/YPVzaaNm vAGpNuKIfAa+tUBu+1TqgG1l3XDgTNUtSae6ehLgoqN0Xk9M6OB9Nb4+5cTjjYRd 7CEuzz9vVZKpdL2xBQhK94hrI+8fs1sXZAW1O7E/aXWcA4zVkwVQgeShNiamhf0Z 2Ky8gdCGTEFU6Gazo/odBA+nbmO9ZHBGdGAMx8919NS2P8aDi1dAeYqTvTUqXdby mCwq16L77P7eTbN0a8+k+a4NtPljB0pNOL3YoJUnbKGc4kAzl+vNhzIudv1v3gKl +yqjrATcLmKpKqveglvshtWjeJtIyB0oBF/bGFcdEkA96L2yU44drJ0nvVNvrGQ4 y4hmjZdIqqYi0e0oCQHyyGKiB3lufspF0FdQs5Yh5npSiHlF9os= =Tts4 -----END PGP SIGNATURE----- --=-=-=--