From patchwork Thu Feb 25 21:09:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102679 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp373827lbc; Thu, 25 Feb 2016 13:10:10 -0800 (PST) X-Received: by 10.66.124.226 with SMTP id ml2mr65517172pab.90.1456434610157; Thu, 25 Feb 2016 13:10:10 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTP id q21si14686358pfi.231.2016.02.25.13.10.09; Thu, 25 Feb 2016 13:10:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 230476E96B; Thu, 25 Feb 2016 21:10:09 +0000 (UTC) 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 6B0AD6E96B for ; Thu, 25 Feb 2016 21:10:07 +0000 (UTC) Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue001) with ESMTPA (Nemesis) id 0LvtTJ-1Zrunh3bdF-017oxO; Thu, 25 Feb 2016 22:10:04 +0100 From: Arnd Bergmann To: David Airlie Subject: [PATCH, RESEND] drm: avoid uninitialized timestamp use in wait_vblank Date: Thu, 25 Feb 2016 22:09:57 +0100 Message-Id: <1456434600-4185759-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:ac8m0o9+mkodd1xNHhJ7GnGZAwpEdwlIPM8qejByuNgSuZV550x LwkmaWxsplBdcKtVzcxOs4k6wLKLGPNWlbawxkpn89zwvUx22T7Md0cUxLPzU0Ln+f8hmxv fcbgM+lzpm3AeAlNfhhruRj3lQS0mQblC66dqiECtv00QgmRrn9w9uAealejhETji/3Rvx+ ydM/CVxrsd+4sYBFozZSQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:JDvzBn7PoHQ=:8dQAlgO+YmLjEmi2IONaOm Eufq3dR8xa0cfPf8xUKI00QSZdbrPgtJMlMTA1qCkUmxC16l5MSOP1Bb9Q30nKcC2PabAoNky XZve6/Tq72unOBQUPd1bwrMx0/DVOoh43RGL2ZB3OQmHTiRib6zMsztbIbqGgZZY4D8yR+v7p caHNs6rg+Udht5rGkm0W0wbW4/Z06XRcQ76aDFgJhfXJSmZn2gXb0ldnKsQ2voEHUwBGiya2r yLGAm1+o3GwAAdCKRMMifTLNVeihkmYzsxwQTcdtCOyk5OMbDaexrk+AGINaROHOL/4cdku54 QU+BtzyMsWjvuyIfyGNpF0utMyBTDrjHczDHs76AiSAozgPXaBa/pDt2tq5Z81e7FgoJPm+nv p/D1UYSN4dJli8J8iEXFk+yEf9DcZGEd0BzLE0ceRMq09/TcsucC8963J4PiVyMo2ZehiwJIP zq1gveVS3ar7MmlKq1Oq3ZOqLAztozvMqZFLSvFtuf9XNTM5jTur2n8NTVoW+9mAnIa+il0MV c1QJ6p6BxmlkkgoTopi9LNPmHG2YKb76Y09wiVMfx/Jdd40A2n+4KrcYD3ralEPT8aelw7d70 DPuTASmmC1jc7Ttk1ykzT+HdSN1XZ0ffdrKwBylKCWhOeoROXq4pGJ/DEgQjvkVDywkjFgD++ WOSPEa1ub2xp6DfA2/IC8cJrieRZTDw3atePPx8aPgOeftfQxm6Z/RLISiRwjuTnteGs= Cc: dri-devel@lists.freedesktop.org, Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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") --- 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. diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 881c5a6c180c..6f41ddfbe061 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -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