[PATCH] adsp: Fix test on unsigned in find_adsp_module_by_id()

Jiri Slaby jirislaby at gmail.com
Sat Oct 17 10:55:50 UTC 2009


On 10/17/2009 12:05 AM, Roel Kluin wrote:
> A negative id will not be noticed unless the comparison is signed.
> 
> Signed-off-by: Roel Kluin <roel.kluin at gmail.com>
> ---
>>> diff --git a/drivers/staging/dream/qdsp5/adsp.c b/drivers/staging/dream/qdsp5/adsp.c
>>> index d096456..6948bdc 100644
>>> --- a/drivers/staging/dream/qdsp5/adsp.c
>>> +++ b/drivers/staging/dream/qdsp5/adsp.c
>>> @@ -171,7 +171,7 @@ static struct msm_adsp_module *find_adsp_module_by_id(
>>>        } else {
>>>  #if CONFIG_MSM_AMSS_VERSION >= 6350
>>>                id = get_module_index(id);
>>> -               if (id < 0)
>>> +               if ((int)id < 0)
>>
>> Are you sure this is right? Simply casting an unsigned number to
>> signed won't miraculously give it a negative value...

Why? ~0U will become -1 etc. so that the test ((int)id < 0) will match.
I didn't look into the code if the change is correct though.

>>
> An uint32_t is usually an unsigned int, so it should work, but
> maybe plainly casting it to signed is better.

signed is exactly the same as int.



More information about the devel mailing list