Re: [PATCH v2 6/6] usb: typec: Link all ports during connector registration
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Date: 2021-03-29 09:18:36
Also in:
lkml
On Mon, Mar 29, 2021 at 10:48:19AM +0200, Greg Kroah-Hartman wrote:
On Mon, Mar 29, 2021 at 11:44:26AM +0300, Heikki Krogerus wrote:quoted
+#ifdef CONFIG_USBThis feels odd in a file under drivers/usb/ is it still relevant? Will this code get built for non-USB systems (i.e. gadget only?)
Yes, later. The typec connector class can not depend on CONFIG_USB for sure.
quoted
+static int each_port(struct device *port, void *connector) +{ + struct port_node *node; + int ret; + + node = create_port_node(port); + if (IS_ERR(node)) + return PTR_ERR(node); + + if (!connector_match(connector, node)) { + remove_port_node(node); + return 0; + } + + ret = link_port(to_typec_port(connector), node); + if (ret) { + remove_port_node(node->pld); + return ret; + } + + get_device(connector); + + return 0; +} +#endif + +int typec_link_ports(struct typec_port *con) +{ + int ret = 0; + + con->pld = get_pld(&con->dev); + if (!con->pld) + return 0; + +#ifdef CONFIG_USB + ret = usb_for_each_port(&con->dev, each_port); + if (ret) + typec_unlink_ports(con);If you have proper #ifdef for CONFIG_USB in the .h file, then there's no need for the #ifdef in the .c file.
We could do that now, but we will have to move the ifdef back to the C file the moment we add support for Thunderbolt ports and/or DisplayPorts. I could make a stub for the usb_for_each_port() function in case CONFIG_USB is not enable. Would that work? thanks, -- heikki