From patchwork Thu Jan 19 22:40:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9527085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D07D66020B for ; Thu, 19 Jan 2017 22:43:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C30EE28531 for ; Thu, 19 Jan 2017 22:43:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B639228671; Thu, 19 Jan 2017 22:43:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69DCF28531 for ; Thu, 19 Jan 2017 22:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753528AbdASWm6 (ORCPT ); Thu, 19 Jan 2017 17:42:58 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34744 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753249AbdASWlB (ORCPT ); Thu, 19 Jan 2017 17:41:01 -0500 Received: by mail-pg0-f65.google.com with SMTP id t6so5164747pgt.1; Thu, 19 Jan 2017 14:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KvFzqjPRV4JfqeCn6mm9bdXWY8bnMKWISCCkB+myIfE=; b=Tfu/2TrJ2Viz79kEr74Xe57g7bdSBG0qrq5FN7btRRqByEb3kO8pqV3vQrbjT2kYK/ z4vZn0BDhCHedmUDRxk8GWDq97BQuQQS26lAGLCqPtZYhWa+4i/9JQijtgtofH/4WvRF nyhbSWuidvodL1Zfj+UKFcWwFhNSvo1ec2BsJP8GTB1QMS/lVlfwcy9s3ChpBs1zmWLO sfTGfWTeBZsDzAsnS0yb/Ix/2H0UzMLzXcQMr1A670K+F5KcaZRwiLuwNTVmeQHSb5MT aqe8CgacfFFhOL3zp9dJgi+yjVg+kvryO+v5FONelIAVwFD0Mt1glR/t2PKDW7razT1Q JXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KvFzqjPRV4JfqeCn6mm9bdXWY8bnMKWISCCkB+myIfE=; b=Gh8iOU7wRFyyA/CP8bSMpkwP3kfdTfq3/nLVpolFTa09NNmAIcQ2OaWn/I6jZMKo74 9wz1Uc/8V/qfRcocLCu6X1rvJE70d2I9Phb9Ky5KACwtIIi3h8fmdYa21np03wSun4kQ 0s5lj0eNTK93Om9I2ziKqwophdg9VjPb5W2nWJly6gWchIJorUnk4CaVeYNXofpD49rv uYi+LWFRRqUMhDaWEJIdlXqsOdIZ/+0osB0KxafDkEEXa3UOmLwu5SROLoU55dD5Aes8 T8judo0J6XA05BwrGAAJQ689ZyWFP0LVWTtlluIK9+0d3sO/ZaY1onCEvxUxgnb9Keym tWxA== X-Gm-Message-State: AIkVDXKGBLko/YmoCV4Sb4o2siTD1vtViKsh31SW8yFCPHyo0mfJow4rTVzaOMQOYHUzJg== X-Received: by 10.84.134.169 with SMTP id 38mr16491481plh.67.1484865660587; Thu, 19 Jan 2017 14:41:00 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id s136sm11207573pgc.38.2017.01.19.14.40.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jan 2017 14:41:00 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Thierry Reding , linux-kernel@vger.kernel.org, David Lechner , Frieder Schrempf Subject: [PATCH v2 2/7] Input: pwm-beeper - switch to using managed resources Date: Thu, 19 Jan 2017 14:40:52 -0800 Message-Id: <20170119224057.9995-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170119224057.9995-1-dmitry.torokhov@gmail.com> References: <20170119224057.9995-1-dmitry.torokhov@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use of managed resources (devm) simplifies error handling and tear down of the driver. Signed-off-by: Dmitry Torokhov Reviewed-by: Thierry Reding --- drivers/input/misc/pwm-beeper.c | 44 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index cb87e475bd23..14c52054f5b7 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -95,18 +95,19 @@ static void pwm_beeper_close(struct input_dev *input) static int pwm_beeper_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct pwm_beeper *beeper; int error; - beeper = kzalloc(sizeof(*beeper), GFP_KERNEL); + beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); if (!beeper) return -ENOMEM; - beeper->pwm = pwm_get(&pdev->dev, NULL); + beeper->pwm = devm_pwm_get(dev, NULL); if (IS_ERR(beeper->pwm)) { error = PTR_ERR(beeper->pwm); - dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error); - goto err_free; + dev_err(dev, "Failed to request pwm device: %d\n", error); + return error; } /* @@ -117,13 +118,11 @@ static int pwm_beeper_probe(struct platform_device *pdev) INIT_WORK(&beeper->work, pwm_beeper_work); - beeper->input = input_allocate_device(); + beeper->input = devm_input_allocate_device(dev); if (!beeper->input) { - dev_err(&pdev->dev, "Failed to allocate input device\n"); - error = -ENOMEM; - goto err_pwm_free; + dev_err(dev, "Failed to allocate input device\n"); + return -ENOMEM; } - beeper->input->dev.parent = &pdev->dev; beeper->input->name = "pwm-beeper"; beeper->input->phys = "pwm/input0"; @@ -142,35 +141,13 @@ static int pwm_beeper_probe(struct platform_device *pdev) error = input_register_device(beeper->input); if (error) { - dev_err(&pdev->dev, "Failed to register input device: %d\n", error); - goto err_input_free; + dev_err(dev, "Failed to register input device: %d\n", error); + return error; } platform_set_drvdata(pdev, beeper); return 0; - -err_input_free: - input_free_device(beeper->input); -err_pwm_free: - pwm_free(beeper->pwm); -err_free: - kfree(beeper); - - return error; -} - -static int pwm_beeper_remove(struct platform_device *pdev) -{ - struct pwm_beeper *beeper = platform_get_drvdata(pdev); - - input_unregister_device(beeper->input); - - pwm_free(beeper->pwm); - - kfree(beeper); - - return 0; } static int __maybe_unused pwm_beeper_suspend(struct device *dev) @@ -205,7 +182,6 @@ MODULE_DEVICE_TABLE(of, pwm_beeper_match); static struct platform_driver pwm_beeper_driver = { .probe = pwm_beeper_probe, - .remove = pwm_beeper_remove, .driver = { .name = "pwm-beeper", .pm = &pwm_beeper_pm_ops,