From patchwork Wed Oct 8 10:50:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 5053241 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 3D7AD9F30B for ; Wed, 8 Oct 2014 10:48:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 445F120200 for ; Wed, 8 Oct 2014 10:48:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34003201FA for ; Wed, 8 Oct 2014 10:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932104AbaJHKrK (ORCPT ); Wed, 8 Oct 2014 06:47:10 -0400 Received: from smtp88.ord1c.emailsrvr.com ([108.166.43.88]:57976 "EHLO smtp88.ord1c.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932109AbaJHKqz (ORCPT ); Wed, 8 Oct 2014 06:46:55 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp20.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id 87992802AC; Wed, 8 Oct 2014 06:46:54 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp20.relay.ord1c.emailsrvr.com (Authenticated sender: pramod.gurav-AT-smartplayin.com) with ESMTPSA id 1184E802A4; Wed, 8 Oct 2014 06:46:52 -0400 (EDT) X-Sender-Id: pramod.gurav@smartplayin.com Received: from SPINITLTDL00278.smartplayin.local ([UNAVAILABLE]. [220.227.185.53]) (using TLSv1.1 with cipher DHE-RSA-AES256-SHA) by 0.0.0.0:465 (trex/5.2.13); Wed, 08 Oct 2014 10:46:54 GMT From: Pramod Gurav To: linux-kernel@vger.kernel.org Cc: Pramod Gurav , Dmitry Torokhov , linux-input@vger.kernel.org Subject: [PATCH] Input: nomadik-ske-keypad: Switch to using managed resources Date: Wed, 8 Oct 2014 16:20:28 +0530 Message-Id: <1412765428-6517-1-git-send-email-pramod.gurav@smartplayin.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@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=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 change switches to using devm_* APIs to allocate resources. This helps to simplify failure path in probe function as well as remove function. Cc: Dmitry Torokhov Cc: linux-input@vger.kernel.org Signed-off-by: Pramod Gurav --- drivers/input/keyboard/nomadik-ske-keypad.c | 63 +++++++++------------------ 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c index 63332e2..95ac317 100644 --- a/drivers/input/keyboard/nomadik-ske-keypad.c +++ b/drivers/input/keyboard/nomadik-ske-keypad.c @@ -247,12 +247,11 @@ static int __init ske_keypad_probe(struct platform_device *pdev) return -EINVAL; } - keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL); + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); input = input_allocate_device(); if (!keypad || !input) { dev_err(&pdev->dev, "failed to allocate keypad memory\n"); - error = -ENOMEM; - goto err_free_mem; + return -ENOMEM; } keypad->irq = irq; @@ -260,31 +259,29 @@ static int __init ske_keypad_probe(struct platform_device *pdev) keypad->input = input; spin_lock_init(&keypad->ske_keypad_lock); - if (!request_mem_region(res->start, resource_size(res), pdev->name)) { + if (!devm_request_mem_region(&pdev->dev, res->start, + resource_size(res), pdev->name)) { dev_err(&pdev->dev, "failed to request I/O memory\n"); - error = -EBUSY; - goto err_free_mem; + return -EBUSY; } - keypad->reg_base = ioremap(res->start, resource_size(res)); + keypad->reg_base = devm_ioremap(&pdev->dev, res->start, + resource_size(res)); if (!keypad->reg_base) { dev_err(&pdev->dev, "failed to remap I/O memory\n"); - error = -ENXIO; - goto err_free_mem_region; + return -ENXIO; } - keypad->pclk = clk_get(&pdev->dev, "apb_pclk"); + keypad->pclk = devm_clk_get(&pdev->dev, "apb_pclk"); if (IS_ERR(keypad->pclk)) { dev_err(&pdev->dev, "failed to get pclk\n"); - error = PTR_ERR(keypad->pclk); - goto err_iounmap; + return PTR_ERR(keypad->pclk); } - keypad->clk = clk_get(&pdev->dev, NULL); + keypad->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(keypad->clk)) { dev_err(&pdev->dev, "failed to get clk\n"); - error = PTR_ERR(keypad->clk); - goto err_pclk; + return PTR_ERR(keypad->clk); } input->id.bustype = BUS_HOST; @@ -296,7 +293,7 @@ static int __init ske_keypad_probe(struct platform_device *pdev) keypad->keymap, input); if (error) { dev_err(&pdev->dev, "Failed to build keymap\n"); - goto err_clk; + return error; } input_set_capability(input, EV_MSC, MSC_SCAN); @@ -306,7 +303,7 @@ static int __init ske_keypad_probe(struct platform_device *pdev) error = clk_prepare_enable(keypad->pclk); if (error) { dev_err(&pdev->dev, "Failed to prepare/enable pclk\n"); - goto err_clk; + return error; } error = clk_prepare_enable(keypad->clk); @@ -326,8 +323,9 @@ static int __init ske_keypad_probe(struct platform_device *pdev) goto err_clk_disable; } - error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq, - IRQF_ONESHOT, "ske-keypad", keypad); + error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, + ske_keypad_irq, IRQF_ONESHOT, + "ske-keypad", keypad); if (error) { dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); goto err_clk_disable; @@ -337,7 +335,7 @@ static int __init ske_keypad_probe(struct platform_device *pdev) if (error) { dev_err(&pdev->dev, "unable to register input device: %d\n", error); - goto err_free_irq; + goto err_clk_disable; } if (plat->wakeup_enable) @@ -347,45 +345,24 @@ static int __init ske_keypad_probe(struct platform_device *pdev) return 0; -err_free_irq: - free_irq(keypad->irq, keypad); err_clk_disable: clk_disable_unprepare(keypad->clk); err_pclk_disable: clk_disable_unprepare(keypad->pclk); -err_clk: - clk_put(keypad->clk); -err_pclk: - clk_put(keypad->pclk); -err_iounmap: - iounmap(keypad->reg_base); -err_free_mem_region: - release_mem_region(res->start, resource_size(res)); -err_free_mem: - input_free_device(input); - kfree(keypad); + return error; } static int ske_keypad_remove(struct platform_device *pdev) { struct ske_keypad *keypad = platform_get_drvdata(pdev); - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - - free_irq(keypad->irq, keypad); - - input_unregister_device(keypad->input); clk_disable_unprepare(keypad->clk); - clk_put(keypad->clk); + clk_disable_unprepare(keypad->pclk); if (keypad->board->exit) keypad->board->exit(); - iounmap(keypad->reg_base); - release_mem_region(res->start, resource_size(res)); - kfree(keypad); - return 0; }