From patchwork Tue Sep 20 09:01:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 9341367 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 8AE1A607D0 for ; Tue, 20 Sep 2016 09:01:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7943329D58 for ; Tue, 20 Sep 2016 09:01:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C84429D69; Tue, 20 Sep 2016 09:01:45 +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_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 06C0E29D58 for ; Tue, 20 Sep 2016 09:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752364AbcITJBk (ORCPT ); Tue, 20 Sep 2016 05:01:40 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:33877 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045AbcITJBj (ORCPT ); Tue, 20 Sep 2016 05:01:39 -0400 Received: by mail-pa0-f67.google.com with SMTP id vz6so653486pab.1 for ; Tue, 20 Sep 2016 02:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ingics-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=I5qBGqaomA/Cm0OHJV1+KLiUTHnolm7gdd90gFKhcv0=; b=IBKo4SHJYfEsX02I64Szga7Q9ao2VMXQHWSJneTCpgTHo335nmuYLWORmpl5lmJP0q Ni45sL0h43/WENQhSubIaiEIuBNBZuZjcS0yYrZWxQY95oi/T1mEAvdvu0lQjpAVzhpb EBk5Mqudy+WOPoRpmdxG6EXsDkWwMl0Zl2waZlBrLLb+XL5u5BzrNI5C5TXWnOhiEiFd PoafOQA99FgHemWVxg3fTlUrihVKzXOrgl6k1zC9ivu0f2AKhjHUSZWQlOigOtLID2oA a5MrRAlIAnbCEiHTaHOw3k3oX4GMYX1b8SdiV6ycoBucTJqxbyfD25Y8PtL21g0Mtxvj 7p8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=I5qBGqaomA/Cm0OHJV1+KLiUTHnolm7gdd90gFKhcv0=; b=Z+kqnYx4zlwimn2tYjCw6ABZ87OEVj1SDUJW0XO8xWX/0k+oZLJ5mBdACZ/XZ0Yi76 PGjhyZdyK1AIy0YXgt0Yb6axOqkgdJprDXwXeZkytWZlGIce/Fo2Be8x6Y46U8libgrF CN5YdEk928DVZ9XS/AWLbyTqE33HIgJG0C1xRMKy6eWtWr+nS3spiAzOJhX+HCebw565 61Enq3fOn4kG7PCg6toHz5I1GeiqF0/H+kLKxca1l3SFMU3CCfwmR4IzwaIycJmL67ua uxPoTzutPte9DwvUle7EmJoC0USEElgojEp2/tUvS5wzR+UitfCJBKmkdF7nsVtnrJq3 48Fw== X-Gm-Message-State: AE9vXwPU3h2y/QTwHg6x4NpCSUkVdq8lbkXlalovajUbOKSBsGZEuMqOBPsRAX5Z+e3Zyg== X-Received: by 10.66.157.103 with SMTP id wl7mr53391337pab.116.1474362098604; Tue, 20 Sep 2016 02:01:38 -0700 (PDT) Received: from localhost.localdomain (59-115-243-103.dynamic.hinet.net. [59.115.243.103]) by smtp.gmail.com with ESMTPSA id ve9sm37311168pac.12.2016.09.20.02.01.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Sep 2016 02:01:38 -0700 (PDT) From: Axel Lin To: Darren Hart Cc: AceLan Kao , platform-driver-x86@vger.kernel.org, Axel Lin Subject: [PATCH RFT] platform/x86: intel-vbtn: Switch to use devm_input_allocate_device Date: Tue, 20 Sep 2016 17:01:24 +0800 Message-Id: <1474362084-2670-1-git-send-email-axel.lin@ingics.com> X-Mailer: git-send-email 2.7.4 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_input_allocate_device to simplify the error handling code. This conversion also makes input_register_device() to be called after acpi_remove_notify_handler. This avoid a small window that it's possible to call notify_handler after unregister input device. Signed-off-by: Axel Lin Reviewed-by: Andy Shevchenko --- drivers/platform/x86/intel-vbtn.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c index f04a394..bd7230a 100644 --- a/drivers/platform/x86/intel-vbtn.c +++ b/drivers/platform/x86/intel-vbtn.c @@ -49,34 +49,19 @@ static int intel_vbtn_input_setup(struct platform_device *device) struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev); int ret; - priv->input_dev = input_allocate_device(); + priv->input_dev = devm_input_allocate_device(&device->dev); if (!priv->input_dev) return -ENOMEM; ret = sparse_keymap_setup(priv->input_dev, intel_vbtn_keymap, NULL); if (ret) - goto err_free_device; + return ret; priv->input_dev->dev.parent = &device->dev; priv->input_dev->name = "Intel Virtual Button driver"; priv->input_dev->id.bustype = BUS_HOST; - ret = input_register_device(priv->input_dev); - if (ret) - goto err_free_device; - - return 0; - -err_free_device: - input_free_device(priv->input_dev); - return ret; -} - -static void intel_vbtn_input_destroy(struct platform_device *device) -{ - struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev); - - input_unregister_device(priv->input_dev); + return input_register_device(priv->input_dev); } static void notify_handler(acpi_handle handle, u32 event, void *context) @@ -117,24 +102,16 @@ static int intel_vbtn_probe(struct platform_device *device) ACPI_DEVICE_NOTIFY, notify_handler, device); - if (ACPI_FAILURE(status)) { - err = -EBUSY; - goto err_remove_input; - } + if (ACPI_FAILURE(status)) + return -EBUSY; return 0; - -err_remove_input: - intel_vbtn_input_destroy(device); - - return err; } static int intel_vbtn_remove(struct platform_device *device) { acpi_handle handle = ACPI_HANDLE(&device->dev); - intel_vbtn_input_destroy(device); acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); /*