From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruno =?UTF-8?B?UHLDqW1vbnQ=?= Subject: [PATCH] hid: Register debugfs entries before adding device Date: Sat, 13 Mar 2010 23:13:55 +0100 Message-ID: <20100313231355.61c75c30@neptune.home> References: <20100313203953.0f3436b3@neptune.home> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from legolas.restena.lu ([158.64.1.34]:40444 "EHLO legolas.restena.lu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754530Ab0CMWOg convert rfc822-to-8bit (ORCPT ); Sat, 13 Mar 2010 17:14:36 -0500 In-Reply-To: Sender: linux-input-owner@vger.kernel.org List-Id: linux-input@vger.kernel.org To: Alan Stern , Jiri Kosina Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Rick L. Vinyard Jr." , Nicu Pavel On Sat, 13 March 2010 Alan Stern wrote: >=20 > If the device_add() fails, you should undo the hid_debug_register()=20 > call. Well I was wondering why hid_debug_register() was called no matter what device_add() returned but didn't dig around what happened when hid_add_device() would return an error. Looking a few lines further, hid_remove_device() just unregisters debug= fs entries when status has HID_STAT_ADDED so it definitely makes sense to do the proper cleanup (and hid_remove_device() is the only once calling hid_debug_unregister()) So patch for both below: Register debugfs entries before calling device_add() so debugfs entries are already present when HID driver's probe function gets called on dev= ice hotplug. Also undo debugfs entry registration if device_add() fails so status HID_STAT_ADDED and debugfs registration status remain consistent and we don't leak the debugfs entries. Signed-off-by: Bruno Pr=C3=A9mont Cc: Alan Stern --- diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index eabe5f8..709b4d0 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1759,11 +1759,12 @@ int hid_add_device(struct hid_device *hdev) dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus, hdev->vendor, hdev->product, atomic_inc_return(&id)); =20 + hid_debug_register(hdev, dev_name(&hdev->dev)); ret =3D device_add(&hdev->dev); if (!ret) hdev->status |=3D HID_STAT_ADDED; - - hid_debug_register(hdev, dev_name(&hdev->dev)); + else + hid_debug_unregister(hdev); =20 return ret; } -- To unsubscribe from this list: send the line "unsubscribe linux-input" = in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html