From patchwork Thu Jun 22 12:35:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 106206 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp92956qgd; Thu, 22 Jun 2017 05:37:01 -0700 (PDT) X-Received: by 10.84.238.15 with SMTP id u15mr2791853plk.126.1498135021199; Thu, 22 Jun 2017 05:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498135021; cv=none; d=google.com; s=arc-20160816; b=clCErfmZ69+93O5RZyBI19EyqeF2pN0Cj0c+fnotTykMAyAgg5Gh6pVrxKE6xh65z+ Wu8hnzXX6NmLkdp40P8GsAcGzayFWkGQXfg4dGMEsbZdvn3pcPalOaaTw57+bwEoxGBr KrfWxoNOCnsQm4j/a+If3xoKcYI93c4JOulXUXwxs4LWCEthsxLTTfc220HJaZESdogL bFMCh6CKuqkGnqXlGwB+3u5aSP93VA3oVRD8NyBwLrOIBw+/CFL5x+VuEPgug0Ho+EzP Vfjki9cf3OY5sZ4KiK1gOMWjo38GX45fJ2zLUJxRBwzJuADKNbWMDK0Ef4A7u6Jknk73 XRaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IZxCA4qe7XG/BlIFkY3daBy9y2H53+28gQ6l5I8YgGM=; b=Uf/eDun1PEnfXiKAdo+qs4CKohDCBxMwvzP4Gzbmj8d5//vPkL9ZfE7tusfAF7jffV +KjfhPKJ/qwO9qnz9oWAdPSOIklnCiT6oLho5DL7JVPWoKWvKSejeo7tm0DpfNkTptzC q3hMAtUCAa0g0r1nYv/lq0fONIKnp0327A93oV7rgbZ00kwNq3AEZ+f5QbofhcbhCL39 8LfMLCjKFJTmT577pFYpHnUExXIA15VzyaRnRDwChWtSTmGpJ5CAo/Ezlr1JcHNt84Wz R5EXg4wUeO6k+qhasPg0eIypysjn2IMuhD4t1ncaAcTwTvWILSm6ZvHclw3Q0dEdc7Bx TGGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w70si1067420pgw.98.2017.06.22.05.37.00; Thu, 22 Jun 2017 05:37:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751094AbdFVMg7 (ORCPT + 1 other); Thu, 22 Jun 2017 08:36:59 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:53571 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750847AbdFVMg6 (ORCPT ); Thu, 22 Jun 2017 08:36:58 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0Mddka-1d9lju2feO-00PNJG; Thu, 22 Jun 2017 14:36:14 +0200 From: Arnd Bergmann To: Giovanni Cabiddu , Salvatore Benedetto , Herbert Xu , "David S. Miller" Cc: Arnd Bergmann , Christoph Hellwig , Corentin LABBE , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto: qat - avoid an uninitialized variable warning Date: Thu, 22 Jun 2017 14:35:46 +0200 Message-Id: <20170622123604.505337-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:CmPPCAGDHxO4M+AMonTUiLR+lvWlcxR27lGHEIE+LMgIQGR9bkI 19XbVA7P3I5RsSXf/cZrlGyTyYsWejg/o4Rr3w9GSubGAS9x19eMiz3DHnf4lSx8OxNRmmi JOeCKFLeIVc5D9Tb5D1O2sPIZXIlLVXY/JI1LdFlFbXtFaNVz1mDCh7+PoijZudjeRwEZB1 so4WdKoa3Gm8RRNXa4ZjQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Z1RXEp47FfQ=:E1avC6rIXQjQFSd+vLl+A2 ZTX/QKBEGFf1QtNthlBx2tVi7oEzDYPOig9k08IWRPdk3yijbzojAnmBAF2S9XsTYT2MaOOxR lTofqhqqloY6hFCaNIHqms3M4MXu4tyb3gSzsoKV7x39Jj/jZEDKKug7rk4xOM35ygwbTTjxz lklrMaVwCB+N8JxyH4pOETx2G9Mb3j2dQYPNpjp6UpQY7R7wjVSF+wier7sELaQuRovNEXszZ V/qOXoeCl+lBza8Vtg08gq5/DHWInOotL22LweROc6WjmB8cY6zD4FXiS7o4YmFXHb5CV5c9L zDuwPp4QOPTxWNHcBpLUcu2+1DD9DWVgoce7i7OLkPXqHqLqp1pRSW9TsSG2ADsB2DaDovbKt iguKu4d5cH1iKjxh0NTxaTaARytUZ7Xa3WM24xJiK267m2tDLH/ip/WGMYWHjE+r895MicRCt pTW69BGyROhQs2mzL7FCquS9UQPxNWHssdvZRKn/BqZrKyXBUzLOLrzhgcBA01tJME3s6FgzM RRZcXJZ0RrzqvOv2Aa0PxfufhUJI8rC7pIJ2grMb1rg86GKF8dggS1Osl3ZoxNgFDdHUdmX33 4H/qdDynohXt/HlKCXnaKnJ/Qyx71jy6IO3ovpQhv8lx06IpTssp1Z/cmatUaxF0pBvbHFqHh T3iKNvDfDMTZDMqvit5SAb9gjatACo2p5g5d1BwccL9LUVkZufpnAIMj2FoNqDTJ5Phc= Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org After commit 9e442aa6a753 ("x86: remove DMA_ERROR_CODE"), the inlining decisions in the qat driver changed slightly, introducing a new false-positive warning: drivers/crypto/qat/qat_common/qat_algs.c: In function 'qat_alg_sgl_to_bufl.isra.6': include/linux/dma-mapping.h:228:2: error: 'sz_out' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/crypto/qat/qat_common/qat_algs.c:676:9: note: 'sz_out' was declared here The patch that introduced this is correct, so let's just avoid the warning in this driver by rearranging the unwinding after an error to make it more obvious to the compiler what is going on. The problem here is the 'if (unlikely(dma_mapping_error(dev, blp)))' check, in which the 'unlikely' causes gcc to forget what it knew about the state of the variables. Cleaning up the dma state in the reverse order it was created means we can simplify the logic so it doesn't have to know about that state, and also makes it easier to understand. Cc: Christoph Hellwig Signed-off-by: Arnd Bergmann --- drivers/crypto/qat/qat_common/qat_algs.c | 40 +++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) -- 2.9.0 diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c index 5b5efcc52cb5..baffae817259 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -686,7 +686,7 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, blp = dma_map_single(dev, bufl, sz, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev, blp))) - goto err; + goto err_in; for_each_sg(sgl, sg, n, i) { int y = sg_nctr; @@ -699,7 +699,7 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, DMA_BIDIRECTIONAL); bufl->bufers[y].len = sg->length; if (unlikely(dma_mapping_error(dev, bufl->bufers[y].addr))) - goto err; + goto err_in; sg_nctr++; } bufl->num_bufs = sg_nctr; @@ -717,10 +717,10 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, buflout = kzalloc_node(sz_out, GFP_ATOMIC, dev_to_node(&GET_DEV(inst->accel_dev))); if (unlikely(!buflout)) - goto err; + goto err_in; bloutp = dma_map_single(dev, buflout, sz_out, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(dev, bloutp))) - goto err; + goto err_out; bufers = buflout->bufers; for_each_sg(sglout, sg, n, i) { int y = sg_nctr; @@ -732,7 +732,7 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, sg->length, DMA_BIDIRECTIONAL); if (unlikely(dma_mapping_error(dev, bufers[y].addr))) - goto err; + goto err_out; bufers[y].len = sg->length; sg_nctr++; } @@ -747,9 +747,20 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, qat_req->buf.sz_out = 0; } return 0; -err: - dev_err(dev, "Failed to map buf for dma\n"); - sg_nctr = 0; + +err_out: + n = sg_nents(sglout); + for (i = 0; i < n; i++) + if (!dma_mapping_error(dev, buflout->bufers[i].addr)) + dma_unmap_single(dev, buflout->bufers[i].addr, + buflout->bufers[i].len, + DMA_BIDIRECTIONAL); + if (!dma_mapping_error(dev, bloutp)) + dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); + kfree(buflout); + +err_in: + n = sg_nents(sgl); for (i = 0; i < n; i++) if (!dma_mapping_error(dev, bufl->bufers[i].addr)) dma_unmap_single(dev, bufl->bufers[i].addr, @@ -759,17 +770,8 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst, if (!dma_mapping_error(dev, blp)) dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); kfree(bufl); - if (sgl != sglout && buflout) { - n = sg_nents(sglout); - for (i = 0; i < n; i++) - if (!dma_mapping_error(dev, buflout->bufers[i].addr)) - dma_unmap_single(dev, buflout->bufers[i].addr, - buflout->bufers[i].len, - DMA_BIDIRECTIONAL); - if (!dma_mapping_error(dev, bloutp)) - dma_unmap_single(dev, bloutp, sz_out, DMA_TO_DEVICE); - kfree(buflout); - } + + dev_err(dev, "Failed to map buf for dma\n"); return -ENOMEM; }