From patchwork Sat Nov 25 20:45:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10075099 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 9075C602BC for ; Sat, 25 Nov 2017 20:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80BD628A0A for ; Sat, 25 Nov 2017 20:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72BD028E02; Sat, 25 Nov 2017 20:45:38 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EE0DF28A0A for ; Sat, 25 Nov 2017 20:45:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 84E006E14A; Sat, 25 Nov 2017 20:45:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.web.de (mout.web.de [212.227.17.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id E5F446E14A for ; Sat, 25 Nov 2017 20:45:35 +0000 (UTC) Received: from [192.168.1.3] ([92.228.138.71]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LgYOH-1ewzt703Zl-00nyAE; Sat, 25 Nov 2017 21:45:28 +0100 Subject: [PATCH 2/5] video: smscufx: Less checks in ufx_usb_probe() after error detection From: SF Markus Elfring To: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Bartlomiej Zolnierkiewicz , Steve Glendinning References: Message-ID: <73df7ce0-c4b0-aec7-ee7e-74f55a0fe708@users.sourceforge.net> Date: Sat, 25 Nov 2017 21:45:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-Provags-ID: V03:K0:Y6ySV4a5t18eZUz4dkQzgtCjZ3vBHJspw1HxApZ5l35Vmfjq0Os li4hiOB0novUuHyS1M+Feq93ZnGr9716Wx+lyPbES3x/J1/ibST/d7HCpHCYQGsc0i/Vb2w 702/HY2PBelHlZo0HcjSOJM1F4FRkY1MaExCk+7Nv4TjQPnfSKOfSqd8fEnK31XKoR6xupA rWG/9CHCgSKgfvGvYnuUw== X-UI-Out-Filterresults: notjunk:1; V01:K0:kFTmNuN6TCQ=:W5KtzknTNnQ8HwbJEdnaIN scHJEvg0aHKTXccluTbrcE/fgM7PP2Y5UOHfR0gyQ96WCyHbmkfH6ezopW4R6hnSLb6vVkjrx kfszoDhIrrzrZrUfO/Q5pBcr0M1pzZCvDu0PRAz5LgBThKlb3s8SeExHGgmDOb7WkB4VyOJgY XAOT7EZpB69CX+det4ozbZLCyeX5xb9atluEp7ZeR74NpnaQW7ryf2o6wGCW4NQAXv4dXrQ1k REwkeGHM2/6iP8QiAKTVJgsYOF5nmf31RMk5OZ9SGIYorPQEnUWKv8+N8B94C4aQ1f9xGqX2Y YifW2mfiFAhnw0bBMWjjFPLeN/9EPNBRN0pTMzMGA5ckfgL79dWV9weraWQtt8aIJZn8ju+SK X1D2hFfyILFpNXEHhMxb5ok8zDs3wpdezhhXXP/dCXh4bzJwkZ4ZxAjNM7x3t99cP7eMzDuWk 3KLF6GfWoLHjxAXxGf6MkroGGqHNV9eHiZIdZTM5rrC7qONkuNn7Q66AAwMetAiGQv0Am2XrA RnXDvIWBtLa1puuFpW3/5sGJaWUYVd26lQhDwo1hTF5lSQR5JfJ8G6DIIhkW2qx8/VzRhsjIg ektCVmcdvkKJhAvVCYVPf23N/YJXrurIxmeoKJ5QhkacwzYkdezyVjowBso9X2lUZLFWxJa/W f/er903uajv691CqkZO1r4W3nizfKAt8YqYOzeJHlNBXgi4lYJ+4Q9Gi9V8ZlI5vrXX8OGvg3 i3xmFn2Ulup5cNaHI4pCZs9nwyWMVoogLuWbxd4Qj0DCV29xEquj9fhOedvT3hBbD4P1oVU+P okdm/SRGQVivy2MVpmbvChIb+9/Bsaiy6Ff+aYpKnOPIOwBJlo= Cc: kernel-janitors@vger.kernel.org, LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 25 Nov 2017 19:47:51 +0100 Up to four checks could be repeated by the ufx_usb_probe() function during error handling even if the relevant properties can be determined for the involved variables before by source code analysis. * Return directly after a call of the function "kzalloc" failed at the beginning. * Adjust jump targets so that extra checks can be omitted at the end. * Delete initialisations for the variables "info" and "retval" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/video/fbdev/smscufx.c | 45 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c index 32de07d77184..08271dafd138 100644 --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -1619,8 +1619,8 @@ static int ufx_usb_probe(struct usb_interface *interface, { struct usb_device *usbdev; struct ufx_data *dev; - struct fb_info *info = NULL; - int retval = -ENOMEM; + struct fb_info *info; + int retval; u32 id_rev, fpga_rev; /* usb initialization */ @@ -1629,7 +1629,7 @@ static int ufx_usb_probe(struct usb_interface *interface, dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) - goto error; + return -ENOMEM; /* we need to wait for both usb and fbdev to spin down on disconnect */ kref_init(&dev->kref); /* matching kref_put in usb .disconnect fn */ @@ -1649,9 +1649,8 @@ static int ufx_usb_probe(struct usb_interface *interface, dev_dbg(dev->gdev, "fb_defio enable=%d\n", fb_defio); if (!ufx_alloc_urb_list(dev, WRITES_IN_FLIGHT, MAX_TRANSFER)) { - retval = -ENOMEM; dev_err(dev->gdev, "ufx_alloc_urb_list failed\n"); - goto error; + goto e_nomem; } /* We don't register a new USB class. Our client interface is fbdev */ @@ -1659,9 +1658,8 @@ static int ufx_usb_probe(struct usb_interface *interface, /* allocates framebuffer driver structure, not framebuffer memory */ info = framebuffer_alloc(0, &usbdev->dev); if (!info) { - retval = -ENOMEM; dev_err(dev->gdev, "framebuffer_alloc failed\n"); - goto error; + goto e_nomem; } dev->info = info; @@ -1672,7 +1670,7 @@ static int ufx_usb_probe(struct usb_interface *interface, retval = fb_alloc_cmap(&info->cmap, 256, 0); if (retval < 0) { dev_err(dev->gdev, "fb_alloc_cmap failed %x\n", retval); - goto error; + goto destroy_modedb; } INIT_DELAYED_WORK(&dev->free_framebuffer_work, @@ -1733,26 +1731,19 @@ static int ufx_usb_probe(struct usb_interface *interface, return 0; error: - if (dev) { - if (info) { - if (info->cmap.len != 0) - fb_dealloc_cmap(&info->cmap); - if (info->monspecs.modedb) - fb_destroy_modedb(info->monspecs.modedb); - vfree(info->screen_base); - - fb_destroy_modelist(&info->modelist); - - framebuffer_release(info); - } - - kref_put(&dev->kref, ufx_free); /* ref for framebuffer */ - kref_put(&dev->kref, ufx_free); /* last ref from kref_init */ - - /* dev has been deallocated. Do not dereference */ - } - +destroy_modedb: + fb_destroy_modedb(info->monspecs.modedb); + vfree(info->screen_base); + fb_destroy_modelist(&info->modelist); + framebuffer_release(info); +put_ref: + kref_put(&dev->kref, ufx_free); /* ref for framebuffer */ + kref_put(&dev->kref, ufx_free); /* last ref from kref_init */ return retval; + +e_nomem: + retval = -ENOMEM; + goto put_ref; } static void ufx_usb_disconnect(struct usb_interface *interface)