On Tue, 13 Nov 2012, Lan Tianyu wrote:
> This patch is to create driver/usb/core/port.c and move usb port related
> code into it.
> @@ -1237,57 +1227,12 @@ static int hub_post_reset(struct usb_interface *intf)
> return 0;
> }
>
> -static void usb_port_device_release(struct device *dev)
> -{
> - struct usb_port *port_dev = to_usb_port(dev);
> -
> - usb_acpi_unregister_power_resources(dev);
> - kfree(port_dev);
> -}
> -
> static void usb_hub_remove_port_device(struct usb_hub *hub,
> int port1)
> {
> device_unregister(&hub->ports[port1 - 1]->dev);
> }
I'd like to see this routine moved into the new file too.
> @@ -1548,10 +1493,24 @@ static int hub_configure(struct usb_hub *hub,
> if (hub->has_indicators && blinkenlights)
> hub->indicator [0] = INDICATOR_CYCLE;
>
> - for (i = 0; i < hdev->maxchild; i++)
> - if (usb_hub_create_port_device(hub, i + 1) < 0)
> + for (i = 0; i < hdev->maxchild; i++) {
> + struct usb_port *port_dev = NULL;
> +
> + port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
> + if (!port_dev) {
> + dev_err(hub->intfdev,
> + "couldn't create port%d device due to lack
> mem.\n", i + 1);
> + continue;
> + }
> +
> + hub->ports[i] = port_dev;
> +
> + if (usb_hub_create_port_device(hub->intfdev, i + 1, port_dev) <
> 0) {
> dev_err(hub->intfdev,
> "couldn't create port%d device.\n", i + 1);
> + hub->ports[i] = NULL;
> + }
> + }
As well as most of this code.
> --- a/include/linux/usb.h
> +++ b/include/linux/usb.h
> @@ -572,6 +572,22 @@ struct usb_device {
> };
> #define to_usb_device(d) container_of(d, struct usb_device, dev)
>
> +/**
> + * struct usb port - kernel's representation of a usb port
> + * @child: usb device attatched to the port
> + * @dev: generic device interface
> + * @port_owner: port's owner
> + * @connect_type: port's connect type
> + */
> +struct usb_port {
> + struct usb_device *child;
> + struct device dev;
> + struct dev_state *port_owner;
> + enum usb_port_connect_type connect_type;
> +};
> +#define to_usb_port(_dev) \
> + container_of(_dev, struct usb_port, dev)
> +
This does not belong here; it belongs in your new port.c file. Maybe in
drivers/usb/core/usb.h if necessary.
The idea is that include/linux/usb.h has only stuff that a general USB
driver needs to worry about. Details about internal workings of the
core or the hub driver don't belong there.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html