From patchwork Fri Jul 19 14:10:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 18452 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BF32825E49 for ; Fri, 19 Jul 2013 14:10:33 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id d10sf5995322vea.4 for ; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=JtXH2mBXJNRfT8Q5nZwV0eeexd9w+zLOocKZh7xs3YU=; b=GmNASIcXMV1oLW8S5VomKNvHlOuN3cG3G672/Mv30j0Asba1de9G1YvFOg+CSbGKYU gJCnowMXv9RElGihctOC7PQmQ9ZSG3kH9fLXWxRJJ84y13uspWvM0oAZIA8hTZca4spx IEU32WX0XlICoPpWbAft1uSzp0ksdzWkI82uTBFLVwoYm5LVMLOC0mwLTNwtgl0P4rMu s2XCfaAUV8xPLzHAFxshaIY0ldglTU2oa7++i2ZBWPBoKKuHuBSnrrFO/Xof+4XHby1+ W2JIGJguvTz01cPYjPUqzTfwHagMG0oyaN2WPmeFD7Kb2PHF/2jggan5sw2MJRKa4D2f EI7w== X-Received: by 10.236.206.105 with SMTP id k69mr8856111yho.8.1374243033445; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.14.131 with SMTP id p3ls1981982qec.93.gmail; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) X-Received: by 10.220.44.195 with SMTP id b3mr5798369vcf.62.1374243033253; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id aj7si4066436vec.97.2013.07.19.07.10.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Jul 2013 07:10:33 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id da11so3361539veb.6 for ; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) X-Received: by 10.52.120.77 with SMTP id la13mr4848466vdb.23.1374243033186; Fri, 19 Jul 2013 07:10:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp27256veb; Fri, 19 Jul 2013 07:10:32 -0700 (PDT) X-Received: by 10.14.184.4 with SMTP id r4mr16126690eem.100.1374243032256; Fri, 19 Jul 2013 07:10:32 -0700 (PDT) Received: from mail-ea0-f182.google.com (mail-ea0-f182.google.com [209.85.215.182]) by mx.google.com with ESMTPS id v1si14152987eeo.235.2013.07.19.07.10.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Jul 2013 07:10:32 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.182 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.215.182; Received: by mail-ea0-f182.google.com with SMTP id d10so2422163eaj.41 for ; Fri, 19 Jul 2013 07:10:31 -0700 (PDT) X-Received: by 10.14.209.197 with SMTP id s45mr16251635eeo.108.1374243031794; Fri, 19 Jul 2013 07:10:31 -0700 (PDT) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPSA id m1sm27644902eex.17.2013.07.19.07.10.29 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Jul 2013 07:10:30 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: sameo@linux.intel.com, Lee Jones Subject: [PATCH 3/3] mfd: ucb1x00-core: Rewrite ucb1x00_add_dev() Date: Fri, 19 Jul 2013 15:10:17 +0100 Message-Id: <1374243017-8515-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1374243017-8515-1-git-send-email-lee.jones@linaro.org> References: <1374243017-8515-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQmi5MSRRUWNHRVYo8yGWnFLKG2hLxP73Yp/D9hAhRMsM4iaombl8J/hVfKHwmBBa8vsb4kb X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Error handling is on-its-head in this function. After invoking a function we should examine the return code and return the error value if there was one. Instead, this function checks for success and goes onto provide functionality if success was received. Not so bad in a simple function like this, but in a more complex one this could end up drowning in curly brackets. Signed-off-by: Lee Jones --- drivers/mfd/ucb1x00-core.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c index 70f02da..0690ffd 100644 --- a/drivers/mfd/ucb1x00-core.c +++ b/drivers/mfd/ucb1x00-core.c @@ -393,22 +393,24 @@ static struct irq_chip ucb1x00_irqchip = { static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) { struct ucb1x00_dev *dev; - int ret = -ENOMEM; + int ret; dev = kmalloc(sizeof(struct ucb1x00_dev), GFP_KERNEL); - if (dev) { - dev->ucb = ucb; - dev->drv = drv; - - ret = drv->add(dev); - - if (ret == 0) { - list_add_tail(&dev->dev_node, &ucb->devs); - list_add_tail(&dev->drv_node, &drv->devs); - } else { - kfree(dev); - } + if (!dev) + return -ENOMEM; + + dev->ucb = ucb; + dev->drv = drv; + + ret = drv->add(dev); + if (ret) { + kfree(dev); + return ret; } + + list_add_tail(&dev->dev_node, &ucb->devs); + list_add_tail(&dev->drv_node, &drv->devs); + return ret; }