From patchwork Wed Jan 13 20:26:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 8027931 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4532A9F32E for ; Wed, 13 Jan 2016 20:27:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CA8A2051A for ; Wed, 13 Jan 2016 20:27:05 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8FB55204A9 for ; Wed, 13 Jan 2016 20:27:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9421A6E714; Wed, 13 Jan 2016 12:27:03 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B56F6E714 for ; Wed, 13 Jan 2016 12:27:01 -0800 (PST) Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue001) with ESMTPSA (Nemesis) id 0Lbm9E-1Zrmlj01RM-00jI6T; Wed, 13 Jan 2016 21:26:59 +0100 From: Arnd Bergmann To: David Airlie Subject: [PATCH] drm: avoid uninitialized timestamp use in wait_vblank Date: Wed, 13 Jan 2016 21:26:55 +0100 Message-ID: <4063054.9IPA0UdbYa@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 X-Provags-ID: V03:K0:icqs5mnr71OF7Xd5h/aHiJeOZjDyu5EXzp++MMFGVYGOXtcfs9k eOqDOdACxIJQJPUpP7t/h2yosiWMDb2MxFgYlvDOQiQuqz8TLtJT3mb0TWIHR+Fuiu/SeOT 3K7rkYUlr34xe2yNWg0pluupz7rZ2r8iFeKHriIxTEYT7QmPvcKGuoRrI704PHLHKzOdR1p nCj7BaPiYTPJC6t+SaWuA== X-UI-Out-Filterresults: notjunk:1; V01:K0:zkXibWA+0HQ=:o2dJ0OPA3Cc8x1tXO4QGr6 vxunzR+5M1BMXqN+rHvaXsR4Hn608EO2uPgOTkGrUxpenoAktUw6EuYL/5EmpuIl5HnLPrImA pwtt6OQYJA1n/DhIP2nRVTyMOYM8M0463HcxTI5gEq0wTWMx8LLvyYAU/LITk1NZDebzXiygZ Q2Uo9ITyaATis3YD4M9EQhYQYXKmjvJIZkryrcA8O1poKuT9/hTG6YCy+RFCJWmQv1DUuOeBU H+Nq1qNB8h/tk4O0zcOb0ZuXwjAx9p/R0LY/H8qk0XCJi0YA1vZOOz4ELzdtBi68EyGe8gxHn JmAC7uK7FYbE3OZBPQOGSGxbJm3MDH1VhW8LpiOdIxRJdq1WwtvCFrqjhPbSj9LQnCRw57IiE MXaH8ZiF6FjMadZsWRWVCUK2skWlKRIgQJSEWtz/Mp+wF1V/0zTrIphZPo1HPmDHiOTWpBmEZ vw94b6hAwIIK7wRLZlbki/eQlfM21Dd01aXZVjHR51EZlbGPEQxWMjknlOMp7NngyjB/h76Ah TzYq9dIX+o9UulizK3ZmULC/GC8TKTphjPWjtxcKavvDkIsZ0HXWWevQyvu3GpLTQvuLVD2qA pBgu9f/Gfx4DNQTLfV9jTK1OD/NsrBog0Dd3v7FjONBr+iFx+1qT36GbOsFpQZ6d/bTO2QAdg 8cxZJEkWmqoOs/XH1qqxeKCquLPXZKhm4Ab0E1/WxwEHRiOeBI74JJm+vZf8MBXfBX40lFiq4 t8wUbzr2AT1vdx37 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Arnd Bergmann Fixes: e6ae8687a87b ("drm: idiot-proof vblank") --- 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. diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index d12a4efa651b..d32ff169fdb8 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -939,8 +939,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