From patchwork Sun Jan 7 16:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10148355 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 8F7D76037E for ; Sun, 7 Jan 2018 16:02:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E0C8265B9 for ; Sun, 7 Jan 2018 16:02:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FF9428595; Sun, 7 Jan 2018 16:02:32 +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 D9EF1265B9 for ; Sun, 7 Jan 2018 16:02:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D5676E520; Sun, 7 Jan 2018 16:02:31 +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.15.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id D14FC6E520 for ; Sun, 7 Jan 2018 16:02:29 +0000 (UTC) Received: from [192.168.1.3] ([78.48.134.178]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M8zhl-1ekd4V3fEz-00CNkc; Sun, 07 Jan 2018 17:02:23 +0100 Subject: [PATCH v3 1/3] 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: <1736749.UIs06O4xc5@amdc3058> Message-ID: <03be4276-520e-1d22-1c6e-e35c8df2b1e8@users.sourceforge.net> Date: Sun, 7 Jan 2018 17:02:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-Provags-ID: V03:K0:0nn+m50aH1tYluQjpH3QA/eLsQkbkWW91b/AKXyQgccz2kWGGxR FSkWLteJYmGJ75tmPBnoc8mq6eUDGzQbyKrzBR4D6vkkXv6w4CtdswQIQTXrNnI4LVu+dDW VX8uWjQUBhC+Bm/UgioTFhhncAc2Dfy8tETeQXbBFmJCAexakEnOpQ1kYO10UV4oRxWIriO hCcRoCBlqe6+tWkYtDJIQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:66AVmlrM2+s=:1iK7zG3jDSqlXyZS6a3XjD j4QBCdvadlZ8PA8niHjgSYJCGmi7xiReYkDWgsURD1CXMHAf21xPryX0tRCiqq29hdNZim68Q auNmVQHtK8VMC7H9jJiwAIMxKLGvpn/Q1C5SrxGfrHdFACEZ5Ho/2MHaZsZHyA2gNKE+mIeaR mU3wM9TVrD/wVnZetw+L31Pi+X0TFruCpe4muDlFk1JQNRrDcHcV0DOcpvzFPRb2yP4rU/mJ7 yN8sO/7dJVc8OnDh1QqnC4gzkM97cKHSO7x8pKDBPT9bCV890wHUOqcbZQdgwgYkonU7WBSzh Ec7G9nh6Pc+xGb844vLzJ0q+BvyeNHvkNwtLNVSIahm/8LlnStfbXepVIZt3lRZzHHpfqAup5 CiupIgHRFAMD5wT1Y+4U70mMasSHN4sZ64wx8yqGrXSZiR9MY+CrfedlJg9vNp5Is4IQVkd2L yXagYBAy7wu+LAOh+VVbYwHuzhKNURwXW1VpDN7eCZjZsH2nG63XM/NCUmopfZsazX9zuoQOv qVTnAG1l3sXThFKwokIo7ZN7SyMKX1YudQJLIiqnK89zeUWYDgZfQHR6DOGViU09COqbcuoDO ZXcnCOud9b8egGbRxUyqN66F95P4493rkUBEzqwNVrCfgX0pIAMcxxc42lzEi8tNuQFZ4d9d1 oETXr8u4Z4BC+Uk0NexOzRs7PS6hlF4mLxq0PtAMu2yZ9Zq4E2ArBuaMPhIiEX0TYD8NrCLLa d471H/mIV2Hl2AJh5aCQPUFu3xtY4Y60Ifa4bOOUJ2xc/B2R5UPziyvbanHrnFP3snk/i163O vaFZ3j7Cb4OTyjdozsJOiZX8+71udMlrq6jYTVzAeXF1SPtSy4= 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: Sun, 7 Jan 2018 15:56:11 +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 --- v3: This update suggestion was rebased on source files from the software "Linux next-20180105". v2: A call of the function "fb_dealloc_cmap" was preserved for the exception handling at the end. drivers/video/fbdev/smscufx.c | 46 ++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c index 8db7085e5d1a..893daeb1ffd9 100644 --- a/drivers/video/fbdev/smscufx.c +++ b/drivers/video/fbdev/smscufx.c @@ -1620,8 +1620,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 */ @@ -1631,7 +1631,7 @@ static int ufx_usb_probe(struct usb_interface *interface, dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&usbdev->dev, "ufx_usb_probe: failed alloc of dev struct\n"); - goto error; + return -ENOMEM; } /* we need to wait for both usb and fbdev to spin down on disconnect */ @@ -1652,9 +1652,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 */ @@ -1662,9 +1661,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; @@ -1675,7 +1673,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, @@ -1736,26 +1734,20 @@ 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 */ - } - + fb_dealloc_cmap(&info->cmap); +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)