From patchwork Thu Nov 15 11:56:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 12866 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 46A5D23E02 for ; Thu, 15 Nov 2012 12:02:53 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id C6DFCA18982 for ; Thu, 15 Nov 2012 12:02:52 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so1987642iej.11 for ; Thu, 15 Nov 2012 04:02:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=Z5lAptzqXu9Bef30SLmDk9beCe9+O2WesgvikgiJtVc=; b=dAWMq3vjOULVE0RMC1psDVxB2TswRxYf2SEwPJkP7SutJpr3b1a0a+EqMNXwQeIMpv N+nR5VR9k4PBvnWMUkQI0Cmx1TCOXTnmsqmR6PLaYTQ2Q/zFIfHPgHXdpExPAluaFld7 ny8THlPr4lvmZeMgiExJoEQ+/3eLZcKOurmV34P695bH/vY/pFPcppNOMIZNGyKoV51O 3YKLF60w3qGKmeLqsMhbgKZMZE/vHrxfSVpAjGB45w4BKQwDXHPEGjRhgqkmcvcg1KbX kuqDtrmQXgdUrju6ZhxxltFGQlDJi44CbJJtnqL0Chj/zbm8P/w0+novzIuMJsBtHhUI /hwg== Received: by 10.50.187.197 with SMTP id fu5mr605827igc.70.1352980972254; Thu, 15 Nov 2012 04:02:52 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp813887igt; Thu, 15 Nov 2012 04:02:51 -0800 (PST) Received: by 10.66.84.40 with SMTP id v8mr2603722pay.47.1352980971524; Thu, 15 Nov 2012 04:02:51 -0800 (PST) Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by mx.google.com with ESMTPS id q6si22264154pay.313.2012.11.15.04.02.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 04:02:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.43 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.220.43; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.43 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by mail-pa0-f43.google.com with SMTP id fb1so1411618pad.16 for ; Thu, 15 Nov 2012 04:02:51 -0800 (PST) Received: by 10.69.1.35 with SMTP id bd3mr3959101pbd.141.1352980971225; Thu, 15 Nov 2012 04:02:51 -0800 (PST) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id bv6sm9640449pab.13.2012.11.15.04.02.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 04:02:50 -0800 (PST) From: Sachin Kamat To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, sachin.kamat@linaro.org, patches@linaro.org Subject: [PATCH 1/1] input: samsung-keypad: Use devm_* functions Date: Thu, 15 Nov 2012 17:26:38 +0530 Message-Id: <1352980598-6305-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQlhpbXauyY7/oHJmh+rG9xP+CDw0nSNai5++pBaGG6OukkVl7hwxK/E26H++oqyWo5IfTdH devm_* functions are device managed and make error handling and code simpler. Signed-off-by: Sachin Kamat --- drivers/input/keyboard/samsung-keypad.c | 59 +++++++++--------------------- 1 files changed, 18 insertions(+), 41 deletions(-) diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index 9d7a111..abf6d3d 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -405,36 +405,29 @@ static int __devinit samsung_keypad_probe(struct platform_device *pdev) row_shift = get_count_order(pdata->cols); keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]); - keypad = kzalloc(sizeof(*keypad) + keymap_size, GFP_KERNEL); - input_dev = input_allocate_device(); - if (!keypad || !input_dev) { - error = -ENOMEM; - goto err_free_mem; - } + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size, GFP_KERNEL); + input_dev = devm_input_allocate_device(&pdev->dev); + if (!keypad || !input_dev) + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - error = -ENODEV; - goto err_free_mem; - } + if (!res) + return -ENODEV; - keypad->base = ioremap(res->start, resource_size(res)); - if (!keypad->base) { - error = -EBUSY; - goto err_free_mem; - } + keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!keypad->base) + return -EBUSY; - keypad->clk = clk_get(&pdev->dev, "keypad"); + keypad->clk = devm_clk_get(&pdev->dev, "keypad"); if (IS_ERR(keypad->clk)) { dev_err(&pdev->dev, "failed to get keypad clk\n"); - error = PTR_ERR(keypad->clk); - goto err_unmap_base; + return PTR_ERR(keypad->clk); } error = clk_prepare(keypad->clk); if (error) { dev_err(&pdev->dev, "keypad clock prepare failed\n"); - goto err_put_clk; + goto err_dt_gpio_free; } keypad->input_dev = input_dev; @@ -479,14 +472,15 @@ static int __devinit samsung_keypad_probe(struct platform_device *pdev) keypad->irq = platform_get_irq(pdev, 0); if (keypad->irq < 0) { error = keypad->irq; - goto err_put_clk; + goto err_dt_gpio_free; } - error = request_threaded_irq(keypad->irq, NULL, samsung_keypad_irq, - IRQF_ONESHOT, dev_name(&pdev->dev), keypad); + error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, + samsung_keypad_irq, IRQF_ONESHOT, + dev_name(&pdev->dev), keypad); if (error) { dev_err(&pdev->dev, "failed to register keypad interrupt\n"); - goto err_put_clk; + goto err_dt_gpio_free; } device_init_wakeup(&pdev->dev, pdata->wakeup); @@ -505,20 +499,13 @@ static int __devinit samsung_keypad_probe(struct platform_device *pdev) return 0; err_free_irq: - free_irq(keypad->irq, keypad); pm_runtime_disable(&pdev->dev); device_init_wakeup(&pdev->dev, 0); platform_set_drvdata(pdev, NULL); err_unprepare_clk: clk_unprepare(keypad->clk); -err_put_clk: - clk_put(keypad->clk); +err_dt_gpio_free: samsung_keypad_dt_gpio_free(keypad); -err_unmap_base: - iounmap(keypad->base); -err_free_mem: - input_free_device(input_dev); - kfree(keypad); return error; } @@ -533,19 +520,9 @@ static int __devexit samsung_keypad_remove(struct platform_device *pdev) input_unregister_device(keypad->input_dev); - /* - * It is safe to free IRQ after unregistering device because - * samsung_keypad_close will shut off interrupts. - */ - free_irq(keypad->irq, keypad); - clk_unprepare(keypad->clk); - clk_put(keypad->clk); samsung_keypad_dt_gpio_free(keypad); - iounmap(keypad->base); - kfree(keypad); - return 0; }