crypto: ccree - Correctly handle return of sg_nents_for_len
Fix error handling in cc_map_hash_request_update where sg_nents_for_len
return value was assigned to u32, converting negative errors to large
positive values before passing to sg_copy_to_buffer.
Check sg_nents_for_len return value and propagate errors before
assigning to areq_ctx->in_nents.
Fixes: b7ec853068 ("crypto: ccree - use std api when possible")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
pull/1354/merge
parent
e9eb52037a
commit
8700ce07c5
|
|
@ -1235,6 +1235,7 @@ int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
u32 dummy = 0;
|
u32 dummy = 0;
|
||||||
u32 mapped_nents = 0;
|
u32 mapped_nents = 0;
|
||||||
|
int sg_nents;
|
||||||
|
|
||||||
dev_dbg(dev, " update params : curr_buff=%p curr_buff_cnt=0x%X nbytes=0x%X src=%p curr_index=%u\n",
|
dev_dbg(dev, " update params : curr_buff=%p curr_buff_cnt=0x%X nbytes=0x%X src=%p curr_index=%u\n",
|
||||||
curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index);
|
curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index);
|
||||||
|
|
@ -1248,7 +1249,10 @@ int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
|
||||||
if (total_in_len < block_size) {
|
if (total_in_len < block_size) {
|
||||||
dev_dbg(dev, " less than one block: curr_buff=%p *curr_buff_cnt=0x%X copy_to=%p\n",
|
dev_dbg(dev, " less than one block: curr_buff=%p *curr_buff_cnt=0x%X copy_to=%p\n",
|
||||||
curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]);
|
curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]);
|
||||||
areq_ctx->in_nents = sg_nents_for_len(src, nbytes);
|
sg_nents = sg_nents_for_len(src, nbytes);
|
||||||
|
if (sg_nents < 0)
|
||||||
|
return sg_nents;
|
||||||
|
areq_ctx->in_nents = sg_nents;
|
||||||
sg_copy_to_buffer(src, areq_ctx->in_nents,
|
sg_copy_to_buffer(src, areq_ctx->in_nents,
|
||||||
&curr_buff[*curr_buff_cnt], nbytes);
|
&curr_buff[*curr_buff_cnt], nbytes);
|
||||||
*curr_buff_cnt += nbytes;
|
*curr_buff_cnt += nbytes;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue