diff mbox series

[3/4] crypto: hisilicon/sec2 - fix some cleanup issues

Message ID 20231229064421.16981-4-taoqi10@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series some updates and cleanups for hisilicon/sec2. | expand

Commit Message

taoqi Dec. 29, 2023, 6:44 a.m. UTC
This patch fixes following cleanup issues:
 - The return value of the function is
   inconsistent with the actual return type.
 - After the pointer type is directly converted
   to the '__le64' type, the program may crash
   or produce unexpected results.

Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
 drivers/crypto/hisilicon/sec2/sec_crypto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Herbert Xu Jan. 25, 2024, 9:37 a.m. UTC | #1
On Fri, Dec 29, 2023 at 02:44:20PM +0800, Qi Tao wrote:
>
> @@ -1371,7 +1371,7 @@ static int sec_skcipher_bd_fill_v3(struct sec_ctx *ctx, struct sec_req *req)
>  	sec_sqe3->bd_param = cpu_to_le32(bd_param);
>  
>  	sec_sqe3->c_len_ivin |= cpu_to_le32(c_req->c_len);
> -	sec_sqe3->tag = cpu_to_le64(req);
> +	sec_sqe3->tag = cpu_to_le64((unsigned long)(uintptr_t)req);

Please explain why you're casting twice.

Thanks,
taoqi Jan. 26, 2024, 8:40 a.m. UTC | #2
On 2024/1/25 17:37, Herbert Xu wrote:
> On Fri, Dec 29, 2023 at 02:44:20PM +0800, Qi Tao wrote:
>>
>> @@ -1371,7 +1371,7 @@ static int sec_skcipher_bd_fill_v3(struct sec_ctx *ctx, struct sec_req *req)
>>   	sec_sqe3->bd_param = cpu_to_le32(bd_param);
>>   
>>   	sec_sqe3->c_len_ivin |= cpu_to_le32(c_req->c_len);
>> -	sec_sqe3->tag = cpu_to_le64(req);
>> +	sec_sqe3->tag = cpu_to_le64((unsigned long)(uintptr_t)req);
> 
> Please explain why you're casting twice.
> 
> Thanks,

I'm sorry. I made a mistake here. unsigned long and uintptr_t are the 
same data type in linux kernel. The type cast is invalidly repeated 
here. Can I just keep (unsigned long) one cast?
Herbert Xu Jan. 26, 2024, 8:54 a.m. UTC | #3
On Fri, Jan 26, 2024 at 04:40:39PM +0800, taoqi wrote:
>
> I'm sorry. I made a mistake here. unsigned long and uintptr_t are the same
> data type in linux kernel. The type cast is invalidly repeated here. Can I
> just keep (unsigned long) one cast?

Yes that makes sense.

Thanks,
diff mbox series

Patch

diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c
index 692ba3213cc6..5d4facf62c86 100644
--- a/drivers/crypto/hisilicon/sec2/sec_crypto.c
+++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c
@@ -118,7 +118,7 @@  struct sec_aead {
 };
 
 /* Get an en/de-cipher queue cyclically to balance load over queues of TFM */
-static inline int sec_alloc_queue_id(struct sec_ctx *ctx, struct sec_req *req)
+static inline u32 sec_alloc_queue_id(struct sec_ctx *ctx, struct sec_req *req)
 {
 	if (req->c_req.encrypt)
 		return (u32)atomic_inc_return(&ctx->enc_qcyclic) %
@@ -1371,7 +1371,7 @@  static int sec_skcipher_bd_fill_v3(struct sec_ctx *ctx, struct sec_req *req)
 	sec_sqe3->bd_param = cpu_to_le32(bd_param);
 
 	sec_sqe3->c_len_ivin |= cpu_to_le32(c_req->c_len);
-	sec_sqe3->tag = cpu_to_le64(req);
+	sec_sqe3->tag = cpu_to_le64((unsigned long)(uintptr_t)req);
 
 	return 0;
 }