crypto: hisilicon/sgl - small cleanups for sgl.c
authorWeili Qian <qianweili@huawei.com>
Sat, 25 Nov 2023 11:50:09 +0000 (19:50 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 1 Dec 2023 10:03:26 +0000 (18:03 +0800)
1. Remove unnecessary brackets in function hisi_acc_create_sgl_pool().
2. Modify local variable type, ensure that the variable type is
consistent with the variable type to be compared.
3. Because the function clear_hw_sgl_sge() is in the task process,
obtain the value of le16_to_cpu(hw_sgl->entry_sum_in_sgl) before
loop execting to shorten the loop execution time.

Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/hisilicon/sgl.c

index 3df7a256e9197a3dba8b9f12cc30bdc382ac9f0e..4b2cd6736df7ea17791f0cb93d373419e1b695fd 100644 (file)
@@ -121,10 +121,10 @@ struct hisi_acc_sgl_pool *hisi_acc_create_sgl_pool(struct device *dev,
        return pool;
 
 err_free_mem:
-       for (j = 0; j < i; j++) {
+       for (j = 0; j < i; j++)
                dma_free_coherent(dev, block_size, block[j].sgl,
                                  block[j].sgl_dma);
-       }
+
        kfree_sensitive(pool);
        return ERR_PTR(-ENOMEM);
 }
@@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(hisi_acc_create_sgl_pool);
 void hisi_acc_free_sgl_pool(struct device *dev, struct hisi_acc_sgl_pool *pool)
 {
        struct mem_block *block;
-       int i;
+       u32 i;
 
        if (!dev || !pool)
                return;
@@ -196,9 +196,10 @@ static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum)
 static void clear_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
 {
        struct acc_hw_sge *hw_sge = hw_sgl->sge_entries;
+       u16 entry_sum = le16_to_cpu(hw_sgl->entry_sum_in_sgl);
        int i;
 
-       for (i = 0; i < le16_to_cpu(hw_sgl->entry_sum_in_sgl); i++) {
+       for (i = 0; i < entry_sum; i++) {
                hw_sge[i].page_ctrl = NULL;
                hw_sge[i].buf = 0;
                hw_sge[i].len = 0;
@@ -223,10 +224,11 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
                              u32 index, dma_addr_t *hw_sgl_dma)
 {
        struct hisi_acc_hw_sgl *curr_hw_sgl;
+       unsigned int i, sg_n_mapped;
        dma_addr_t curr_sgl_dma = 0;
        struct acc_hw_sge *curr_hw_sge;
        struct scatterlist *sg;
-       int i, sg_n, sg_n_mapped;
+       int sg_n;
 
        if (!dev || !sgl || !pool || !hw_sgl_dma)
                return ERR_PTR(-EINVAL);