From patchwork Tue Nov 12 10:38:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 3171711 Return-Path: X-Original-To: patchwork-linux-input@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 5E863C045B for ; Tue, 12 Nov 2013 11:12:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8526720200 for ; Tue, 12 Nov 2013 11:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD802201EF for ; Tue, 12 Nov 2013 11:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751559Ab3KLLMC (ORCPT ); Tue, 12 Nov 2013 06:12:02 -0500 Received: from fallback8.mail.ru ([94.100.176.136]:41894 "EHLO fallback8.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751214Ab3KLLMB (ORCPT ); Tue, 12 Nov 2013 06:12:01 -0500 Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) by fallback8.mail.ru (mPOP.Fallback_MX) with ESMTP id BB1E444D9D38 for ; Tue, 12 Nov 2013 14:41:58 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Message-Id:Date:Subject:Cc:To:From; bh=eliIw1Ife1eNED//+5DSFq9eNake5HkcpccgrAw8cw0=; b=t9HcB2KTBIh/TsgT30u1Jt0JqGdcIb14ZsmNddqfBEyvWQ3JUz8aEfZMZP3CUYbWXiDoILGPuyqqMs9TV6/MxReMBmvfgYICQ8w65cufejzNMac0K0+RCUej5RHrj9i7B0BCgYsHn0hrntRaN4ZreAM5rFNoDe61Kgn/ro12+KQ=; Received: from [217.119.30.118] (port=40325 helo=shc.milas.spb.ru) by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1VgBMi-0008BK-Vk; Tue, 12 Nov 2013 14:38:45 +0400 From: Alexander Shiyan To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Alexander Shiyan Subject: [PATCH RESEND 1/3] input: gpio_keys_polled: Convert to devm-* API Date: Tue, 12 Nov 2013 14:38:23 +0400 Message-Id: <1384252705-18553-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.1.5 X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB,RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Mras: Ok Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, RDNS_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths. kzalloc -> devm_kzalloc gpio_request_one -> devm_gpio_request_one Signed-off-by: Alexander Shiyan --- drivers/input/keyboard/gpio_keys_polled.c | 87 ++++++++----------------------- 1 file changed, 23 insertions(+), 64 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 4e42819..0dce49d 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -109,9 +109,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct struct device_node *node, *pp; struct gpio_keys_platform_data *pdata; struct gpio_keys_button *button; - int error; - int nbuttons; - int i; + int i, nbuttons; node = dev->of_node; if (!node) @@ -121,12 +119,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (nbuttons == 0) return NULL; - pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), - GFP_KERNEL); - if (!pdata) { - error = -ENOMEM; - goto err_out; - } + pdata = devm_kzalloc(dev, sizeof(*pdata) + nbuttons * (sizeof *button), + GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); pdata->buttons = (struct gpio_keys_button *)(pdata + 1); pdata->nbuttons = nbuttons; @@ -147,12 +143,11 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct gpio = of_get_gpio_flags(pp, 0, &flags); if (gpio < 0) { - error = gpio; - if (error != -EPROBE_DEFER) + if (gpio != -EPROBE_DEFER) dev_err(dev, "Failed to get gpio flags, error: %d\n", - error); - goto err_free_pdata; + gpio); + return ERR_PTR(gpio); } button = &pdata->buttons[i++]; @@ -163,8 +158,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); - error = -EINVAL; - goto err_free_pdata; + return ERR_PTR(-EINVAL); } button->desc = of_get_property(pp, "label", NULL); @@ -179,17 +173,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct button->debounce_interval = 5; } - if (pdata->nbuttons == 0) { - error = -EINVAL; - goto err_free_pdata; - } + if (!pdata->nbuttons) + return ERR_PTR(-EINVAL); return pdata; - -err_free_pdata: - kfree(pdata); -err_out: - return ERR_PTR(error); } static struct of_device_id gpio_keys_polled_of_match[] = { @@ -229,24 +216,21 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) if (!pdata->poll_interval) { dev_err(dev, "missing poll_interval value\n"); - error = -EINVAL; - goto err_free_pdata; + return -EINVAL; } - bdev = kzalloc(sizeof(struct gpio_keys_polled_dev) + - pdata->nbuttons * sizeof(struct gpio_keys_button_data), - GFP_KERNEL); + bdev = devm_kzalloc(&pdev->dev, sizeof(struct gpio_keys_polled_dev) + + pdata->nbuttons * sizeof(struct gpio_keys_button_data), + GFP_KERNEL); if (!bdev) { dev_err(dev, "no memory for private data\n"); - error = -ENOMEM; - goto err_free_pdata; + return -ENOMEM; } poll_dev = input_allocate_polled_device(); if (!poll_dev) { dev_err(dev, "no memory for polled device\n"); - error = -ENOMEM; - goto err_free_bdev; + return -ENOMEM; } poll_dev->private = bdev; @@ -279,15 +263,15 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) if (button->wakeup) { dev_err(dev, DRV_NAME " does not support wakeup\n"); error = -EINVAL; - goto err_free_gpio; + goto err_out; } - error = gpio_request_one(gpio, GPIOF_IN, - button->desc ?: DRV_NAME); + error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN, + button->desc ? : DRV_NAME); if (error) { dev_err(dev, "unable to claim gpio %u, err=%d\n", gpio, error); - goto err_free_gpio; + goto err_out; } bdata->can_sleep = gpio_cansleep(gpio); @@ -307,7 +291,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) if (error) { dev_err(dev, "unable to register polled device, err=%d\n", error); - goto err_free_gpio; + goto err_out; } /* report initial state of the buttons */ @@ -317,45 +301,20 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) return 0; -err_free_gpio: - while (--i >= 0) - gpio_free(pdata->buttons[i].gpio); - +err_out: input_free_polled_device(poll_dev); -err_free_bdev: - kfree(bdev); - -err_free_pdata: - /* If we have no platform_data, we allocated pdata dynamically. */ - if (!dev_get_platdata(&pdev->dev)) - kfree(pdata); - return error; } static int gpio_keys_polled_remove(struct platform_device *pdev) { struct gpio_keys_polled_dev *bdev = platform_get_drvdata(pdev); - const struct gpio_keys_platform_data *pdata = bdev->pdata; - int i; input_unregister_polled_device(bdev->poll_dev); - for (i = 0; i < pdata->nbuttons; i++) - gpio_free(pdata->buttons[i].gpio); - input_free_polled_device(bdev->poll_dev); - /* - * If we had no platform_data, we allocated pdata dynamically and - * must free it here. - */ - if (!dev_get_platdata(&pdev->dev)) - kfree(pdata); - - kfree(bdev); - return 0; }