From patchwork Sun Dec 25 18:40:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9488299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 600C160471 for ; Sun, 25 Dec 2016 18:40:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57ADD1FF65 for ; Sun, 25 Dec 2016 18:40:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AC7F22A63; Sun, 25 Dec 2016 18:40:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF5661FF65 for ; Sun, 25 Dec 2016 18:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754081AbcLYSkb (ORCPT ); Sun, 25 Dec 2016 13:40:31 -0500 Received: from mout.web.de ([217.72.192.78]:55972 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753678AbcLYSka (ORCPT ); Sun, 25 Dec 2016 13:40:30 -0500 Received: from [192.168.1.2] ([77.182.80.223]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MJkxE-1cMKB927rY-0018OE; Sun, 25 Dec 2016 19:40:23 +0100 Subject: [PATCH 09/19] [media] uvc_driver: Less function calls in uvc_parse_streaming() after error detection To: linux-media@vger.kernel.org, Laurent Pinchart , Mauro Carvalho Chehab References: <47aa4314-74ec-b2bf-ee3b-aad4d6e9f0a2@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Sun, 25 Dec 2016 19:40:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <47aa4314-74ec-b2bf-ee3b-aad4d6e9f0a2@users.sourceforge.net> X-Provags-ID: V03:K0:gCwWDErhFApSXJHX32lKWWTTMPuC2Is38etMPfyOJLGf1k/3iOP qpa+osYHwBIR5E3k5aJpnb2DiBjBnqw9YS1npAEyTHeBiFw9PrKkR/0Y4IHVTbA5R6CWgOv x6BFdjDn/HbZ3a0h5kB51SEhxsnxQyUrQYcx8ax8e+IXi9AF8whIM3cRSeYN5LQgUQS1XTh AyQQrXuDrcuwrS66YN28Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:14xSOLWHlf4=:3Mhvy5xs5FqsLQXeDA94VM hIuCXL1B+FDTt6dUf9vhDoInMt7eGSC/6iuu8Imxd21VzxkvD7LmORR9j10t5019SjlkZlFrx K4Cykdx+U6vlT5I4NrSG94FCI8iv1Vls4fXhkJchrGwwoyh+b4XjOjMBtxPZcZ758Vynieb90 eRViYrvppGIVlEGGyI3SB/dCsr4FP0huMY7/J0CW9SkHvRau9jb/Y0VTBrpO65gcd0//AfDEG bjWaVbym1GV4/SBNA5QKOAHacJJ9ySyiGFIgavmKhLco2SC4T8HRkYUmRdZ+g/AptWDImPkZ9 MlT7cc+ie4eP7c+uGSYJQe2uuRnNukP5LqT8Wa8cjRVl1Ns/JFJjoZjSbjW8S2iwrt8bPjHXa h9dHGUTQcAq3NZhFgGh1nx8wGQXOyYyQUpZMp+EXZ/cm7PtvLQwdRrNPO8Lhg+iB0nnaGBHSb PMbawu16fNojcRQRK9VmBDCFpWYSH62AuJMfAdk+Cm3aR1pzaLuUiqFjcMpkQBtfMr5O8ECFD OspDJQCyRd+mQm+3q19I/c1YfEgAot9Ld2WgyVhUh7NCvZDdPmh/pPD2SYn4BsVDuxw/7KWKX 66KAO0vh09iI5sGxSnVnLYsjI7VWF7V0SMdl/qugqTY8ehRfAluWkUoZEHBHkSxUFgP7ec6dH yNF/ek8suThrVZZW/GOo/XHEmPHa0AF7jwEIOwrb0eOazwCJmVPeT5jvUVgVRfY0A72+CWosd rIAXQuI/pwK5ZEKKH2CPwjWK36CIszJSrXrF6zR3UOPuwQxYJYmJBsZm+H3M8JTrXmAJtWy8a FHTxelC Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 25 Dec 2016 15:45:31 +0100 The kfree() function was called in a few cases by the uvc_parse_streaming() function during error handling even if the passed data structure member contained a null pointer. Adjust jump targets according to the Linux coding style convention. Fixes: c0efd232929c2cd87238de2cccdaf4e845be5b0c ("V4L/DVB (8145a): USB Video Class driver") Signed-off-by: Markus Elfring --- drivers/media/usb/uvc/uvc_driver.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c4e954aecdd5..b0833902fde2 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -702,7 +702,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, if (buflen <= 2) { uvc_trace(UVC_TRACE_DESCR, "no class-specific streaming interface descriptors found.\n"); - goto error; + goto release_interface; } /* Parse the header descriptor. */ @@ -721,7 +721,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d HEADER descriptor not found.\n", dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } p = buflen >= 4 ? buffer[3] : 0; @@ -731,7 +731,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d HEADER descriptor is invalid.\n", dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } streaming->header.bNumFormats = p; @@ -751,7 +751,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, GFP_KERNEL); if (!streaming->header.bmaControls) { ret = -ENOMEM; - goto error; + goto release_interface; } buflen -= buffer[0]; @@ -809,7 +809,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d has no supported formats defined.\n", dev->udev->devnum, alts->desc.bInterfaceNumber); - goto error; + goto release_interface; } size = nformats * sizeof(*format) + nframes * sizeof(*frame) @@ -817,7 +817,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, format = kzalloc(size, GFP_KERNEL); if (!format) { ret = -ENOMEM; - goto error; + goto free_controls; } frame = (struct uvc_frame *)&format[nformats]; @@ -837,7 +837,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, ret = uvc_parse_format(dev, streaming, format, &interval, buffer, buflen); if (ret < 0) - goto error; + goto free_format; frame += format->nframes; format++; @@ -878,12 +878,13 @@ static int uvc_parse_streaming(struct uvc_device *dev, list_add_tail(&streaming->list, &dev->streams); return 0; - -error: - usb_driver_release_interface(&uvc_driver.driver, intf); - usb_put_intf(intf); +free_format: kfree(streaming->format); +free_controls: kfree(streaming->header.bmaControls); +release_interface: + usb_driver_release_interface(&uvc_driver.driver, intf); + usb_put_intf(intf); kfree(streaming); return ret; }