[PATCH] drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug

oushixiong1025@163.com posted 1 patch 11 hours ago
drivers/gpu/drm/sysfb/ofdrm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug
Posted by oushixiong1025@163.com 11 hours ago
From: Shixiong Ou <oushixiong@kylinos.cn>

The is_avivo() function has a logic error where it compares a constant
to another constant instead of checking the device parameter:

  (PCI_VENDOR_ID_ATI_R600 >= 0x9400)

However, according to the code comment and the OFDRM_MODEL_AVIVO
definition ("ATI R5xx"), this function is intended to match only R5xx
cards (device IDs 0x7100-0x7800), not R6xx or later. The second
condition checking for R600 is erroneous and should be removed.

Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
---
 drivers/gpu/drm/sysfb/ofdrm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c
index a6dc34b9ec0f..ea1db1cfe3ed 100644
--- a/drivers/gpu/drm/sysfb/ofdrm.c
+++ b/drivers/gpu/drm/sysfb/ofdrm.c
@@ -238,8 +238,7 @@ static bool is_avivo(u32 vendor, u32 device)
 {
 	/* This will match most R5xx */
 	return (vendor == PCI_VENDOR_ID_ATI) &&
-	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
-		(PCI_VENDOR_ID_ATI_R600 >= 0x9400));
+	       (device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800);
 }
 
 static enum ofdrm_model display_get_model_of(struct drm_device *dev, struct device_node *of_node)
-- 
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus
Re: [PATCH] drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug
Posted by Thomas Zimmermann 9 hours ago
Hi

Am 24.07.26 um 11:41 schrieb oushixiong1025@163.com:
> From: Shixiong Ou <oushixiong@kylinos.cn>
>
> The is_avivo() function has a logic error where it compares a constant
> to another constant instead of checking the device parameter:
>
>    (PCI_VENDOR_ID_ATI_R600 >= 0x9400)
>
> However, according to the code comment and the OFDRM_MODEL_AVIVO
> definition ("ATI R5xx"), this function is intended to match only R5xx
> cards (device IDs 0x7100-0x7800), not R6xx or later. The second
> condition checking for R600 is erroneous and should be removed.
>
> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
> ---
>   drivers/gpu/drm/sysfb/ofdrm.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c
> index a6dc34b9ec0f..ea1db1cfe3ed 100644
> --- a/drivers/gpu/drm/sysfb/ofdrm.c
> +++ b/drivers/gpu/drm/sysfb/ofdrm.c
> @@ -238,8 +238,7 @@ static bool is_avivo(u32 vendor, u32 device)
>   {
>   	/* This will match most R5xx */
>   	return (vendor == PCI_VENDOR_ID_ATI) &&
> -	       ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
> -		(PCI_VENDOR_ID_ATI_R600 >= 0x9400));

I tried to match exactly this: 
https://elixir.bootlin.com/linux/v7.1.4/source/drivers/video/fbdev/offb.c#L365

IDK if that works in practice, but I don't dare changing it without a 
concrete bug report.

Best regards
Thomas

> +	       (device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800);
>   }
>   
>   static enum ofdrm_model display_get_model_of(struct drm_device *dev, struct device_node *of_node)

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)


Re: [PATCH] drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug
Posted by Shixiong Ou 8 hours ago
On 2026/7/24 19:34, Thomas Zimmermann wrote:
> Hi
>
> Am 24.07.26 um 11:41 schrieb oushixiong1025@163.com:
>> From: Shixiong Ou <oushixiong@kylinos.cn>
>>
>> The is_avivo() function has a logic error where it compares a constant
>> to another constant instead of checking the device parameter:
>>
>>    (PCI_VENDOR_ID_ATI_R600 >= 0x9400)
>>
>> However, according to the code comment and the OFDRM_MODEL_AVIVO
>> definition ("ATI R5xx"), this function is intended to match only R5xx
>> cards (device IDs 0x7100-0x7800), not R6xx or later. The second
>> condition checking for R600 is erroneous and should be removed.
>>
>> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
>> ---
>>   drivers/gpu/drm/sysfb/ofdrm.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/sysfb/ofdrm.c 
>> b/drivers/gpu/drm/sysfb/ofdrm.c
>> index a6dc34b9ec0f..ea1db1cfe3ed 100644
>> --- a/drivers/gpu/drm/sysfb/ofdrm.c
>> +++ b/drivers/gpu/drm/sysfb/ofdrm.c
>> @@ -238,8 +238,7 @@ static bool is_avivo(u32 vendor, u32 device)
>>   {
>>       /* This will match most R5xx */
>>       return (vendor == PCI_VENDOR_ID_ATI) &&
>> -           ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
>> -        (PCI_VENDOR_ID_ATI_R600 >= 0x9400));
>
> I tried to match exactly this: 
> https://elixir.bootlin.com/linux/v7.1.4/source/drivers/video/fbdev/offb.c#L365
>
> IDK if that works in practice, but I don't dare changing it without a 
> concrete bug report.
>
> Best regards
> Thomas
>
Hi,

