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: 1748791 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 10C693FC8A for ; Thu, 15 Nov 2012 12:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2993410Ab2KOMCw (ORCPT ); Thu, 15 Nov 2012 07:02:52 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:48894 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993257Ab2KOMCv (ORCPT ); Thu, 15 Nov 2012 07:02:51 -0500 Received: by mail-pa0-f46.google.com with SMTP id hz1so1031620pad.19 for ; Thu, 15 Nov 2012 04:02:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=Z5lAptzqXu9Bef30SLmDk9beCe9+O2WesgvikgiJtVc=; b=Bc4jqBiODZsGitkGkxLGY8/MUmTrRkoSOvLuRiCf9SXPOm+xQu5Ga1WLwyGMjfl7H4 t6hyqyRoLB+lwMCmbjmfluXxSJuNzUu0OiEC2PA8pWBJ6ZJHqWP9TwwKSXEXubbVuuPh fWnba0Y291E6DQdbAOiL+FkTeFWdZx8l6YTuwMfc2riAPVnVL/vsheJ77v5sj6NBnfe+ UPdRwFMUp6D1soce0IeXWKjFNA0rrYLETYV5h6XtbqlS+IRppyzRcP0zPgR2tXEKf2FV vm7PHZQJAKKD6j/g20069Xu5Y+aL2ZsAh1Dt9p6HE9C7+LEZXTzzvSVhewzuurOneBJD yckg== 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: ALoCoQnUEWIRRDn9aYZ2RVLLpBLLko/RDrjNPYQ982iCasZYMMXjVwVWDngMiG49P08MRJWWxvOx Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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; }