lkml.org 
[lkml]   [2023]   [Jan]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v7 3/9] drm/display: Add Type-C switch helpers
Hi Andy,

Thanks for the review.

On Thu, Jan 5, 2023 at 11:41 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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;

Thanks for the suggestion. I'll update this in v8.
>
> > + }
> > +
> > + 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?

I didn't know that goto label is preferred even when there are no
duplicated code blocks in the function.

I'll update this accordingly in v8.
>
> 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
>
>
Best regards,
Pin-yen

\
 
 \ /
  Last update: 2023-03-26 23:31    [W:0.107 / U:1.620 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site