PCI_VENDOR_ID_ATI_R600 is defined as 0x9400 . Therefore, this expression 
always evaluates to true (0x9400 >= 0x9400).
It does not depend on the device parameter passed to is_avivo().
So is this a coding mistake?

Best regards
Shixiong Ou.

>> +           (device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800);
>>   }
>>     static enum ofdrm_model display_get_model_of(struct drm_device 
>> *dev, struct device_node *of_node)
>

Re: [PATCH] drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug
Posted by Thomas Zimmermann 6 hours ago
Hi

Am 24.07.26 um 15:21 schrieb Shixiong Ou:
>
> On 2026/7/24 19:34, Thomas Zimmermann wrote:
>> Hi
>>
>> Am 24.07.26 um 11:41 schrieb oushixiong1025@163.com:
>>> From: Shixiong Ou <oushixiong@kylinos.cn>
>>>
>>> The is_avivo() function has a logic error where it compares a constant
>>> to another constant instead of checking the device parameter:
>>>
>>>    (PCI_VENDOR_ID_ATI_R600 >= 0x9400)
>>>
>>> However, according to the code comment and the OFDRM_MODEL_AVIVO
>>> definition ("ATI R5xx"), this function is intended to match only R5xx
>>> cards (device IDs 0x7100-0x7800), not R6xx or later. The second
>>> condition checking for R600 is erroneous and should be removed.
>>>
>>> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
>>> ---
>>>   drivers/gpu/drm/sysfb/ofdrm.c | 3 +--
>>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/sysfb/ofdrm.c 
>>> b/drivers/gpu/drm/sysfb/ofdrm.c
>>> index a6dc34b9ec0f..ea1db1cfe3ed 100644
>>> --- a/drivers/gpu/drm/sysfb/ofdrm.c
>>> +++ b/drivers/gpu/drm/sysfb/ofdrm.c
>>> @@ -238,8 +238,7 @@ static bool is_avivo(u32 vendor, u32 device)
>>>   {
>>>       /* This will match most R5xx */
>>>       return (vendor == PCI_VENDOR_ID_ATI) &&
>>> -           ((device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800) ||
>>> -        (PCI_VENDOR_ID_ATI_R600 >= 0x9400));
>>
>> I tried to match exactly this: 
>> https://elixir.bootlin.com/linux/v7.1.4/source/drivers/video/fbdev/offb.c#L365
>>
>> IDK if that works in practice, but I don't dare changing it without a 
>> concrete bug report.
>>
>> Best regards
>> Thomas
>>
> Hi,
>
> PCI_VENDOR_ID_ATI_R600 is defined as 0x9400 . Therefore, this 
> expression always evaluates to true (0x9400 >= 0x9400).
> It does not depend on the device parameter passed to is_avivo().
> So is this a coding mistake?

Oh, now I see it. That's indeed a bug. It should test for (device >= 
PCI_VENDOR_ID_ATI_R600) instead.  Thanks for addressing this.

Best regards
Thomas


>
> Best regards
> Shixiong Ou.
>
>>> +           (device >= PCI_VENDOR_ID_ATI_R520 && device < 0x7800);
>>>   }
>>>     static enum ofdrm_model display_get_model_of(struct drm_device 
>>> *dev, struct device_node *of_node)
>>
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)