Skip to content

Commit a92a00f

Browse files
Zhou Wangherbertx
authored andcommitted
crypto: hisilicon - misc fix about sgl
This patch fixes some misc problems in sgl codes, e.g. missing static, sparse error and input parameter check. Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> Signed-off-by: Shukun Tan <tanshukun1@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent d8ac7b8 commit a92a00f

File tree

1 file changed

+22
-18
lines changed
  • drivers/crypto/hisilicon

1 file changed

+22
-18
lines changed

drivers/crypto/hisilicon/sgl.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ void hisi_acc_free_sgl_pool(struct device *dev, struct hisi_acc_sgl_pool *pool)
144144
}
145145
EXPORT_SYMBOL_GPL(hisi_acc_free_sgl_pool);
146146

147-
struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool, u32 index,
148-
dma_addr_t *hw_sgl_dma)
147+
static struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool,
148+
u32 index, dma_addr_t *hw_sgl_dma)
149149
{
150150
struct mem_block *block;
151151
u32 block_index, offset;
@@ -161,23 +161,24 @@ struct hisi_acc_hw_sgl *acc_get_sgl(struct hisi_acc_sgl_pool *pool, u32 index,
161161
return (void *)block[block_index].sgl + pool->sgl_size * offset;
162162
}
163163

164-
void acc_put_sgl(struct hisi_acc_sgl_pool *pool, u32 index) {}
165-
166164
static void sg_map_to_hw_sg(struct scatterlist *sgl,
167165
struct acc_hw_sge *hw_sge)
168166
{
169167
hw_sge->buf = sgl->dma_address;
170-
hw_sge->len = sgl->dma_length;
168+
hw_sge->len = cpu_to_le32(sgl->dma_length);
171169
}
172170

173171
static void inc_hw_sgl_sge(struct hisi_acc_hw_sgl *hw_sgl)
174172
{
175-
hw_sgl->entry_sum_in_sgl++;
173+
u16 var = le16_to_cpu(hw_sgl->entry_sum_in_sgl);
174+
175+
var++;
176+
hw_sgl->entry_sum_in_sgl = cpu_to_le16(var);
176177
}
177178

178179
static void update_hw_sgl_sum_sge(struct hisi_acc_hw_sgl *hw_sgl, u16 sum)
179180
{
180-
hw_sgl->entry_sum_in_chain = sum;
181+
hw_sgl->entry_sum_in_chain = cpu_to_le16(sum);
181182
}
182183

183184
/**
@@ -201,22 +202,26 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
201202
dma_addr_t curr_sgl_dma = 0;
202203
struct acc_hw_sge *curr_hw_sge;
203204
struct scatterlist *sg;
204-
int sg_n = sg_nents(sgl);
205-
int i, ret;
205+
int i, ret, sg_n;
206206

207-
if (!dev || !sgl || !pool || !hw_sgl_dma || sg_n > pool->sge_nr)
207+
if (!dev || !sgl || !pool || !hw_sgl_dma)
208+
return ERR_PTR(-EINVAL);
209+
210+
sg_n = sg_nents(sgl);
211+
if (sg_n > pool->sge_nr)
208212
return ERR_PTR(-EINVAL);
209213

210214
ret = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
211215
if (!ret)
212216
return ERR_PTR(-EINVAL);
213217

214218
curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma);
215-
if (!curr_hw_sgl) {
216-
ret = -ENOMEM;
217-
goto err_unmap_sg;
219+
if (IS_ERR(curr_hw_sgl)) {
220+
dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
221+
return ERR_PTR(-ENOMEM);
222+
218223
}
219-
curr_hw_sgl->entry_length_in_sgl = pool->sge_nr;
224+
curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr);
220225
curr_hw_sge = curr_hw_sgl->sge_entries;
221226

222227
for_each_sg(sgl, sg, sg_n, i) {
@@ -229,10 +234,6 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev,
229234
*hw_sgl_dma = curr_sgl_dma;
230235

231236
return curr_hw_sgl;
232-
233-
err_unmap_sg:
234-
dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL);
235-
return ERR_PTR(ret);
236237
}
237238
EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_map_to_hw_sgl);
238239

@@ -249,6 +250,9 @@ EXPORT_SYMBOL_GPL(hisi_acc_sg_buf_map_to_hw_sgl);
249250
void hisi_acc_sg_buf_unmap(struct device *dev, struct scatterlist *sgl,
250251
struct hisi_acc_hw_sgl *hw_sgl)
251252
{
253+
if (!dev || !sgl || !hw_sgl)
254+
return;
255+
252256
dma_unmap_sg(dev, sgl, sg_nents(sgl), DMA_BIDIRECTIONAL);
253257

254258
hw_sgl->entry_sum_in_chain = 0;

0 commit comments

Comments
 (0)