From patchwork Sat Sep 26 21:02:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guinot X-Patchwork-Id: 7270031 Return-Path: X-Original-To: patchwork-linux-arm@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 66F529F372 for ; Sat, 26 Sep 2015 21:04:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 641FA2086F for ; Sat, 26 Sep 2015 21:04:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64CB320815 for ; Sat, 26 Sep 2015 21:04:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zfwcl-0007bs-Ac; Sat, 26 Sep 2015 21:03:15 +0000 Received: from vm1.sequanux.org ([188.165.36.56]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zfwca-0007TY-Lw for linux-arm-kernel@lists.infradead.org; Sat, 26 Sep 2015 21:03:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by vm1.sequanux.org (Postfix) with ESMTP id 1C415108AC5; Sat, 26 Sep 2015 23:02:45 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at vm1.sequanux.org Received: from vm1.sequanux.org ([127.0.0.1]) by localhost (vm1.sequanux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f4uurjiazmJ2; Sat, 26 Sep 2015 23:02:43 +0200 (CEST) Received: from localhost (stp25-2-82-234-233-9.fbx.proxad.net [82.234.233.9]) by vm1.sequanux.org (Postfix) with ESMTPSA id EA0D210871A; Sat, 26 Sep 2015 23:02:41 +0200 (CEST) From: Simon Guinot To: Jacek Anaszewski , Bryan Wu , Richard Purdie Subject: [PATCH v6 4/5] leds: netxbig: convert to use the devm_ functions Date: Sat, 26 Sep 2015 23:02:37 +0200 Message-Id: <1443301358-2131-5-git-send-email-simon.guinot@sequanux.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443301358-2131-1-git-send-email-simon.guinot@sequanux.org> References: <1443301358-2131-1-git-send-email-simon.guinot@sequanux.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150926_140305_031474_A477ED74 X-CRM114-Status: GOOD ( 16.12 ) X-Spam-Score: -2.9 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Jason Cooper , Alexandre Courbot , Linus Walleij , Yoann Sculo , Vincent Donnefort , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Gregory Clement , linux-leds@vger.kernel.org, Sebastian Hesselbarth MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 This patch converts the leds-netxbig driver to use the devres functions devm_gpio_request_one() and devm_led_classdev_register(). This allows to simplify the code a bit. Signed-off-by: Simon Guinot --- drivers/leds/leds-netxbig.c | 108 ++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 80 deletions(-) diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c index e1f3c2632278..b166fd9f4186 100644 --- a/drivers/leds/leds-netxbig.c +++ b/drivers/leds/leds-netxbig.c @@ -71,7 +71,8 @@ static void gpio_ext_set_value(struct netxbig_gpio_ext *gpio_ext, spin_unlock_irqrestore(&gpio_ext_lock, flags); } -static int gpio_ext_init(struct netxbig_gpio_ext *gpio_ext) +static int gpio_ext_init(struct platform_device *pdev, + struct netxbig_gpio_ext *gpio_ext) { int err; int i; @@ -81,46 +82,28 @@ static int gpio_ext_init(struct netxbig_gpio_ext *gpio_ext) /* Configure address GPIOs. */ for (i = 0; i < gpio_ext->num_addr; i++) { - err = gpio_request_one(gpio_ext->addr[i], GPIOF_OUT_INIT_LOW, - "GPIO extension addr"); + err = devm_gpio_request_one(&pdev->dev, gpio_ext->addr[i], + GPIOF_OUT_INIT_LOW, + "GPIO extension addr"); if (err) - goto err_free_addr; + return err; } /* Configure data GPIOs. */ for (i = 0; i < gpio_ext->num_data; i++) { - err = gpio_request_one(gpio_ext->data[i], GPIOF_OUT_INIT_LOW, - "GPIO extension data"); + err = devm_gpio_request_one(&pdev->dev, gpio_ext->data[i], + GPIOF_OUT_INIT_LOW, + "GPIO extension data"); if (err) - goto err_free_data; + return err; } /* Configure "enable select" GPIO. */ - err = gpio_request_one(gpio_ext->enable, GPIOF_OUT_INIT_LOW, - "GPIO extension enable"); + err = devm_gpio_request_one(&pdev->dev, gpio_ext->enable, + GPIOF_OUT_INIT_LOW, + "GPIO extension enable"); if (err) - goto err_free_data; + return err; return 0; - -err_free_data: - for (i = i - 1; i >= 0; i--) - gpio_free(gpio_ext->data[i]); - i = gpio_ext->num_addr; -err_free_addr: - for (i = i - 1; i >= 0; i--) - gpio_free(gpio_ext->addr[i]); - - return err; -} - -static void gpio_ext_free(struct netxbig_gpio_ext *gpio_ext) -{ - int i; - - gpio_free(gpio_ext->enable); - for (i = gpio_ext->num_addr - 1; i >= 0; i--) - gpio_free(gpio_ext->addr[i]); - for (i = gpio_ext->num_data - 1; i >= 0; i--) - gpio_free(gpio_ext->data[i]); } /* @@ -141,11 +124,6 @@ struct netxbig_led_data { spinlock_t lock; }; -struct netxbig_led_priv { - struct netxbig_led_platform_data *pdata; - struct netxbig_led_data leds_data[]; -}; - static int netxbig_led_get_timer_mode(enum netxbig_led_mode *mode, unsigned long delay_on, unsigned long delay_off, @@ -305,18 +283,11 @@ static struct attribute *netxbig_led_attrs[] = { }; ATTRIBUTE_GROUPS(netxbig_led); -static void delete_netxbig_led(struct netxbig_led_data *led_dat) -{ - led_classdev_unregister(&led_dat->cdev); -} - -static int create_netxbig_led(struct platform_device *pdev, int led, - struct netxbig_led_priv *priv) +static int create_netxbig_led(struct platform_device *pdev, + struct netxbig_led_platform_data *pdata, + struct netxbig_led_data *led_dat, + const struct netxbig_led *template) { - struct netxbig_led_platform_data *pdata = priv->pdata; - struct netxbig_led_data *led_dat = &priv->leds_data[led]; - const struct netxbig_led *template = &priv->pdata->leds[led]; - spin_lock_init(&led_dat->lock); led_dat->gpio_ext = pdata->gpio_ext; led_dat->cdev.name = template->name; @@ -349,7 +320,7 @@ static int create_netxbig_led(struct platform_device *pdev, int led, if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE) led_dat->cdev.groups = netxbig_led_groups; - return led_classdev_register(&pdev->dev, &led_dat->cdev); + return devm_led_classdev_register(&pdev->dev, &led_dat->cdev); } #ifdef CONFIG_OF_GPIO @@ -579,7 +550,7 @@ netxbig_leds_get_of_pdata(struct device *dev, static int netxbig_led_probe(struct platform_device *pdev) { struct netxbig_led_platform_data *pdata = dev_get_platdata(&pdev->dev); - struct netxbig_led_priv *priv; + struct netxbig_led_data *leds_data; int i; int ret; @@ -592,51 +563,28 @@ static int netxbig_led_probe(struct platform_device *pdev) return ret; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + - pdata->num_leds * sizeof(struct netxbig_led_data), - GFP_KERNEL); - if (!priv) + leds_data = devm_kzalloc(&pdev->dev, + pdata->num_leds * sizeof(*leds_data), + GFP_KERNEL); + if (!leds_data) return -ENOMEM; - priv->pdata = pdata; - ret = gpio_ext_init(pdata->gpio_ext); + ret = gpio_ext_init(pdev, pdata->gpio_ext); if (ret < 0) return ret; for (i = 0; i < pdata->num_leds; i++) { - ret = create_netxbig_led(pdev, i, priv); + ret = create_netxbig_led(pdev, pdata, + &leds_data[i], &pdata->leds[i]); if (ret < 0) - goto err_free_leds; + return ret; } - platform_set_drvdata(pdev, priv); - - return 0; - -err_free_leds: - for (i = i - 1; i >= 0; i--) - delete_netxbig_led(&priv->leds_data[i]); - - gpio_ext_free(pdata->gpio_ext); - return ret; -} - -static int netxbig_led_remove(struct platform_device *pdev) -{ - struct netxbig_led_priv *priv = platform_get_drvdata(pdev); - struct netxbig_led_platform_data *pdata = priv->pdata; - int i; - - for (i = 0; i < pdata->num_leds; i++) - delete_netxbig_led(&priv->leds_data[i]); - - gpio_ext_free(pdata->gpio_ext); return 0; } static struct platform_driver netxbig_led_driver = { .probe = netxbig_led_probe, - .remove = netxbig_led_remove, .driver = { .name = "leds-netxbig", .of_match_table = of_match_ptr(of_netxbig_leds_match),