lkml.org 
[lkml]   [2010]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] hid: Register debugfs entries before adding device
On Sat, 13 Mar 2010, Bruno Prémont 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@linux-vserver.org>
> Cc: Alan Stern <stern@rowland.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;

Applied, thank you Bruno.

--
Jiri Kosina
SUSE Labs, Novell Inc.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2010-03-15 14:51    [W:0.054 / U:5.552 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site