From patchwork Tue Jul 5 14:39:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9214449 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 7E8B260752 for ; Tue, 5 Jul 2016 14:45:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 711D62522B for ; Tue, 5 Jul 2016 14:45:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65E9125749; Tue, 5 Jul 2016 14:45:30 +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 64A842522B for ; Tue, 5 Jul 2016 14:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933069AbcGEOju (ORCPT ); Tue, 5 Jul 2016 10:39:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45224 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933060AbcGEOjs (ORCPT ); Tue, 5 Jul 2016 10:39:48 -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 0B8323B741; Tue, 5 Jul 2016 14:39:48 +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 u65EdPaB001766; Tue, 5 Jul 2016 10:39:46 -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 10/27] HID: wacom: use devm_kasprintf for allocating the name of the remote Date: Tue, 5 Jul 2016 16:39:06 +0200 Message-Id: <1467729563-23318-11-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.30]); Tue, 05 Jul 2016 14:39:48 +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 sysfs group was indeed removed by kobject_put(wacom->remote_dir) in wacom_remove(), but the name of the group was never freed. Also remove the misplaced kobject_put(wacom->remote_dir) in the error path of wacom_remote_create_attr_group(). Signed-off-by: Benjamin Tissoires --- drivers/hid/wacom_sys.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index c08a752..ec088c1 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -25,7 +25,6 @@ #define WAC_CMD_RETRIES 10 #define WAC_CMD_DELETE_PAIRING 0x20 #define WAC_CMD_UNPAIR_ALL 0xFF -#define WAC_REMOTE_SERIAL_MAX_STRLEN 9 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) @@ -1233,23 +1232,21 @@ DEVICE_EKR_ATTR_GROUP(4); int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int index) { int error = 0; - char *buf; struct wacom_wac *wacom_wac = &wacom->wacom_wac; wacom_wac->serial[index] = serial; - buf = kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN, GFP_KERNEL); - if (!buf) + wacom->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev, + GFP_KERNEL, + "%d", serial); + if (!wacom->remote_group[index].name) return -ENOMEM; - snprintf(buf, WAC_REMOTE_SERIAL_MAX_STRLEN, "%d", serial); - wacom->remote_group[index].name = buf; error = sysfs_create_group(wacom->remote_dir, &wacom->remote_group[index]); if (error) { hid_err(wacom->hdev, "cannot create sysfs group err: %d\n", error); - kobject_put(wacom->remote_dir); return error; } @@ -1271,7 +1268,8 @@ void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) if (wacom->remote_group[i].name) { sysfs_remove_group(wacom->remote_dir, &wacom->remote_group[i]); - kfree(wacom->remote_group[i].name); + devm_kfree(&wacom->hdev->dev, + (char *)wacom->remote_group[i].name); wacom->remote_group[i].name = NULL; } }