]> git.baikalelectronics.ru Git - kernel.git/commitdiff
crypto: img-hash - Fix variable dereferenced before check 'hdev->req'
authorGaosheng Cui <cuigaosheng1@huawei.com>
Thu, 1 Dec 2022 06:25:26 +0000 (14:25 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:21 +0000 (11:41 +0100)
[ Upstream commit a435272a208230f3263757c326e3159b52587969 ]

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: c004c2f51dbc ("crypto: img-hash - Add Imagination Technologies hw hash accelerator")
Fixes: 1731bcf22ff8 ("crypto: img-hash - Fix null pointer exception")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/img-hash.c

index fe4cc8babe1c7d510c5eed0f9462059d623d124b..17cc44f14e5c49ac531a7611cc9fd22420f1fa80 100644 (file)
@@ -356,12 +356,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);