From patchwork Tue Jul 5 14:39:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9214459 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 593A060752 for ; Tue, 5 Jul 2016 14:46:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AA0225227 for ; Tue, 5 Jul 2016 14:46:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D78225749; Tue, 5 Jul 2016 14:46:34 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 D911F25227 for ; Tue, 5 Jul 2016 14:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933187AbcGEOqI (ORCPT ); Tue, 5 Jul 2016 10:46:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46395 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933022AbcGEOjm (ORCPT ); Tue, 5 Jul 2016 10:39:42 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11CD580E4A; Tue, 5 Jul 2016 14:39:42 +0000 (UTC) Received: from plouf.banquise.eu.com (ovpn-116-124.ams2.redhat.com [10.36.116.124]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u65EdPa8001766; Tue, 5 Jul 2016 10:39:40 -0400 From: Benjamin Tissoires To: Jiri Kosina , Ping Cheng , Jason Gerecke , Aaron Skomra , Peter Hutterer Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 07/27] HID: wacom: switch inputs to devres Date: Tue, 5 Jul 2016 16:39:03 +0200 Message-Id: <1467729563-23318-8-git-send-email-benjamin.tissoires@redhat.com> In-Reply-To: <1467729563-23318-1-git-send-email-benjamin.tissoires@redhat.com> References: <1467729563-23318-1-git-send-email-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 05 Jul 2016 14:39:42 +0000 (UTC) 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 Simplifying the error code paths. We need to keep wacom_clean_inputs() around for now as the wireless module is using it to dynamically remove the inputs on disconnect. Signed-off-by: Benjamin Tissoires --- drivers/hid/wacom_sys.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 61dcb87e..da2fccf 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -91,7 +91,12 @@ static void wacom_close(struct input_dev *dev) { struct wacom *wacom = input_get_drvdata(dev); - hid_hw_close(wacom->hdev); + /* + * wacom->hdev should never be null, but surprisingly, I had the case + * once while unplugging the Wacom Wireless Receiver. + */ + if (wacom->hdev) + hid_hw_close(wacom->hdev); } /* @@ -1370,7 +1375,7 @@ static struct input_dev *wacom_allocate_input(struct wacom *wacom) struct hid_device *hdev = wacom->hdev; struct wacom_wac *wacom_wac = &(wacom->wacom_wac); - input_dev = input_allocate_device(); + input_dev = devm_input_allocate_device(&hdev->dev); if (!input_dev) return NULL; @@ -1424,10 +1429,10 @@ static int wacom_allocate_inputs(struct wacom *wacom) wacom_wac->pen_input = wacom_allocate_input(wacom); wacom_wac->touch_input = wacom_allocate_input(wacom); wacom_wac->pad_input = wacom_allocate_input(wacom); - if (!wacom_wac->pen_input || !wacom_wac->touch_input || !wacom_wac->pad_input) { - wacom_clean_inputs(wacom); + if (!wacom_wac->pen_input || + !wacom_wac->touch_input || + !wacom_wac->pad_input) return -ENOMEM; - } wacom_wac->pen_input->name = wacom_wac->pen_name; wacom_wac->touch_input->name = wacom_wac->touch_name; @@ -1458,7 +1463,7 @@ static int wacom_register_inputs(struct wacom *wacom) } else { error = input_register_device(pen_input_dev); if (error) - goto fail_register_pen_input; + goto fail; wacom_wac->pen_registered = true; } @@ -1471,7 +1476,7 @@ static int wacom_register_inputs(struct wacom *wacom) } else { error = input_register_device(touch_input_dev); if (error) - goto fail_register_touch_input; + goto fail; wacom_wac->touch_registered = true; } @@ -1484,23 +1489,19 @@ static int wacom_register_inputs(struct wacom *wacom) } else { error = input_register_device(pad_input_dev); if (error) - goto fail_register_pad_input; + goto fail; wacom_wac->pad_registered = true; } return 0; -fail_register_pad_input: - if (touch_input_dev) - input_unregister_device(touch_input_dev); +fail: + wacom_wac->pad_input = NULL; + wacom_wac->pad_registered = false; wacom_wac->touch_input = NULL; wacom_wac->touch_registered = false; -fail_register_touch_input: - if (pen_input_dev) - input_unregister_device(pen_input_dev); wacom_wac->pen_input = NULL; wacom_wac->pen_registered = false; -fail_register_pen_input: return error; } @@ -1741,14 +1742,12 @@ fail_hw_start: fail_remote: wacom_destroy_leds(wacom); fail_leds: - wacom_clean_inputs(wacom); fail_register_inputs: fail_battery: wacom_remove_shared_data(wacom); fail_shared_data: fail_parsed: fail_allocate_inputs: - wacom_clean_inputs(wacom); return error; } @@ -1928,7 +1927,6 @@ static void wacom_remove(struct hid_device *hdev) cancel_work_sync(&wacom->battery_work); kobject_put(wacom->remote_dir); wacom_destroy_leds(wacom); - wacom_clean_inputs(wacom); if (hdev->bus == BUS_BLUETOOTH) device_remove_file(&hdev->dev, &dev_attr_speed); wacom_remove_shared_data(wacom);