Re: [PATCH v2 6/6] usb: typec: Link all ports during connector registration

From: Greg Kroah-Hartman
Date: Mon Mar 29 2021 - 05:06:39 EST


On Mon, Mar 29, 2021 at 11:44:26AM +0300, Heikki Krogerus wrote:
> +#ifdef CONFIG_USB

This 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?)

> +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.

thanks,

greg k-h