From patchwork Tue Jul 5 14:39:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9214431 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 1DE2C6088F for ; Tue, 5 Jul 2016 14:44:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 102CB24EE5 for ; Tue, 5 Jul 2016 14:44:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04D8E2522B; Tue, 5 Jul 2016 14:44:09 +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=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 9822A25221 for ; Tue, 5 Jul 2016 14:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754508AbcGEOoD (ORCPT ); Tue, 5 Jul 2016 10:44:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50170 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933146AbcGEOkE (ORCPT ); Tue, 5 Jul 2016 10:40:04 -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 25648D3C2A; Tue, 5 Jul 2016 14:40:04 +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 u65EdPaJ001766; Tue, 5 Jul 2016 10:40:02 -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 18/27] HID: wacom: EKR: use devres groups to manage resources Date: Tue, 5 Jul 2016 16:39:14 +0200 Message-Id: <1467729563-23318-19-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.38]); Tue, 05 Jul 2016 14:40:04 +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 This will be useful when each remote will be assigned its own input device. We won't need to unregister each input and sysfs and other elements one at a time. Signed-off-by: Benjamin Tissoires --- drivers/hid/wacom_sys.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 27ca147..9121e72 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -934,8 +934,9 @@ static void wacom_devm_sysfs_group_release(struct device *dev, void *res) sysfs_remove_group(kobj, devres->group); } -static int wacom_devm_sysfs_create_group(struct wacom *wacom, - struct attribute_group *group) +static int __wacom_devm_sysfs_create_group(struct wacom *wacom, + struct kobject *root, + struct attribute_group *group) { struct wacom_sysfs_group_devres *devres; int error; @@ -947,7 +948,7 @@ static int wacom_devm_sysfs_create_group(struct wacom *wacom, return -ENOMEM; devres->group = group; - devres->root = &wacom->hdev->dev.kobj; + devres->root = root; error = sysfs_create_group(devres->root, group); if (error) @@ -958,6 +959,13 @@ static int wacom_devm_sysfs_create_group(struct wacom *wacom, return 0; } +static int wacom_devm_sysfs_create_group(struct wacom *wacom, + struct attribute_group *group) +{ + return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj, + group); +} + static void wacom_led_groups_release(void *data) { struct wacom *wacom = data; @@ -1306,9 +1314,10 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, if (!remote->remote_group[index].name) return -ENOMEM; - error = sysfs_create_group(remote->remote_dir, - &remote->remote_group[index]); + error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir, + &remote->remote_group[index]); if (error) { + remote->remote_group[index].name = NULL; hid_err(wacom->hdev, "cannot create sysfs group err: %d\n", error); return error; @@ -1317,15 +1326,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, return 0; } -static void wacom_remote_destroy_attr_group(struct wacom *wacom, unsigned int i) -{ - struct wacom_remote *remote = wacom->remote; - - sysfs_remove_group(remote->remote_dir, &remote->remote_group[i]); - devm_kfree(&wacom->hdev->dev, (char *)remote->remote_group[i].name); - remote->remote_group[i].name = NULL; -} - static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) { const size_t buf_size = 2; @@ -1906,11 +1906,13 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) u32 serial = remote->serial[index]; int i; - wacom_remote_destroy_attr_group(wacom, index); + if (remote->remote_group[index].name) + devres_release_group(&wacom->hdev->dev, &remote->serial[index]); for (i = 0; i < WACOM_MAX_REMOTES; i++) { if (remote->serial[i] == serial) { remote->serial[i] = 0; + remote->remote_group[i].name = NULL; wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; } } @@ -1920,6 +1922,7 @@ static int wacom_remote_create_one(struct wacom *wacom, u32 serial, unsigned int index) { struct wacom_remote *remote = wacom->remote; + struct device *dev = &wacom->hdev->dev; int error, k; /* A remote can pair more than once with an EKR, @@ -1935,13 +1938,22 @@ static int wacom_remote_create_one(struct wacom *wacom, u32 serial, return 0; } + if (!devres_open_group(dev, &remote->serial[index], GFP_KERNEL)) + return -ENOMEM; + error = wacom_remote_create_attr_group(wacom, serial, index); if (error) - return error; + goto fail; remote->serial[index] = serial; + devres_close_group(dev, &remote->serial[index]); return 0; + +fail: + devres_release_group(dev, &remote->serial[index]); + remote->serial[index] = 0; + return error; } static void wacom_remote_work(struct work_struct *work)