Skip to contentSkip to conversation

drm: avoid uninitialized timestamp use in wait_vblank

PATCH RESEND In review Arnd Bergmann 2 participants 2 messages Feb 25, 2016 – Feb 26, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 drm: avoid uninitialized timestamp use in wait_vblank

gcc warns about the timestamp in drm_wait_vblank being possibly used without an initialization:

drivers/gpu/drm/drm_irq.c: In function 'drm_wait_vblank':
drivers/gpu/drm/drm_irq.c:1755:28: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
vblwait->reply.tval_usec = now.tv_usec;
drivers/gpu/drm/drm_irq.c:1754:27: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
vblwait->reply.tval_sec = now.tv_sec;

This can happen if drm_vblank_count_and_time() returns 0 in its error path. To sanitize the error case, I'm changing that function to return a zero timestamp when it fails.

Fixes e6ae8687a87b ("drm: idiot-proof vblank")
---
 drivers/gpu/drm/drm_irq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

I'm going through the maybe-unused warnings in randconfig builds, this one is apparently not a false positive, although it only happens if something else has already gone wrong.

Originally sent out on Jan 13, but I received no reply, so resending now.

drivers/gpu/drm/drm_irq.c +3 -1
index 881c5a6c180c..6f41ddfbe061 100644
@@ -997,8 +997,10 @@ u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
 	int count = DRM_TIMESTAMP_MAXRETRIES;
 	u32 cur_vblank;
 
-	if (WARN_ON(pipe >= dev->num_crtcs))
+	if (WARN_ON(pipe >= dev->num_crtcs)) {
+		*vblanktime = (struct timeval) { 0 };
 		return 0;
+	}
 
 	/*
 	 * Vblank timestamps are read lockless. To ensure consistency the vblank
Signature · 1 line
2.7.0
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 30 lines · Arnd Bergmann

gcc warns about the timestamp in drm_wait_vblank being possibly used without an initialization:

drivers/gpu/drm/drm_irq.c: In function 'drm_wait_vblank':
drivers/gpu/drm/drm_irq.c:1755:28: warning: 'now.tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized]
vblwait->reply.tval_usec = now.tv_usec;
drivers/gpu/drm/drm_irq.c:1754:27: warning: 'now.tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized]
vblwait->reply.tval_sec = now.tv_sec;

This can happen if drm_vblank_count_and_time() returns 0 in its error path. To sanitize the error case, I'm changing that function to return a zero timestamp when it fails.

Fixes e6ae8687a87b ("drm: idiot-proof vblank")
---
 drivers/gpu/drm/drm_irq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

I'm going through the maybe-unused warnings in randconfig builds, this one is apparently not a false positive, although it only happens if something else has already gone wrong.

Originally sent out on Jan 13, but I received no reply, so resending now.

drivers/gpu/drm/drm_irq.c +0 -0
index 881c5a6c180c..6f41ddfbe061 100644

drivers/gpu/drm/drm_irq.c u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe, · line 1001

Quoted 6 lines
drivers/gpu/drm/drm_irq.c +2 -1
@@ -997,8 +997,10 @@ u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe,
        int count = DRM_TIMESTAMP_MAXRETRIES;
        u32 cur_vblank;
 
-       if (WARN_ON(pipe >= dev->num_crtcs))
+       if (WARN_ON(pipe >= dev->num_crtcs)) {
+               *vblanktime = (struct timeval) { 0 };

The '0' is redundant. Anyway, this is:

(CC: Daniel, for drm-misc)

Thanks
David

Quoted 12 lines
drivers/gpu/drm/drm_irq.c +1 -1
                return 0;
+       }
 
        /*
         * Vblank timestamps are read lockless. To ensure consistency the vblank
--

2.7.0

_______________________________________________
dri-devel mailing list
dri-devel at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel