[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221027093730.tb4oaissdapf6ifr@houat>
Date: Thu, 27 Oct 2022 11:37:30 +0200
From: Maxime Ripard <maxime@...no.tech>
To: Mateusz Kwiatkowski <kfyatek@...il.com>
Cc: Karol Herbst <kherbst@...hat.com>, Emma Anholt <emma@...olt.net>,
Ben Skeggs <bskeggs@...hat.com>, Chen-Yu Tsai <wens@...e.org>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Daniel Vetter <daniel@...ll.ch>,
Thomas Zimmermann <tzimmermann@...e.de>,
Tvrtko Ursulin <tvrtko.ursulin@...ux.intel.com>,
Samuel Holland <samuel@...lland.org>,
Jernej Skrabec <jernej.skrabec@...il.com>,
David Airlie <airlied@...ux.ie>,
Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
Lyude Paul <lyude@...hat.com>, linux-sunxi@...ts.linux.dev,
intel-gfx@...ts.freedesktop.org,
Phil Elwell <phil@...pberrypi.com>,
linux-arm-kernel@...ts.infradead.org,
nouveau@...ts.freedesktop.org, Hans de Goede <hdegoede@...hat.com>,
Dom Cobley <dom@...pberrypi.com>,
dri-devel@...ts.freedesktop.org,
Dave Stevenson <dave.stevenson@...pberrypi.com>,
linux-kernel@...r.kernel.org,
Noralf Trønnes <noralf@...nnes.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>
Subject: Re: [PATCH v6 16/23] drm/probe-helper: Provide a TV get_modes helper
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
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists