From patchwork Sun Nov 26 07:38:49 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: 10075239 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 02FF460353 for ; Sun, 26 Nov 2017 07:39:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3E1228B24 for ; Sun, 26 Nov 2017 07:39:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D722928BC8; Sun, 26 Nov 2017 07:39:51 +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 DA11A28B24 for ; Sun, 26 Nov 2017 07:39:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1DBC76E06E; Sun, 26 Nov 2017 07:39:49 +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.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6072D6E06E for ; Sun, 26 Nov 2017 07:39:47 +0000 (UTC) Received: from [192.168.1.3] ([78.49.168.181]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MTQ07-1ejyWs1Pvz-00SN1X; Sun, 26 Nov 2017 08:39:37 +0100 Subject: [PATCH v2 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: <73df7ce0-c4b0-aec7-ee7e-74f55a0fe708@users.sourceforge.net> Message-ID: <3f66c1b1-bf12-94ed-4dc9-34094c0d5816@users.sourceforge.net> Date: Sun, 26 Nov 2017 08:38:49 +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: <73df7ce0-c4b0-aec7-ee7e-74f55a0fe708@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:LgEm2GxydOCQyay916A7G4yXuA2zevAo9mOzVmiIxsehhrxvcPE XBHl1dWTKBKoqZLQOUZ9FJ2191jYcAAc5DG/WLxoOFwNHnaA/vP0nH6Ib7ziGwbxgVDaG/2 6+4c4NUNZmaXUwOOsDsyzlIkMmRBLuAAItHg7VMXxw5SlRsm+866uHU8t5hf6pVam10RL9V PG2jasJ38dGUP1vvdBqTQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:y8Emd7x+Ue4=:Gslf3G3ilmfiDN8s5tJrQ0 VdgxQEj2q1avDOW+IO8onBFf2JDWPTafaCgs16niaw/dpXbG0k6SBUsfuENcx0VmEvdVv5Qgs IuvHkCDLpFCjuHEQU+HDHo6X9mHl6VRRnl9FhHBshiumtrjEcbjSvL5Nvc/lA89bUN68/36EY QuFaK29wd0RNHdAeMs9oCAdbYeMLpvWgYNC9qvCR62x/TL4Ae1RziTMn8Vs+GAUqwUu01LtQq 2z9rX7vz9teax9FCLj3vFPpaCZX9dq6cSzfAezNHKrGwjTqJHbv91KMbzl1oSDFMkz5auqYxa OEBAkSDvaT1iC5n1vy6b25+Uh2nV4p0D6Yv85O4X1PDl8eS2X8NY3JU6oFj/qFf+2i8989lB3 8yb2MexS+WaUhYBumZJ4sDrmK5Zr/pkmVe90obPkCtgxBwNBF3lc6M0hQaloBKP+JgBtkN39L lHKCer5mJqmi13QAr0LcdHGFUYsIOx8uMgtb0LD/ZgFmUmmhlv5mMP2+EOelxCjNvqVbK+g8A Cq/rzXQfvk2D9/2INRSsSRNyk/ymXHyLs18vjJokLTt8nBxeg13W1TEhA6XkDRdJQ+wjuF4aF KeXZbMll52uv98T2TrYEos5LOer4UiAe5enjP79zoRbjH4n+k0KkZJR3sPrTF79OS50Rpbx9U K33XQbcYPh8Buw/iLOpwyL011rA1t5oO8ug9KQ/w4gX3/CqRp6mrMr4Nv6QjkLJ+1wyHwbsn9 lb8vn6ohTtIY7ch+4cbDcAfDi47uJAfMjjYKi9sDpLKdko3fmaku2CTUq9y1w3Wb9DQRE1QzL yGz+5YWKbOnYkf23cv1/BxWG8L6e8Jax2m9etvAsueWi23bws9lKgtrFUEjz8Rxa5HTznmq 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, 26 Nov 2017 08:18:20 +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 --- 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 32de07d77184..a48a2dec3f5e 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,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)