From patchwork Wed Jul 13 16:06:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9227841 X-Patchwork-Delegate: jikos@jikos.cz 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 4DC32608A1 for ; Wed, 13 Jul 2016 16:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F24B27FA6 for ; Wed, 13 Jul 2016 16:10:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31D5A27FA4; Wed, 13 Jul 2016 16:10:17 +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 BF09227FA2 for ; Wed, 13 Jul 2016 16:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752298AbcGMQHF (ORCPT ); Wed, 13 Jul 2016 12:07:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36212 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbcGMQG7 (ORCPT ); Wed, 13 Jul 2016 12:06:59 -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 1B00D18689C; Wed, 13 Jul 2016 16:06:54 +0000 (UTC) Received: from plouf.banquise.eu.com (ovpn-116-194.phx2.redhat.com [10.3.116.194]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6DG6JwM004508; Wed, 13 Jul 2016 12:06:52 -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 v2 17/30] HID: wacom: EKR: have proper allocator and destructor Date: Wed, 13 Jul 2016 18:06:04 +0200 Message-Id: <1468425977-4819-18-git-send-email-benjamin.tissoires@redhat.com> In-Reply-To: <1468425977-4819-1-git-send-email-benjamin.tissoires@redhat.com> References: <1468425977-4819-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.28]); Wed, 13 Jul 2016 16:06:54 +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 The wacom_remote_create_attr_group() and wacom_remote_destroy_attr_group() functions were both allocating/destroying the sysfs groups but also initializing the parameters for the remotes. Have proper functions that can be called and extended. Signed-off-by: Benjamin Tissoires --- No changes in v2 --- drivers/hid/wacom_sys.c | 93 ++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 241acee..27ca147 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1300,8 +1300,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int error = 0; struct wacom_remote *remote = wacom->remote; - remote->serial[index] = serial; - remote->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev, GFP_KERNEL, "%d", serial); @@ -1319,27 +1317,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, return 0; } -static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) +static void wacom_remote_destroy_attr_group(struct wacom *wacom, unsigned int i) { struct wacom_remote *remote = wacom->remote; - int i; - if (!serial) - return; - - for (i = 0; i < WACOM_MAX_REMOTES; i++) { - if (remote->serial[i] == serial) { - remote->serial[i] = 0; - wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; - if (remote->remote_group[i].name) { - 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; - } - } - } + 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) @@ -1916,6 +1900,50 @@ fail: return; } +static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + u32 serial = remote->serial[index]; + int i; + + wacom_remote_destroy_attr_group(wacom, index); + + for (i = 0; i < WACOM_MAX_REMOTES; i++) { + if (remote->serial[i] == serial) { + remote->serial[i] = 0; + wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; + } + } +} + +static int wacom_remote_create_one(struct wacom *wacom, u32 serial, + unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + int error, k; + + /* A remote can pair more than once with an EKR, + * check to make sure this serial isn't already paired. + */ + for (k = 0; k < WACOM_MAX_REMOTES; k++) { + if (remote->serial[k] == serial) + break; + } + + if (k < WACOM_MAX_REMOTES) { + remote->serial[index] = serial; + return 0; + } + + error = wacom_remote_create_attr_group(wacom, serial, index); + if (error) + return error; + + remote->serial[index] = serial; + + return 0; +} + static void wacom_remote_work(struct work_struct *work) { struct wacom *wacom = container_of(work, struct wacom, remote_work); @@ -1924,7 +1952,7 @@ static void wacom_remote_work(struct work_struct *work) unsigned long flags; unsigned int count; u32 serial; - int i, k; + int i; spin_lock_irqsave(&remote->remote_lock, flags); @@ -1949,28 +1977,13 @@ static void wacom_remote_work(struct work_struct *work) if (remote->serial[i] == serial) continue; - if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); - } - - /* A remote can pair more than once with an EKR, - * check to make sure this serial isn't already paired. - */ - for (k = 0; k < WACOM_MAX_REMOTES; k++) { - if (remote->serial[k] == serial) - break; - } + if (remote->serial[i]) + wacom_remote_destroy_one(wacom, i); - if (k < WACOM_MAX_REMOTES) { - remote->serial[i] = serial; - continue; - } - wacom_remote_create_attr_group(wacom, serial, i); + wacom_remote_create_one(wacom, serial, i); } else if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); + wacom_remote_destroy_one(wacom, i); } } }