From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: Re: [PATCH 23/24] drm/vblank: reduce pipe checks
Date: Mon, 10 Nov 2025 19:45:57 +0200 [thread overview]
Message-ID: <aRIk1Q6ivG6temIY@intel.com> (raw)
In-Reply-To: <472777431de3c0f8a8d43e2ee7a55b3a170d138c.1762791343.git.jani.nikula@intel.com>
On Mon, Nov 10, 2025 at 06:17:41PM +0200, Jani Nikula wrote:
> Now that drm_vblank_crtc() is the only place that indexes dev->vblank[],
> and its usage has reduced considerably, add the primary pipe
> out-of-bounds check there, and return NULL. Expect callers to check it
> and act accordingly.
>
> In drm_crtc_vblank_crtc(), warn and return NULL, and let it go boom. If
> the crtc->pipe is out of bounds, it's a driver error that needs to be
> fixed.
>
> Remove superfluous pipe checks all around.
>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
> drivers/gpu/drm/drm_vblank.c | 36 +++++++++++++++---------------------
> 1 file changed, 15 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 44fb8d225485..7829e64e42b4 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -177,13 +177,22 @@ MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
> static struct drm_vblank_crtc *
> drm_vblank_crtc(struct drm_device *dev, unsigned int pipe)
> {
> + if (pipe >= dev->num_crtcs)
> + return NULL;
> +
> return &dev->vblank[pipe];
> }
>
> struct drm_vblank_crtc *
> drm_crtc_vblank_crtc(struct drm_crtc *crtc)
> {
> - return drm_vblank_crtc(crtc->dev, drm_crtc_index(crtc));
> + struct drm_vblank_crtc *vblank;
> +
> + vblank = drm_vblank_crtc(crtc->dev, drm_crtc_index(crtc));
> + if (drm_WARN_ON(crtc->dev, !vblank))
> + return NULL;
> +
> + return vblank;
> }
> EXPORT_SYMBOL(drm_crtc_vblank_crtc);
>
> @@ -631,7 +640,6 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
> const struct drm_display_mode *mode)
> {
> struct drm_device *dev = crtc->dev;
> - unsigned int pipe = drm_crtc_index(crtc);
> struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
> int linedur_ns = 0, framedur_ns = 0;
> int dotclock = mode->crtc_clock;
> @@ -639,9 +647,6 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
> if (!drm_dev_has_vblank(dev))
> return;
I belive this at least gets called from the atomic helpers even
for drivers that don't have vblank support. In which case the
drm_crtc_vblank_crtc() call would have to be done after the
drm_dev_has_vblank() check or else you'll get spurious WARNs.
I don't remember if there are other cases like this as well.
>
> - if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
> - return;
> -
> /* Valid dotclock? */
> if (dotclock > 0) {
> int frame_size = mode->crtc_htotal * mode->crtc_vtotal;
> @@ -724,11 +729,6 @@ drm_crtc_vblank_helper_get_vblank_timestamp_internal(
> int vpos, hpos, i;
> int delta_ns, duration_ns;
>
> - if (pipe >= dev->num_crtcs) {
> - drm_err(dev, "Invalid crtc %u\n", pipe);
> - return false;
> - }
> -
> /* Scanout position query not supported? Should not happen. */
> if (!get_scanout_position) {
> drm_err(dev, "Called from CRTC w/o get_scanout_position()!?\n");
> @@ -1339,9 +1339,6 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc)
> ktime_t now;
> u64 seq;
>
> - if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
> - return;
> -
> /*
> * Grab event_lock early to prevent vblank work from being scheduled
> * while we're in the middle of shutting down vblank interrupts
> @@ -1480,9 +1477,6 @@ void drm_crtc_vblank_on_config(struct drm_crtc *crtc,
> unsigned int pipe = drm_crtc_index(crtc);
> struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
>
> - if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
> - return;
> -
> spin_lock_irq(&dev->vbl_lock);
> drm_dbg_vbl(dev, "crtc %d, vblank enabled %d, inmodeset %d\n",
> pipe, vblank->enabled, vblank->inmodeset);
> @@ -1764,10 +1758,9 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
> pipe = pipe_index;
> }
>
> - if (pipe >= dev->num_crtcs)
> - return -EINVAL;
> -
> vblank = drm_vblank_crtc(dev, pipe);
> + if (!vblank)
> + return -EINVAL;
>
> /* If the counter is currently enabled and accurate, short-circuit
> * queries to return the cached timestamp of the last vblank.
> @@ -1902,14 +1895,15 @@ static void drm_handle_vblank_events(struct drm_vblank_crtc *vblank)
> */
> bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe)
> {
> - struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, pipe);
> + struct drm_vblank_crtc *vblank;
> unsigned long irqflags;
> bool disable_irq;
>
> if (drm_WARN_ON_ONCE(dev, !drm_dev_has_vblank(dev)))
> return false;
>
> - if (drm_WARN_ON(dev, pipe >= dev->num_crtcs))
> + vblank = drm_vblank_crtc(dev, pipe);
> + if (drm_WARN_ON(dev, !vblank))
> return false;
>
> spin_lock_irqsave(&dev->event_lock, irqflags);
> --
> 2.47.3
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2025-11-10 17:46 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 16:17 [PATCH 00/24] drm/vblank: refactoring and cleanups Jani Nikula
2025-11-10 16:17 ` [PATCH 01/24] drm/vblank: Unexport drm_wait_one_vblank() Jani Nikula
2025-11-11 8:14 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 02/24] drm/vblank: remove drm_wait_one_vblank() completely Jani Nikula
2025-11-11 8:17 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 03/24] drm/vblank: remove superfluous pipe check Jani Nikula
2025-11-11 8:18 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 04/24] drm/vblank: add return value to drm_crtc_wait_one_vblank() Jani Nikula
2025-11-10 16:17 ` [PATCH 05/24] drm/vblank: use the drm_vblank_crtc() and drm_crtc_vblank_crtc() helpers more Jani Nikula
2025-11-11 8:23 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 06/24] drm/vblank: prefer drm_crtc_vblank_crtc() over drm_vblank_crtc() Jani Nikula
2025-11-11 8:26 ` Thomas Zimmermann
2025-11-11 8:43 ` Jani Nikula
2025-11-11 16:00 ` Ville Syrjälä
2025-11-12 8:26 ` Jani Nikula
2025-11-12 11:56 ` Ville Syrjälä
2025-11-12 15:50 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 07/24] drm/vblank: pass vlank to drm_vblank_get()/_put()/_count() Jani Nikula
2025-11-11 8:32 ` Thomas Zimmermann
2025-11-11 8:53 ` Jani Nikula
2025-11-11 9:04 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 08/24] drm/vblank: pass vblank to drm_update_vblank_count() Jani Nikula
2025-11-12 15:54 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 09/24] drm/vblank: pass vblank to drm_handle_vblank_events() Jani Nikula
2025-11-12 15:56 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 10/24] drm/vblank: use the vblank based interfaces more Jani Nikula
2025-11-12 15:56 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 11/24] drm/vblank: pass vblank to drm_queue_vblank_event() Jani Nikula
2025-11-12 15:57 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 12/24] drm/vblank: pass vblank to drm_wait_vblank_reply() Jani Nikula
2025-11-12 16:01 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 13/24] drm/vblank: pass vblank to drm_vblank_count_and_time() Jani Nikula
2025-11-11 6:52 ` kernel test robot
2025-11-12 16:03 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 14/24] drm/vblank: pass vblank to drm_reset_vblank_timestamp() Jani Nikula
2025-11-12 16:07 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 15/24] drm/vblank: pass vblank to store_vblank() Jani Nikula
2025-11-12 16:08 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 16/24] drm/vblank: pass vblank to drm_vblank_enable() Jani Nikula
2025-11-12 16:08 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 17/24] drm/vblank: merge drm_vblank_restore() into drm_crtc_vblank_restore() Jani Nikula
2025-11-12 16:10 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 18/24] drm/vblank: add drm_crtc_from_vblank() helper Jani Nikula
2025-11-12 16:38 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 19/24] drm/vblank: pass vblank to __get_vblank_counter() and drm_max_vblank_count() Jani Nikula
2025-11-12 16:40 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 20/24] drm/vblank: pass vblank to __{enable,disable}_vblank() Jani Nikula
2025-11-12 16:41 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 21/24] drm/vblank: pass vblank to drm_get_last_vbltimestamp() Jani Nikula
2025-11-12 16:44 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 22/24] drm/vblank: pass vblank to drm_vblank_disable_and_save(), make static Jani Nikula
2025-11-12 16:46 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 23/24] drm/vblank: reduce pipe checks Jani Nikula
2025-11-10 17:45 ` Ville Syrjälä [this message]
2025-11-11 8:56 ` Jani Nikula
2025-11-12 16:54 ` Thomas Zimmermann
2025-11-10 16:17 ` [PATCH 24/24] drm/vblank: clean up debug logging Jani Nikula
2025-11-13 14:05 ` Thomas Zimmermann
2025-11-10 17:12 ` ✗ CI.KUnit: failure for drm/vblank: refactoring and cleanups Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aRIk1Q6ivG6temIY@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).