From patchwork Fri Sep 30 16:19:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9358617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3C6F9600C8 for ; Fri, 30 Sep 2016 16:19:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CC332A0D6 for ; Fri, 30 Sep 2016 16:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2120E2A0DC; Fri, 30 Sep 2016 16:19:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DBB72A0D6 for ; Fri, 30 Sep 2016 16:19:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933749AbcI3QTe (ORCPT ); Fri, 30 Sep 2016 12:19:34 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:52143 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933082AbcI3QTe (ORCPT ); Fri, 30 Sep 2016 12:19:34 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue001) with ESMTPA (Nemesis) id 0MWKkb-1bSBAU3qRt-00XNrg; Fri, 30 Sep 2016 18:19:12 +0200 From: Arnd Bergmann To: Vinod Koul Cc: Arnd Bergmann , Dan Williams , Peter Ujfalusi , Tony Lindgren , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] edma: avoid uninitialized variable use Date: Fri, 30 Sep 2016 18:19:01 +0200 Message-Id: <20160930161909.120176-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:agwf/el96IZd84zAGZLPIdYAZjTumFtwe4xHfUkvqj5ON52Yube W/PNonP0XcwEY8hYSmP7+EZtcJYspcYTSkwk3RFPmQGWWMISc7w/NMHqqJ6kgidgD/zRkC6 9Sb3yYB7VGG/iS4zEl/QoF63vHnlH9zmDjb8CEvokX2TGDM7nttoYIWB1k5PP/jPldy7ZAO ai+WbcxuhqqORQAGayqQw== X-UI-Out-Filterresults: notjunk:1; V01:K0:JpX6YrQ4ML8=:hZtxf31LO3gczEpl+8O9Dh nM4GdUBxMCYILmQAAPzLh5Rtq8IFoQIiFPkctBhNIrU1tfC4tkoIYpyJyLOl/rapj59/ABcJW piTzQg7lo+x8oPFdxUWNSbE32NXC4sM+1vl/DDgCbcxFF3CCyjwI532yQTLkgn9kVw3WR5m5i yZEP4rceXgk5L4bWA+8BMnSYZs8UIwa9xLaO8Hi2wctXi1m6NEgbgNEiRK2MRehDOiUQTNJEb 2dHGn2dXoENyNm9g0lnaSGI6X9XUnCQFCQskq4mRq9dBOBgk5Xc3OxIs0Zy2Mcw0Eu8sBjWQ/ LA6OjLw4i9akNwWH01bxleLFxsi/Gyh1LS+URxtaW4AtwS6FafbHHjF5mCQhHKGpwIwlRIe/u EFhqy+UhOsqsEbY5rAJDbwjpVc1u/2Y8CuqUtQaQzDaBtjtUyChadFtFQjN+YTGJOMdupEp4d x2TxAR05PBnx+7WdOQCxNH0Qe9NhonAR8fDX70PeugKE99ckIM1+eVu4CLYtngm8fI4rQDfgF EwP8qLjRYe42IOcD4ZFfmbDofr5UJ5Rz+xvphK0VCAhppPV4u59n9iZa0PUlijUUk4dU4jMVX Fr419Xhdn6+DnLECFvxxDbN5QLnPuEp4iq8PC+MDT5hrHGonVRBtuz9g5udDb9HGK5RehWduA XO8SCSGffeZFvJ9t+Ypb/dS+WiyfQNUGkProiWVArXHPVdQnm17plrS4ls5GpJFUX6KE= Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If edma_read_slot() gets an invalid argument, it does not set a result, as found by "gcc -Wmaybe-uninitialized" drivers/dma/edma.c: In function 'dma_ccerr_handler': drivers/dma/edma.c:1499:21: error: 'p.a_b_cnt' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/dma/edma.c:1499:21: error: 'p.ccnt' may be used uninitialized in this function [-Werror=maybe-uninitialized] if (p.a_b_cnt == 0 && p.ccnt == 0) { If we change the function to return an error in this case, we can handle the failure more gracefully and treat this the same way as a null slot that we already catch. Signed-off-by: Arnd Bergmann --- drivers/dma/edma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c index 844e87b3bffc..e18a58068bca 100644 --- a/drivers/dma/edma.c +++ b/drivers/dma/edma.c @@ -465,13 +465,15 @@ static void edma_write_slot(struct edma_cc *ecc, unsigned slot, memcpy_toio(ecc->base + PARM_OFFSET(slot), param, PARM_SIZE); } -static void edma_read_slot(struct edma_cc *ecc, unsigned slot, +static int edma_read_slot(struct edma_cc *ecc, unsigned slot, struct edmacc_param *param) { slot = EDMA_CHAN_SLOT(slot); if (slot >= ecc->num_slots) - return; + return -EINVAL; memcpy_fromio(param, ecc->base + PARM_OFFSET(slot), PARM_SIZE); + + return 0; } /** @@ -1477,13 +1479,15 @@ static void edma_error_handler(struct edma_chan *echan) struct edma_cc *ecc = echan->ecc; struct device *dev = echan->vchan.chan.device->dev; struct edmacc_param p; + int err; if (!echan->edesc) return; spin_lock(&echan->vchan.lock); - edma_read_slot(ecc, echan->slot[0], &p); + err = edma_read_slot(ecc, echan->slot[0], &p); + /* * Issue later based on missed flag which will be sure * to happen as: @@ -1496,7 +1500,7 @@ static void edma_error_handler(struct edma_chan *echan) * lead to some nasty recursion when we are in a NULL * slot. So we avoid doing so and set the missed flag. */ - if (p.a_b_cnt == 0 && p.ccnt == 0) { + if (err || (p.a_b_cnt == 0 && p.ccnt == 0)) { dev_dbg(dev, "Error on null slot, setting miss\n"); echan->missed = 1; } else {