On 2012年06月19日 23:51, Alan Stern wrote:
On Tue, 19 Jun 2012, Lan Tianyu wrote:
This patch is to make usb port a real device under usb hub interface.
+static int usb_hub_create_port_device(struct usb_hub *hub,
+ int port1)
+{
+ struct usb_port *port_dev =&hub->ports[port1 - 1];
Now that these things contain a struct device, they can't be allocated
in an array. Each usb_port structure must be allocated dynamically;
you'll have to store a pointer to it in hub->ports[port1 - 1].
Ok.
+ int retval;
+
+ port_dev->udev = hub->hdev;
+ port_dev->dev.parent = hub->intfdev;
+ port_dev->dev.type =&usb_port_device_type;
Where's the "release" callback?
+ dev_set_name(&port_dev->dev, "port%d", port1);
+
+ retval = device_register(&port_dev->dev);
+ if (retval)
+ goto error_register;
+
+error_register:
+ put_device(&port_dev->dev);
+ return retval;
This doesn't look right. What does the "goto" statement do?
Also, don't you want to create the attributes when the port device is
registered?
Yeah. I will create attribute "control" and "state" in the later
patch since this patch is just to make port a real device. Do you
have suggestion to add some other attributes?
@@ -1528,7 +1571,7 @@ static void hub_disconnect(struct usb_interface *intf)
usb_free_urb(hub->urb);
kfree(hdev->children);
- kfree(hub->port_owners);
+ kfree(hub->ports);
No, you can't just deallocate a bunch of device structures. There may
still be outstanding references to them. You have to use a release
routine.
I will add the release callback and allocate/free struct usb_port separately.
--
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html