From patchwork Thu May 28 09:46:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 6497261 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 51D259F38C for ; Thu, 28 May 2015 09:46:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 506D0204D8 for ; Thu, 28 May 2015 09:46:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E89120620 for ; Thu, 28 May 2015 09:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753736AbbE1JqZ (ORCPT ); Thu, 28 May 2015 05:46:25 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:58761 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753678AbbE1JqW (ORCPT ); Thu, 28 May 2015 05:46:22 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YxuOL-00071R-77; Thu, 28 May 2015 11:46:21 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.85) (envelope-from ) id 1YxuOL-0004Xd-0X; Thu, 28 May 2015 11:46:21 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH RFC next 2/2] net: rfkill: gpio: simplify code flow Date: Thu, 28 May 2015 11:46:13 +0200 Message-Id: <1432806373-17372-3-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1432806373-17372-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1432806373-17372-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-wireless@vger.kernel.org Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 When assigning directly to the pointer contained in the driver data the local variable can be dropped together with the extra assignment to it. The downside is that davem doesn't like writing error pointers to dynamically allocated memory as this might result in bugs like: if (driverdata->gpio) free_resources(driverdata->gpio); which is probably wrong for error values. In this case however there is no cleanup code for the gpios as everything is managed by devm_* and furthermore already without this change there is an error path further down in rfkill_gpio_probe that potentially keeps a valid gpio descriptor in driver data which must not be used. For this eventually calling some cleanup function is hardly better than on an error pointer. Signed-off-by: Uwe Kleine-König --- net/rfkill/rfkill-gpio.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c index d5d58d919552..fd540024c506 100644 --- a/net/rfkill/rfkill-gpio.c +++ b/net/rfkill/rfkill-gpio.c @@ -92,7 +92,6 @@ static int rfkill_gpio_probe(struct platform_device *pdev) { struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data; struct rfkill_gpio_data *rfkill; - struct gpio_desc *gpio; int ret; rfkill = devm_kzalloc(&pdev->dev, sizeof(*rfkill), GFP_KERNEL); @@ -112,17 +111,15 @@ static int rfkill_gpio_probe(struct platform_device *pdev) rfkill->clk = devm_clk_get(&pdev->dev, NULL); - gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(gpio)) - return PTR_ERR(gpio); + rfkill->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(rfkill->reset_gpio)) + return PTR_ERR(rfkill->reset_gpio); - rfkill->reset_gpio = gpio; - - gpio = devm_gpiod_get_optional(&pdev->dev, "shutdown", GPIOD_OUT_LOW); - if (IS_ERR(gpio)) - return PTR_ERR(gpio); - - rfkill->shutdown_gpio = gpio; + rfkill->shutdown_gpio = devm_gpiod_get_optional(&pdev->dev, "shutdown", + GPIOD_OUT_LOW); + if (IS_ERR(rfkill->shutdown_gpio)) + return PTR_ERR(rfkill->shutdown_gpio); /* Make sure at-least one of the GPIO is defined and that * a name is specified for this instance