From patchwork Mon Feb 10 04:22:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 3615351 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 09A249F382 for ; Mon, 10 Feb 2014 04:22:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 078792010C for ; Mon, 10 Feb 2014 04:22:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EF8B20148 for ; Mon, 10 Feb 2014 04:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751886AbaBJEWU (ORCPT ); Sun, 9 Feb 2014 23:22:20 -0500 Received: from smtp37.i.mail.ru ([94.100.177.97]:59961 "EHLO smtp37.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751612AbaBJEWU (ORCPT ); Sun, 9 Feb 2014 23:22:20 -0500 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=plVQbPh8i96f6V5A9OjGCSwDlmFBVt9dFHklmGKtAi4=; b=LktqQCF92MZHbg8y1gGLgtjDzHGYkS7++FpqXnQOO130Jghct/T+7uhzOYUKlor8p66ihm5ISa33/BWtWy6xeSS+J6I9GOeX6crpu9WISAS/KEeShB0AkK0vs2LklmwlVha4nQi6tmdw1MRbR5w7Tm12/uC1BOmEWvTeu45cE+w=; Received: from [188.134.40.128] (port=45314 helo=shc.zet) by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1WCiNt-0002tH-U7; Mon, 10 Feb 2014 08:22:18 +0400 From: Alexander Shiyan To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Alexander Shiyan Subject: [PATCH 2/2] input: gpio_keys: Convert to devm-* API Date: Mon, 10 Feb 2014 08:22:16 +0400 Message-Id: <1392006136-10303-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.3.2 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,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=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 input_allocate_device -> devm_input_allocate_device Signed-off-by: Alexander Shiyan --- drivers/input/keyboard/gpio_keys.c | 96 +++++++++++--------------------------- 1 file changed, 28 insertions(+), 68 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 2db1324..50c2746 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -433,7 +433,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, struct device *dev = &pdev->dev; irq_handler_t isr; unsigned long irqflags; - int irq, error; + int error; bdata->input = input; bdata->button = button; @@ -441,7 +441,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, if (gpio_is_valid(button->gpio)) { - error = gpio_request_one(button->gpio, GPIOF_IN, desc); + error = devm_gpio_request_one(&pdev->dev, button->gpio, + GPIOF_IN, desc); if (error < 0) { dev_err(dev, "Failed to request GPIO %d, error %d\n", button->gpio, error); @@ -457,15 +458,13 @@ static int gpio_keys_setup_key(struct platform_device *pdev, button->debounce_interval; } - irq = gpio_to_irq(button->gpio); - if (irq < 0) { - error = irq; + bdata->irq = gpio_to_irq(button->gpio); + if (bdata->irq < 0) { dev_err(dev, "Unable to get irq number for GPIO %d, error %d\n", - button->gpio, error); - goto fail; + button->gpio, bdata->irq); + return bdata->irq; } - bdata->irq = irq; INIT_WORK(&bdata->work, gpio_keys_gpio_work_func); setup_timer(&bdata->timer, @@ -507,16 +506,10 @@ static int gpio_keys_setup_key(struct platform_device *pdev, if (error < 0) { dev_err(dev, "Unable to claim irq %d; error %d\n", bdata->irq, error); - goto fail; + return error; } return 0; - -fail: - if (gpio_is_valid(button->gpio)) - gpio_free(button->gpio); - - return error; } static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata) @@ -573,28 +566,20 @@ gpio_keys_get_devtree_pdata(struct device *dev) 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) { - error = -ENODEV; - goto err_out; - } + if (!node) + return ERR_PTR(-ENODEV); nbuttons = of_get_child_count(node); - if (nbuttons == 0) { - error = -ENODEV; - goto err_out; - } + if (nbuttons == 0) + return ERR_PTR(-ENODEV); - 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; @@ -614,12 +599,11 @@ gpio_keys_get_devtree_pdata(struct device *dev) 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++]; @@ -630,8 +614,7 @@ gpio_keys_get_devtree_pdata(struct device *dev) 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); @@ -646,17 +629,10 @@ gpio_keys_get_devtree_pdata(struct device *dev) 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_of_match[] = { @@ -681,8 +657,6 @@ static void gpio_remove_key(struct gpio_button_data *bdata) if (bdata->timer_debounce) del_timer_sync(&bdata->timer); cancel_work_sync(&bdata->work); - if (gpio_is_valid(bdata->button->gpio)) - gpio_free(bdata->button->gpio); } static int gpio_keys_probe(struct platform_device *pdev) @@ -700,14 +674,13 @@ static int gpio_keys_probe(struct platform_device *pdev) return PTR_ERR(pdata); } - ddata = kzalloc(sizeof(struct gpio_keys_drvdata) + - pdata->nbuttons * sizeof(struct gpio_button_data), - GFP_KERNEL); - input = input_allocate_device(); + ddata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_keys_drvdata) + + pdata->nbuttons * sizeof(struct gpio_button_data), + GFP_KERNEL); + input = devm_input_allocate_device(&pdev->dev); if (!ddata || !input) { dev_err(dev, "failed to allocate state\n"); - error = -ENOMEM; - goto fail1; + return -ENOMEM; } ddata->pdata = pdata; @@ -768,13 +741,6 @@ static int gpio_keys_probe(struct platform_device *pdev) while (--i >= 0) gpio_remove_key(&ddata->data[i]); - fail1: - input_free_device(input); - kfree(ddata); - /* If we have no platform data, we allocated pdata dynamically. */ - if (!dev_get_platdata(&pdev->dev)) - kfree(pdata); - return error; } @@ -793,12 +759,6 @@ static int gpio_keys_remove(struct platform_device *pdev) input_unregister_device(input); - /* If we have no platform data, we allocated pdata dynamically. */ - if (!dev_get_platdata(&pdev->dev)) - kfree(ddata->pdata); - - kfree(ddata); - return 0; }