From patchwork Tue Oct 7 11:31:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 5045151 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 2B317C11AB for ; Tue, 7 Oct 2014 11:28:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 422A7201F5 for ; Tue, 7 Oct 2014 11:28:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BD53201F4 for ; Tue, 7 Oct 2014 11:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753520AbaJGL2O (ORCPT ); Tue, 7 Oct 2014 07:28:14 -0400 Received: from smtp96.ord1c.emailsrvr.com ([108.166.43.96]:50654 "EHLO smtp96.ord1c.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753400AbaJGL2N (ORCPT ); Tue, 7 Oct 2014 07:28:13 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp5.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id BA2C0180509; Tue, 7 Oct 2014 07:28:12 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp5.relay.ord1c.emailsrvr.com (Authenticated sender: pramod.gurav-AT-smartplayin.com) with ESMTPSA id 1C638180042; Tue, 7 Oct 2014 07:28:10 -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); Tue, 07 Oct 2014 11:28:12 GMT From: Pramod Gurav To: linux-kernel@vger.kernel.org Cc: Pramod Gurav , Dmitry Torokhov , linux-input@vger.kernel.org Subject: [PATCH] Input: opencores-kbd: Switch to using managed resources Date: Tue, 7 Oct 2014 17:01:41 +0530 Message-Id: <1412681501-28072-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=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_RHS_DOB 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 This change switch to managed resources to simplifies error handling and module unloading and does away with platform_driver remove function. Cc: Dmitry Torokhov Cc: linux-input@vger.kernel.org Signed-off-by: Pramod Gurav --- drivers/input/keyboard/opencores-kbd.c | 54 ++++++++------------------------ 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c index 7b9b441..ecacb87 100644 --- a/drivers/input/keyboard/opencores-kbd.c +++ b/drivers/input/keyboard/opencores-kbd.c @@ -56,27 +56,27 @@ static int opencores_kbd_probe(struct platform_device *pdev) return -EINVAL; } - opencores_kbd = kzalloc(sizeof(*opencores_kbd), GFP_KERNEL); - input = input_allocate_device(); + opencores_kbd = devm_kzalloc(&pdev->dev, sizeof(*opencores_kbd), + GFP_KERNEL); + input = devm_input_allocate_device(&pdev->dev); if (!opencores_kbd || !input) { dev_err(&pdev->dev, "failed to allocate device structures\n"); - error = -ENOMEM; - goto err_free_mem; + return -ENOMEM; } opencores_kbd->addr_res = res; - res = request_mem_region(res->start, resource_size(res), pdev->name); + res = devm_request_mem_region(&pdev->dev, res->start, + resource_size(res), pdev->name); if (!res) { dev_err(&pdev->dev, "failed to request I/O memory\n"); - error = -EBUSY; - goto err_free_mem; + return -EBUSY; } - opencores_kbd->addr = ioremap(res->start, resource_size(res)); + opencores_kbd->addr = devm_ioremap(&pdev->dev, res->start, + resource_size(res)); if (!opencores_kbd->addr) { dev_err(&pdev->dev, "failed to remap I/O memory\n"); - error = -ENXIO; - goto err_rel_mem; + return -ENXIO; } opencores_kbd->input = input; @@ -109,54 +109,26 @@ static int opencores_kbd_probe(struct platform_device *pdev) } __clear_bit(KEY_RESERVED, input->keybit); - error = request_irq(irq, &opencores_kbd_isr, + error = devm_request_irq(&pdev->dev, irq, &opencores_kbd_isr, IRQF_TRIGGER_RISING, pdev->name, opencores_kbd); if (error) { dev_err(&pdev->dev, "unable to claim irq %d\n", irq); - goto err_unmap_mem; + return error; } error = input_register_device(input); if (error) { dev_err(&pdev->dev, "unable to register input device\n"); - goto err_free_irq; + return error; } platform_set_drvdata(pdev, opencores_kbd); return 0; - - err_free_irq: - free_irq(irq, opencores_kbd); - err_unmap_mem: - iounmap(opencores_kbd->addr); - err_rel_mem: - release_mem_region(res->start, resource_size(res)); - err_free_mem: - input_free_device(input); - kfree(opencores_kbd); - - return error; -} - -static int opencores_kbd_remove(struct platform_device *pdev) -{ - struct opencores_kbd *opencores_kbd = platform_get_drvdata(pdev); - - free_irq(opencores_kbd->irq, opencores_kbd); - - iounmap(opencores_kbd->addr); - release_mem_region(opencores_kbd->addr_res->start, - resource_size(opencores_kbd->addr_res)); - input_unregister_device(opencores_kbd->input); - kfree(opencores_kbd); - - return 0; } static struct platform_driver opencores_kbd_device_driver = { .probe = opencores_kbd_probe, - .remove = opencores_kbd_remove, .driver = { .name = "opencores-kbd", },