* [PATCH] accel/amdxdna: Use int instead of u32 to store error codes
@ 2025-08-26 7:29 Qianfeng Rong
2025-08-26 16:31 ` Lizhi Hou
0 siblings, 1 reply; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-26 7:29 UTC (permalink / raw)
To: Min Ma, Lizhi Hou, Oded Gabbay, dri-devel, linux-kernel; +Cc: Qianfeng Rong
Change the 'ret' variable from u32 to int to store -EINVAL, reducing
potential risks such as incorrect results when comparing 'ret' with
error codes.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/accel/amdxdna/aie2_ctx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 420467a5325c..e9f9b1fa5dc1 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -199,7 +199,7 @@ aie2_sched_resp_handler(void *handle, void __iomem *data, size_t size)
{
struct amdxdna_sched_job *job = handle;
struct amdxdna_gem_obj *cmd_abo;
- u32 ret = 0;
+ int ret = 0;
u32 status;
cmd_abo = job->cmd_bo;
@@ -229,7 +229,7 @@ static int
aie2_sched_nocmd_resp_handler(void *handle, void __iomem *data, size_t size)
{
struct amdxdna_sched_job *job = handle;
- u32 ret = 0;
+ int ret = 0;
u32 status;
if (unlikely(!data))
@@ -257,7 +257,7 @@ aie2_sched_cmdlist_resp_handler(void *handle, void __iomem *data, size_t size)
u32 fail_cmd_status;
u32 fail_cmd_idx;
u32 cmd_status;
- u32 ret = 0;
+ int ret = 0;
cmd_abo = job->cmd_bo;
if (unlikely(!data) || unlikely(size != sizeof(u32) * 3)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] accel/amdxdna: Use int instead of u32 to store error codes
2025-08-26 7:29 [PATCH] accel/amdxdna: Use int instead of u32 to store error codes Qianfeng Rong
@ 2025-08-26 16:31 ` Lizhi Hou
2025-08-27 2:15 ` Qianfeng Rong
0 siblings, 1 reply; 5+ messages in thread
From: Lizhi Hou @ 2025-08-26 16:31 UTC (permalink / raw)
To: Qianfeng Rong, Min Ma, Oded Gabbay, dri-devel, linux-kernel
On 8/26/25 00:29, Qianfeng Rong wrote:
> Change the 'ret' variable from u32 to int to store -EINVAL, reducing
> potential risks such as incorrect results when comparing 'ret' with
> error codes.
Sounds this fixes code issue. Could you add "Fixes" tag?
Thanks,
Lizhi
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> drivers/accel/amdxdna/aie2_ctx.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
> index 420467a5325c..e9f9b1fa5dc1 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -199,7 +199,7 @@ aie2_sched_resp_handler(void *handle, void __iomem *data, size_t size)
> {
> struct amdxdna_sched_job *job = handle;
> struct amdxdna_gem_obj *cmd_abo;
> - u32 ret = 0;
> + int ret = 0;
> u32 status;
>
> cmd_abo = job->cmd_bo;
> @@ -229,7 +229,7 @@ static int
> aie2_sched_nocmd_resp_handler(void *handle, void __iomem *data, size_t size)
> {
> struct amdxdna_sched_job *job = handle;
> - u32 ret = 0;
> + int ret = 0;
> u32 status;
>
> if (unlikely(!data))
> @@ -257,7 +257,7 @@ aie2_sched_cmdlist_resp_handler(void *handle, void __iomem *data, size_t size)
> u32 fail_cmd_status;
> u32 fail_cmd_idx;
> u32 cmd_status;
> - u32 ret = 0;
> + int ret = 0;
>
> cmd_abo = job->cmd_bo;
> if (unlikely(!data) || unlikely(size != sizeof(u32) * 3)) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] accel/amdxdna: Use int instead of u32 to store error codes
2025-08-26 16:31 ` Lizhi Hou
@ 2025-08-27 2:15 ` Qianfeng Rong
2025-08-27 17:18 ` Lizhi Hou
0 siblings, 1 reply; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-27 2:15 UTC (permalink / raw)
To: Lizhi Hou, Min Ma, Oded Gabbay, dri-devel, linux-kernel
在 2025/8/27 0:31, Lizhi Hou 写道:
>
> On 8/26/25 00:29, Qianfeng Rong wrote:
>> Change the 'ret' variable from u32 to int to store -EINVAL, reducing
>> potential risks such as incorrect results when comparing 'ret' with
>> error codes.
>
> Sounds this fixes code issue. Could you add "Fixes" tag?
>
>
The 'ret' variable stores negative error codes directly. Storing
error codes in u32 (an unsigned type) causes no runtime issues but is
stylistically inconsistent and very ugly.
Logical errors with 'ret' only occur when it is compared against negative
error codes. For example:
u32 ret = -EINVAL; // ret becomes an extremely large unsigned integer
if (ret == -EINVAL) // This condition will never be true
This patch reduces the likelihood of such issues occurring. Since it does
not fix an existing bug, I believe there is no need to add a Fixes tag.
Best regards,
Qianfeng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] accel/amdxdna: Use int instead of u32 to store error codes
2025-08-27 2:15 ` Qianfeng Rong
@ 2025-08-27 17:18 ` Lizhi Hou
2025-08-28 2:16 ` Qianfeng Rong
0 siblings, 1 reply; 5+ messages in thread
From: Lizhi Hou @ 2025-08-27 17:18 UTC (permalink / raw)
To: Qianfeng Rong, Min Ma, Oded Gabbay, dri-devel, linux-kernel
On 8/26/25 19:15, Qianfeng Rong wrote:
>
> 在 2025/8/27 0:31, Lizhi Hou 写道:
>>
>> On 8/26/25 00:29, Qianfeng Rong wrote:
>>> Change the 'ret' variable from u32 to int to store -EINVAL, reducing
>>> potential risks such as incorrect results when comparing 'ret' with
>>> error codes.
>>
>> Sounds this fixes code issue. Could you add "Fixes" tag?
>>
>>
>
> The 'ret' variable stores negative error codes directly. Storing
> error codes in u32 (an unsigned type) causes no runtime issues but is
> stylistically inconsistent and very ugly.
>
> Logical errors with 'ret' only occur when it is compared against negative
> error codes. For example:
>
> u32 ret = -EINVAL; // ret becomes an extremely large unsigned integer
>
> if (ret == -EINVAL) // This condition will never be true
>
> This patch reduces the likelihood of such issues occurring. Since it does
> not fix an existing bug, I believe there is no need to add a Fixes tag.
I agree with the change.
u32 ret = -EINVAL may lead to a gcc warning if -Wsign-conversion is
enabled. That is why I suggested Fixes tag.
Lizhi
>
> Best regards,
> Qianfeng
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] accel/amdxdna: Use int instead of u32 to store error codes
2025-08-27 17:18 ` Lizhi Hou
@ 2025-08-28 2:16 ` Qianfeng Rong
0 siblings, 0 replies; 5+ messages in thread
From: Qianfeng Rong @ 2025-08-28 2:16 UTC (permalink / raw)
To: Lizhi Hou, Min Ma, Oded Gabbay, dri-devel, linux-kernel
在 2025/8/28 1:18, Lizhi Hou 写道:
>
> On 8/26/25 19:15, Qianfeng Rong wrote:
>>
>> 在 2025/8/27 0:31, Lizhi Hou 写道:
>>>
>>> On 8/26/25 00:29, Qianfeng Rong wrote:
>>>> Change the 'ret' variable from u32 to int to store -EINVAL, reducing
>>>> potential risks such as incorrect results when comparing 'ret' with
>>>> error codes.
>>>
>>> Sounds this fixes code issue. Could you add "Fixes" tag?
>>>
>>>
>>
>> The 'ret' variable stores negative error codes directly. Storing
>> error codes in u32 (an unsigned type) causes no runtime issues but is
>> stylistically inconsistent and very ugly.
>>
>> Logical errors with 'ret' only occur when it is compared against
>> negative
>> error codes. For example:
>>
>> u32 ret = -EINVAL; // ret becomes an extremely large unsigned integer
>>
>> if (ret == -EINVAL) // This condition will never be true
>>
>> This patch reduces the likelihood of such issues occurring. Since it
>> does
>> not fix an existing bug, I believe there is no need to add a Fixes tag.
>
> I agree with the change.
>
> u32 ret = -EINVAL may lead to a gcc warning if -Wsign-conversion is
> enabled. That is why I suggested Fixes tag.
Thank you for letting me know about this. I will submit the v2 version.
Best regards,
Qianfeng
>
> Lizhi
>
>>
>> Best regards,
>> Qianfeng
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-28 2:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 7:29 [PATCH] accel/amdxdna: Use int instead of u32 to store error codes Qianfeng Rong
2025-08-26 16:31 ` Lizhi Hou
2025-08-27 2:15 ` Qianfeng Rong
2025-08-27 17:18 ` Lizhi Hou
2025-08-28 2:16 ` Qianfeng Rong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).