From patchwork Wed Jun 26 07:53:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 2783391 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E741C0AB1 for ; Wed, 26 Jun 2013 07:54:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DFEDD20240 for ; Wed, 26 Jun 2013 07:54:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEA692023D for ; Wed, 26 Jun 2013 07:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751344Ab3FZHyM (ORCPT ); Wed, 26 Jun 2013 03:54:12 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:25971 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751195Ab3FZHyM (ORCPT ); Wed, 26 Jun 2013 03:54:12 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r5Q7s69U002866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Jun 2013 07:54:06 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5Q7s5MU018667 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Jun 2013 07:54:05 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5Q7s4qt005295; Wed, 26 Jun 2013 07:54:04 GMT Received: from elgon.mountain (/41.202.233.184) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 26 Jun 2013 00:54:04 -0700 Date: Wed, 26 Jun 2013 10:53:58 +0300 From: Dan Carpenter To: Jarod Wilson Cc: Mauro Carvalho Chehab , YAMANE Toshiaki , Andy Shevchenko , linux-media@vger.kernel.org Subject: [patch] [media] staging: lirc: clean error handling in probe() Message-ID: <20130626075358.GC1895@elgon.mountain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I have reorganized the error handling into a simpler and more canonical format. Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/staging/media/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c index 2faa391..4cf3933 100644 --- a/drivers/staging/media/lirc/lirc_igorplugusb.c +++ b/drivers/staging/media/lirc/lirc_igorplugusb.c @@ -390,7 +390,6 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, int devnum, pipe, maxp; int minor = 0; char buf[63], name[128] = ""; - int mem_failure = 0; int ret; dprintk(DRIVER_NAME ": usb probe called.\n"); @@ -416,24 +415,17 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n", devnum, CODE_LENGTH, maxp); - mem_failure = 0; ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL); - if (!ir) { - mem_failure = 1; - goto mem_failure_switch; - } + if (!ir) + return -ENOMEM; driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); - if (!driver) { - mem_failure = 2; - goto mem_failure_switch; - } + if (!driver) + goto err_free_ir; ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, GFP_ATOMIC, &ir->dma_in); - if (!ir->buf_in) { - mem_failure = 3; - goto mem_failure_switch; - } + if (!ir->buf_in) + goto err_free_driver; strcpy(driver->name, DRIVER_NAME " "); driver->minor = -1; @@ -451,23 +443,7 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, minor = lirc_register_driver(driver); if (minor < 0) - mem_failure = 9; - -mem_failure_switch: - - switch (mem_failure) { - case 9: - usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, - ir->buf_in, ir->dma_in); - case 3: - kfree(driver); - case 2: - kfree(ir); - case 1: - printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n", - devnum, mem_failure); - return -ENOMEM; - } + goto err_free_usb; driver->minor = minor; ir->d = driver; @@ -500,6 +476,16 @@ mem_failure_switch: usb_set_intfdata(intf, ir); return 0; + +err_free_usb: + usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, ir->buf_in, + ir->dma_in); +err_free_driver: + kfree(driver); +err_free_ir: + kfree(ir); + + return -ENOMEM; }