lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 13 Mar 2010 23:13:55 +0100
From:	Bruno Prémont <bonbons@...ux-vserver.org>
To:	Alan Stern <stern@...land.harvard.edu>,
	Jiri Kosina <jkosina@...e.cz>
Cc:	<linux-input@...r.kernel.org>, <linux-usb@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>,
	"Rick L. Vinyard Jr." <rvinyard@...nmsu.edu>,
	Nicu Pavel <npavel@...ner.com>
Subject: [PATCH] hid: Register debugfs entries before adding device

On Sat, 13 March 2010 Alan Stern <stern@...land.harvard.edu> wrote:
> 
> If the device_add() fails, you should undo the hid_debug_register() 
> 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 debugfs
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 device
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émont <bonbons@...ux-vserver.org>
Cc: Alan Stern <stern@...land.harvard.edu>
---


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));
 
+	hid_debug_register(hdev, dev_name(&hdev->dev));
 	ret = device_add(&hdev->dev);
 	if (!ret)
 		hdev->status |= HID_STAT_ADDED;
-
-	hid_debug_register(hdev, dev_name(&hdev->dev));
+	else
+		hid_debug_unregister(hdev);
 
 	return ret;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