Re: [PATCH v7 3/9] drm/display: Add Type-C switch helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 05, 2023 at 09:24:51PM +0800, Pin-yen Lin wrote:
> Add helpers to register and unregister Type-C "switches" for bridges
> capable of switching their output between two downstream devices.
> 
> The helper registers USB Type-C mode switches when the "mode-switch"
> and the "data-lanes" properties are available in Device Tree.

...

> +	port_data->typec_mux = typec_mux_register(dev, &mux_desc);
> +	if (IS_ERR(port_data->typec_mux)) {
> +		ret = PTR_ERR(port_data->typec_mux);
> +		dev_err(dev, "Mode switch register for port %d failed: %d\n",
> +			port_num, ret);
> +	}
> +
> +	return ret;

...

> +	struct device_node *sw;

> +	int ret = 0;

It's easy to break things if you squeeze more code in the future in this
function, so I recommend to split assignment to be closer to its first user
(see below).

> +	for_each_child_of_node(port, sw) {
> +		if (of_property_read_bool(sw, "mode-switch"))
> +			switch_desc->num_typec_switches++;
> +	}
> +
> +	if (!switch_desc->num_typec_switches) {
> +		dev_warn(dev, "No Type-C switches node found\n");

> +		return ret;

return 0;

> +	}
> +
> +	switch_desc->typec_ports = devm_kcalloc(
> +		dev, switch_desc->num_typec_switches,
> +		sizeof(struct drm_dp_typec_port_data), GFP_KERNEL);
> +
> +	if (!switch_desc->typec_ports)
> +		return -ENOMEM;

> +	/* Register switches for each connector. */
> +	for_each_child_of_node(port, sw) {
> +		if (!of_property_read_bool(sw, "mode-switch"))
> +			continue;
> +		ret = drm_dp_register_mode_switch(dev, sw, switch_desc, data, mux_set);
> +		if (ret) {
> +			dev_err(dev, "Failed to register mode switch: %d\n", ret);
> +			of_node_put(sw);
> +			break;
> +		}
> +	}

> +	if (ret)
> +		drm_dp_unregister_typec_switches(switch_desc);
> +
> +	return ret;

Why not adding a goto label?

		ret = drm_dp_register_mode_switch(dev, sw, switch_desc, data, mux_set);
		if (ret)
			goto err_unregister_typec_switches;

	return 0;

err_unregister_typec_switches:
	of_node_put(sw);
	drm_dp_unregister_typec_switches(switch_desc);
	dev_err(dev, "Failed to register mode switch: %d\n", ret);
	return ret;

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux