[PATCH] adsp: Fix test on unsigned in find_adsp_module_by_id()
Roel Kluin
roel.kluin at gmail.com
Fri Oct 16 15:05:36 PDT 2009
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...
>
An uint32_t is usually an unsigned int, so it should work, but
maybe plainly casting it to signed is better. Tested with snippet
below.
#include <stdio.h>
#include <stdlib.h>
int foo()
{
return -1;
}
int main()
{
unsigned int i = foo();
if (i < 0)
printf("1:%d\n", i);
if ((int)i < 0)
printf("2:%d\n", i);
if ((signed)i < 0)
printf("3:%d\n", i);
return 0;
}
If you want the signed cast, you can use this:
diff --git a/drivers/staging/dream/qdsp5/adsp.c b/drivers/staging/dream/qdsp5/adsp.c
index d096456..4633e4e 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 ((signed)id < 0)
return NULL;
#endif
return info->id_to_module[id];
More information about the devel
mailing list