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: 101721 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp379780qgf; Fri, 30 Sep 2016 09:19:45 -0700 (PDT) X-Received: by 10.66.12.234 with SMTP id b10mr13080459pac.91.1475252385866; Fri, 30 Sep 2016 09:19:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d187si20716833pfa.241.2016.09.30.09.19.45; Fri, 30 Sep 2016 09:19:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934033AbcI3QTn (ORCPT + 27 others); Fri, 30 Sep 2016 12:19:43 -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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.9.0 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 {