From: Lan Tianyu <tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
sarah.a.sharp-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
mjg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 2/5] usb: move struct usb_device->children to struct usb_hub_port->child
Date: Thu, 29 Mar 2012 16:35:35 +0800 [thread overview]
Message-ID: <4F741ED7.8010105@intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1203281502450.1599-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
hi alan:
Great thanks for your such careful review.
On 2012年03月29日 03:13, Alan Stern wrote:
> On Wed, 28 Mar 2012, Lan Tianyu wrote:
>
>> Move child's pointer to the struct usb_hub_port since the child device
>> is directly associated with the port. Provide usb_get_hub_child_device()
>> to get child's pointer.
>
>> --- a/drivers/usb/core/devices.c
>> +++ b/drivers/usb/core/devices.c
>> @@ -590,7 +590,9 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
>>
>> /* Now look at all of this device's children. */
>> for (chix = 0; chix< usbdev->maxchild; chix++) {
>> - struct usb_device *childdev = usbdev->children[chix];
>> + struct usb_device *childdev;
>> + if (usb_get_hub_child_device(usbdev, chix + 1,&childdev)< 0)
>> + continue;
>>
>
> Whitespace issue: The blank line should come before the new executable
> statement, not after it.
>
>> @@ -1475,11 +1477,12 @@ bool usb_device_is_owned(struct usb_device *udev)
>>
>> static void recursively_mark_NOTATTACHED(struct usb_device *udev)
>> {
>> + struct usb_hub *hub = hdev_to_hub(udev);
>
> I'm not sure this is good. You are calling hdev_to_hub without knowing
> beforehand that udev really is a hub -- in fact, most of the time udev
> won't be a hub. The routine wasn't meant to be used that way. Have
> you checked that hdev_to_hub won't crash when the argument isn't a hub?
> What happens if the active configuration has no interfaces?
About this, I have an idea to add a check of hdev->maxchild. I have
verified that hdev->maxchild only is set in the hub_configure() and
hub_disconnect(). So we can identify whether the udev is a usb hub or
not through hdev->maxchild. Does this make sense?
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c70c170..d29a5dc 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -177,7 +177,7 @@ static inline char *portspeed(struct usb_hub *hub, int
portstatus)
/* Note that hdev or one of its children must be locked! */
static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
{
- if (!hdev || !hdev->actconfig)
+ if (!hdev || !hdev->actconfig || hdev->maxchild == 0)
return NULL;
return usb_get_intfdata(hdev->actconfig->interface[0]);
}
>> @@ -4147,3 +4151,15 @@ void usb_queue_reset_device(struct usb_interface *iface)
>> schedule_work(&iface->reset_ws);
>> }
>> EXPORT_SYMBOL_GPL(usb_queue_reset_device);
>> +
>> +int usb_get_hub_child_device(struct usb_device *hdev, int port1,
>> + struct usb_device **child)
>> +{
>> + struct usb_hub *hub = hdev_to_hub(hdev);
>> +
>> + if (port1> hdev->maxchild || port1< 1)
>> + return -EINVAL;
>> + *child = hub->port_data[port1 - 1].child;
>> + return 0;
>> +}
>
> This new routine is more complicated that it needs to be. You don't
> have to return an error code; none of the callers make use of it.
> Just return the child pointer, and return NULL if there's an error.
>
> Alan Stern
>
>
--
Best Regards
Tianyu Lan
linux kernel enabling team
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-03-29 8:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-28 6:49 [PATCH 0/5] usb/acpi: To bind usb hub ports with acpi when not attached usb devices Lan Tianyu
2012-03-28 6:49 ` [PATCH 1/5] usb: add struct usb_hub_port to store port related members Lan Tianyu
2012-03-28 18:54 ` Alan Stern
2012-03-28 6:49 ` [PATCH 2/5] usb: move struct usb_device->children to struct usb_hub_port->child Lan Tianyu
2012-03-28 19:13 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1203281502450.1599-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-03-29 8:35 ` Lan Tianyu [this message]
2012-03-29 14:50 ` Alan Stern
2012-03-28 6:49 ` [PATCH 3/5] usb: Add platform_data in the struct usb_hub_port Lan Tianyu
[not found] ` <1332917353-28123-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-03-28 6:49 ` [PATCH 4/5] usb/acpi: add the support of usb hub ports' acpi binding without attached devices Lan Tianyu
2012-03-28 19:31 ` Alan Stern
2012-03-28 6:49 ` [PATCH 5/5] usb/acpi: add usb check for the connect type of usb port Lan Tianyu
[not found] ` <1332917353-28123-6-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-03-28 19:40 ` Alan Stern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F741ED7.8010105@intel.com \
--to=tianyu.lan-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=lenb-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-acpi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mjg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=sarah.a.sharp-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox