[PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper
Maxime Ripard
maxime at cerno.tech
Thu Oct 27 09:37:30 UTC 2022
Hi Mateusz,
On Thu, Oct 27, 2022 at 12:02:24AM +0200, Mateusz Kwiatkowski wrote:
> First of all, nice idea with the helper function that can be reused by
> different drivers. This is neat!
Yeah, it looked to me that given how complex it is, we don't want to
duplicate it in each and every driver.
> But looking at this function, it feels a bit overcomplicated. You're
> creating the two modes,
If reported as supported by the connector, yes.
> then checking which one is the default, then set the preferred one and
> possibly reorder them. Maybe it can be simplified somehow?
Possibly, but I couldn't find something simpler. We should only expose
the modes that the driver reports as supported, so we can have 0-2
modes. Then the preferred flag needs to be set on the default one like
you suggested.
But also, EDIDs define the preferred mode as either the mode with the
flag set or the first mode listed. So a lot of program just use the
heuristic to just pick the first mode listed.
So it might be that I'm too careful, but it still seems useful to me.
> Although when I tried to refactor it myself, I ended up with something that's
> not better at all. Maybe it needs to be complicated, after all :(
Yeah, that was my conclusion too :/
> Anyway, the current version seems to have a couple of bugs:
>
> > + if (tv_mode_supported(connector, DRM_MODE_TV_MODE_PAL) ||
> > + tv_mode_supported(connector, DRM_MODE_TV_MODE_PAL_N) ||
> > + tv_mode_supported(connector, DRM_MODE_TV_MODE_SECAM)) {
> > + mode = drm_mode_analog_pal_576i(connector->dev);
> > + if (!mode)
> > + return 0;
> > +
> > + tv_modes[count++] = mode;
> > + }
>
> If the 480i mode has been created properly, but there's an error creating the
> 576i one (we enter the if (!mode) clause), the 480i mode will leak.
>
> > + if (count == 1) {
>
> You're handling the count == 1 case specially, but if count == 0, the rest of
> the code will assume that two modes exist and probably segfault in the process.
>
> > + ret = drm_object_property_get_default_value(&connector->base,
> > + dev->mode_config.tv_mode_property,
> > + &default_mode);
> > + if (ret)
> > + return 0;
> > +
> > + if (cmdline->tv_mode_specified)
> > + default_mode = cmdline->tv_mode;
>
> In case of an error (ret != 0), the modes created so far in the tv_modes array
> will leak.
Thanks for the review, I'll fix these bugs
> Also, I wonder if maybe the if (cmdline->tv_mode_specified) clause should go
> first? If we're going to use the default from cmdline, there's no point in even
> querying the property default value.
Maybe, I don't know. I find the flow of the code more readable that way,
but if you disagree I'll change it.
Maxime
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20221027/3429e8f6/attachment.sig>
More information about the dri-devel
mailing list