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

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

 



Hi Andy,

Thanks for the review.

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



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux