Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp116887rwb; Wed, 30 Nov 2022 23:10:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5mWzpMiTG9mgvP/CTnVImdxz3V5jwWDhUEvc2LQn8vfMHiqJwsybkaWWxuoXcFtNj4nzGf X-Received: by 2002:a17:903:181:b0:189:8f11:f2f with SMTP id z1-20020a170903018100b001898f110f2fmr18572871plg.133.1669878625589; Wed, 30 Nov 2022 23:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669878625; cv=none; d=google.com; s=arc-20160816; b=vCNksO3q1R5gxwEvIbULrxyduPxMrju2X4CPQDB4+nLqIT/pV/neRvygSuN+ytm8/m x89WcZ9pCAOYUvZLbB63iY0SLskL3Ci/BrlXHCgJtmWQwkKh8cSC0ab0GaaS7iU1HCq2 MUJHk9SuGmw+lmtANQZXDX5NMbjuJpo/8xW840WhfVH2FmDTyQLEzszbbi6nDEwTqmo/ DSniE/gxBqFMEOFxMvoTB05YtdSslQDodz6vauGlxiyqbXJm0GttvZgmc/xKfjQBG11k wxrzKhggIwC5Np9u/vOFALzpfu9BvdaLgscUC95DSkf4PldVArplCmcJzN/yfOkGJU+i mcyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=P8+MsRChMoSZCbd7QB9P8K9nTMvNvNDFDZhfTUkVUiI=; b=m0+xX24fpCdmZlLqfqFagw6fLT0Pdthi6hQEUo2+9k8vQW94SjG/DaTbP7aCLanNAb HkNBnsO+P/yDxTSZHWhHn0heIp53KjFHJLhvAE5LLXS040LT2zCsNQ+efR5QJrDUsRFc sdAFbFEtsRY0Yr2yeNcotXeQ7Qv6GCecVkCVqWqR7kW8BC1Ctz/8Ia4936HmmrdmE4Pv wfN4nx/SZ5LOv7tV4Z8rh8vfx4vekri1XpOThXPD/5OaXC3MO4erNHZ0Xy4MitFFsFN+ zguvEABaiibwv5T7jw9VnYj7bwufvW0lptOOSRswwFtSXCUJg7QUAPfmQeBKnd9NEtXg hGCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020a632048000000b0046e9babe7a1si3687267pgm.54.2022.11.30.23.10.11; Wed, 30 Nov 2022 23:10:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229499AbiLAGZd (ORCPT + 99 others); Thu, 1 Dec 2022 01:25:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbiLAGZc (ORCPT ); Thu, 1 Dec 2022 01:25:32 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA6948419 for ; Wed, 30 Nov 2022 22:25:29 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NN5dp1ZC8z15MKy; Thu, 1 Dec 2022 14:24:46 +0800 (CST) Received: from cgs.huawei.com (10.244.148.83) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 1 Dec 2022 14:25:26 +0800 From: Gaosheng Cui To: , , , , , CC: Subject: [PATCH] crypto: img-hash - Fix variable dereferenced before check 'hdev->req' Date: Thu, 1 Dec 2022 14:25:26 +0800 Message-ID: <20221201062526.4089-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Smatch report warning as follows: drivers/crypto/img-hash.c:366 img_hash_dma_task() warn: variable dereferenced before check 'hdev->req' Variable dereferenced should be done after check 'hdev->req', fix it. Fixes: d358f1abbf71 ("crypto: img-hash - Add Imagination Technologies hw hash accelerator") Fixes: 10badea259fa ("crypto: img-hash - Fix null pointer exception") Signed-off-by: Gaosheng Cui --- drivers/crypto/img-hash.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c index d8e82d69745d..9629e98bd68b 100644 --- a/drivers/crypto/img-hash.c +++ b/drivers/crypto/img-hash.c @@ -358,12 +358,16 @@ static int img_hash_dma_init(struct img_hash_dev *hdev) static void img_hash_dma_task(unsigned long d) { struct img_hash_dev *hdev = (struct img_hash_dev *)d; - struct img_hash_request_ctx *ctx = ahash_request_ctx(hdev->req); + struct img_hash_request_ctx *ctx; u8 *addr; size_t nbytes, bleft, wsend, len, tbc; struct scatterlist tsg; - if (!hdev->req || !ctx->sg) + if (!hdev->req) + return; + + ctx = ahash_request_ctx(hdev->req); + if (!ctx->sg) return; addr = sg_virt(ctx->sg); -- 2.25.1