All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vga_switcheroo: Fix impossible judgment condition
@ 2023-10-26  2:10 ` Su Hui
  0 siblings, 0 replies; 8+ messages in thread
From: Su Hui @ 2023-10-26  2:10 UTC (permalink / raw)
  To: lukas, maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: Su Hui, tiwai, Jim.Qu, dri-devel, linux-kernel, kernel-janitors

'id' is enum type like unsigned int, so it will never be less than zero.

Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/gpu/vga/vga_switcheroo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index 365e6ddbe90f..d3064466fd3a 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
 	mutex_lock(&vgasr_mutex);
 	if (vgasr_priv.active) {
 		id = vgasr_priv.handler->get_client_id(vga_dev);
-		if (id < 0) {
+		if ((int)id < 0) {
 			mutex_unlock(&vgasr_mutex);
 			return -EINVAL;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] vga_switcheroo: Fix impossible judgment condition
@ 2023-10-26  2:10 ` Su Hui
  0 siblings, 0 replies; 8+ messages in thread
From: Su Hui @ 2023-10-26  2:10 UTC (permalink / raw)
  To: lukas, maarten.lankhorst, mripard, tzimmermann, airlied, daniel
  Cc: Su Hui, kernel-janitors, linux-kernel, dri-devel, Jim.Qu

'id' is enum type like unsigned int, so it will never be less than zero.

Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/gpu/vga/vga_switcheroo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index 365e6ddbe90f..d3064466fd3a 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
 	mutex_lock(&vgasr_mutex);
 	if (vgasr_priv.active) {
 		id = vgasr_priv.handler->get_client_id(vga_dev);
-		if (id < 0) {
+		if ((int)id < 0) {
 			mutex_unlock(&vgasr_mutex);
 			return -EINVAL;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
  2023-10-26  2:10 ` Su Hui
@ 2023-10-26  4:44   ` Dan Carpenter
  -1 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-26  4:44 UTC (permalink / raw)
  To: Su Hui
  Cc: lukas, maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
	tiwai, Jim.Qu, dri-devel, linux-kernel, kernel-janitors

On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
> 'id' is enum type like unsigned int, so it will never be less than zero.
> 
> Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  drivers/gpu/vga/vga_switcheroo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> index 365e6ddbe90f..d3064466fd3a 100644
> --- a/drivers/gpu/vga/vga_switcheroo.c
> +++ b/drivers/gpu/vga/vga_switcheroo.c
> @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
>  	mutex_lock(&vgasr_mutex);
>  	if (vgasr_priv.active) {
>  		id = vgasr_priv.handler->get_client_id(vga_dev);
> -		if (id < 0) {
> +		if ((int)id < 0) {

Hi,

I feel like you're using Smatch?  Which is great!  Fantastic!

Have you built the cross function database?  If you have there is a
command that's useful.

$ ~/smatch/smatch_db/smdb.py functions vga_switcheroo_handler get_client_id | tee where
drivers/gpu/drm/nouveau/nouveau_acpi.c | (struct vga_switcheroo_handler)->get_client_id | nouveau_dsm_get_client_id | 1
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | amdgpu_atpx_get_client_id | 1
drivers/gpu/drm/radeon/radeon_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | radeon_atpx_get_client_id | 1
drivers/platform/x86/apple-gmux.c | (struct vga_switcheroo_handler)->get_client_id | gmux_get_client_id | 1
$ make cscope
$ vim where
Use cscope to jump to each of those four functions.  Move the cursor to
the nouveau_dsm_get_client_id and hit CTRL-].

They never return negatives.  The enum vga_switcheroo_client_id has a
VGA_SWITCHEROO_UNKNOWN_ID define which I guess these functions are
supposed to return on error.  They never do return that, but I bet
that's what we are supposed to check for.  It honestly might be good
to check for both...

		if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) {
			mutex_unlock(&vgasr_mutex);
			return -EINVAL;
		}

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
@ 2023-10-26  4:44   ` Dan Carpenter
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-26  4:44 UTC (permalink / raw)
  To: Su Hui
  Cc: tzimmermann, kernel-janitors, linux-kernel, mripard, Jim.Qu, dri-devel

On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
> 'id' is enum type like unsigned int, so it will never be less than zero.
> 
> Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  drivers/gpu/vga/vga_switcheroo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> index 365e6ddbe90f..d3064466fd3a 100644
> --- a/drivers/gpu/vga/vga_switcheroo.c
> +++ b/drivers/gpu/vga/vga_switcheroo.c
> @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
>  	mutex_lock(&vgasr_mutex);
>  	if (vgasr_priv.active) {
>  		id = vgasr_priv.handler->get_client_id(vga_dev);
> -		if (id < 0) {
> +		if ((int)id < 0) {

Hi,

I feel like you're using Smatch?  Which is great!  Fantastic!

Have you built the cross function database?  If you have there is a
command that's useful.

$ ~/smatch/smatch_db/smdb.py functions vga_switcheroo_handler get_client_id | tee where
drivers/gpu/drm/nouveau/nouveau_acpi.c | (struct vga_switcheroo_handler)->get_client_id | nouveau_dsm_get_client_id | 1
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | amdgpu_atpx_get_client_id | 1
drivers/gpu/drm/radeon/radeon_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | radeon_atpx_get_client_id | 1
drivers/platform/x86/apple-gmux.c | (struct vga_switcheroo_handler)->get_client_id | gmux_get_client_id | 1
$ make cscope
$ vim where
Use cscope to jump to each of those four functions.  Move the cursor to
the nouveau_dsm_get_client_id and hit CTRL-].

They never return negatives.  The enum vga_switcheroo_client_id has a
VGA_SWITCHEROO_UNKNOWN_ID define which I guess these functions are
supposed to return on error.  They never do return that, but I bet
that's what we are supposed to check for.  It honestly might be good
to check for both...

		if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) {
			mutex_unlock(&vgasr_mutex);
			return -EINVAL;
		}

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
  2023-10-26  4:44   ` Dan Carpenter
@ 2023-10-26  8:46     ` Su Hui
  -1 siblings, 0 replies; 8+ messages in thread
From: Su Hui @ 2023-10-26  8:46 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: lukas, maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
	tiwai, Jim.Qu, dri-devel, linux-kernel, kernel-janitors

On 2023/10/26 12:44, Dan Carpenter wrote:
> On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
>> 'id' is enum type like unsigned int, so it will never be less than zero.
>>
>> Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
>> Signed-off-by: Su Hui <suhui@nfschina.com>
>> ---
>>   drivers/gpu/vga/vga_switcheroo.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
>> index 365e6ddbe90f..d3064466fd3a 100644
>> --- a/drivers/gpu/vga/vga_switcheroo.c
>> +++ b/drivers/gpu/vga/vga_switcheroo.c
>> @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
>>   	mutex_lock(&vgasr_mutex);
>>   	if (vgasr_priv.active) {
>>   		id = vgasr_priv.handler->get_client_id(vga_dev);
>> -		if (id < 0) {
>> +		if ((int)id < 0) {
> Hi,
>
> I feel like you're using Smatch?  Which is great!  Fantastic!
Yep, Smatch helps me  a lot to find these bugs! I really like this 
excellent tool!
>
> Have you built the cross function database?  If you have there is a
> command that's useful.
Not yet, bu I want to build this.
> $ ~/smatch/smatch_db/smdb.py functions vga_switcheroo_handler get_client_id | tee where
> drivers/gpu/drm/nouveau/nouveau_acpi.c | (struct vga_switcheroo_handler)->get_client_id | nouveau_dsm_get_client_id | 1
> drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | amdgpu_atpx_get_client_id | 1
> drivers/gpu/drm/radeon/radeon_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | radeon_atpx_get_client_id | 1
> drivers/platform/x86/apple-gmux.c | (struct vga_switcheroo_handler)->get_client_id | gmux_get_client_id | 1
> $ make cscope
> $ vim where
> Use cscope to jump to each of those four functions.  Move the cursor to
> the nouveau_dsm_get_client_id and hit CTRL-].
Sounds great! I must try this!
>
> They never return negatives.  The enum vga_switcheroo_client_id has a
> VGA_SWITCHEROO_UNKNOWN_ID define which I guess these functions are
> supposed to return on error.  They never do return that, but I bet
> that's what we are supposed to check for.  It honestly might be good
> to check for both...
>
> 		if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) {
> 			mutex_unlock(&vgasr_mutex);
> 			return -EINVAL;
> 		}
Agreed, I will send v2 patch soon.
Really thanks for your wonderful suggestion! :)

Su Hui

> regards,
> dan carpenter
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
@ 2023-10-26  8:46     ` Su Hui
  0 siblings, 0 replies; 8+ messages in thread
From: Su Hui @ 2023-10-26  8:46 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: tzimmermann, kernel-janitors, linux-kernel, mripard, Jim.Qu, dri-devel

On 2023/10/26 12:44, Dan Carpenter wrote:
> On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
>> 'id' is enum type like unsigned int, so it will never be less than zero.
>>
>> Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
>> Signed-off-by: Su Hui <suhui@nfschina.com>
>> ---
>>   drivers/gpu/vga/vga_switcheroo.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
>> index 365e6ddbe90f..d3064466fd3a 100644
>> --- a/drivers/gpu/vga/vga_switcheroo.c
>> +++ b/drivers/gpu/vga/vga_switcheroo.c
>> @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
>>   	mutex_lock(&vgasr_mutex);
>>   	if (vgasr_priv.active) {
>>   		id = vgasr_priv.handler->get_client_id(vga_dev);
>> -		if (id < 0) {
>> +		if ((int)id < 0) {
> Hi,
>
> I feel like you're using Smatch?  Which is great!  Fantastic!
Yep, Smatch helps me  a lot to find these bugs! I really like this 
excellent tool!
>
> Have you built the cross function database?  If you have there is a
> command that's useful.
Not yet, bu I want to build this.
> $ ~/smatch/smatch_db/smdb.py functions vga_switcheroo_handler get_client_id | tee where
> drivers/gpu/drm/nouveau/nouveau_acpi.c | (struct vga_switcheroo_handler)->get_client_id | nouveau_dsm_get_client_id | 1
> drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | amdgpu_atpx_get_client_id | 1
> drivers/gpu/drm/radeon/radeon_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | radeon_atpx_get_client_id | 1
> drivers/platform/x86/apple-gmux.c | (struct vga_switcheroo_handler)->get_client_id | gmux_get_client_id | 1
> $ make cscope
> $ vim where
> Use cscope to jump to each of those four functions.  Move the cursor to
> the nouveau_dsm_get_client_id and hit CTRL-].
Sounds great! I must try this!
>
> They never return negatives.  The enum vga_switcheroo_client_id has a
> VGA_SWITCHEROO_UNKNOWN_ID define which I guess these functions are
> supposed to return on error.  They never do return that, but I bet
> that's what we are supposed to check for.  It honestly might be good
> to check for both...
>
> 		if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) {
> 			mutex_unlock(&vgasr_mutex);
> 			return -EINVAL;
> 		}
Agreed, I will send v2 patch soon.
Really thanks for your wonderful suggestion! :)

Su Hui

> regards,
> dan carpenter
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
  2023-10-26  8:46     ` Su Hui
@ 2023-10-26  9:04       ` Dan Carpenter
  -1 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-26  9:04 UTC (permalink / raw)
  To: Su Hui
  Cc: lukas, maarten.lankhorst, mripard, tzimmermann, airlied, daniel,
	tiwai, Jim.Qu, dri-devel, linux-kernel, kernel-janitors

On Thu, Oct 26, 2023 at 04:46:29PM +0800, Su Hui wrote:
> On 2023/10/26 12:44, Dan Carpenter wrote:
> > On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
> > > 'id' is enum type like unsigned int, so it will never be less than zero.
> > > 
> > > Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
> > > Signed-off-by: Su Hui <suhui@nfschina.com>
> > > ---
> > >   drivers/gpu/vga/vga_switcheroo.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> > > index 365e6ddbe90f..d3064466fd3a 100644
> > > --- a/drivers/gpu/vga/vga_switcheroo.c
> > > +++ b/drivers/gpu/vga/vga_switcheroo.c
> > > @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
> > >   	mutex_lock(&vgasr_mutex);
> > >   	if (vgasr_priv.active) {
> > >   		id = vgasr_priv.handler->get_client_id(vga_dev);
> > > -		if (id < 0) {
> > > +		if ((int)id < 0) {
> > Hi,
> > 
> > I feel like you're using Smatch?  Which is great!  Fantastic!
> Yep, Smatch helps me  a lot to find these bugs! I really like this excellent
> tool!
> > 
> > Have you built the cross function database?  If you have there is a
> > command that's useful.
> Not yet, bu I want to build this.

Yeah.  It's super useful for kernel development.  It helps to understand
how functions are called and where variables are set etc.  The smatch
documentation is crap, I know.  But I did write a short blog about the
cross function DB.

https://staticthinking.wordpress.com/2023/05/02/the-cross-function-db/

It's simple to build, but it takes a long time.  Just run
smatch_scripts/build_kernel_data.sh

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] vga_switcheroo: Fix impossible judgment condition
@ 2023-10-26  9:04       ` Dan Carpenter
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2023-10-26  9:04 UTC (permalink / raw)
  To: Su Hui
  Cc: tzimmermann, kernel-janitors, linux-kernel, mripard, Jim.Qu, dri-devel

On Thu, Oct 26, 2023 at 04:46:29PM +0800, Su Hui wrote:
> On 2023/10/26 12:44, Dan Carpenter wrote:
> > On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote:
> > > 'id' is enum type like unsigned int, so it will never be less than zero.
> > > 
> > > Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id")
> > > Signed-off-by: Su Hui <suhui@nfschina.com>
> > > ---
> > >   drivers/gpu/vga/vga_switcheroo.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> > > index 365e6ddbe90f..d3064466fd3a 100644
> > > --- a/drivers/gpu/vga/vga_switcheroo.c
> > > +++ b/drivers/gpu/vga/vga_switcheroo.c
> > > @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
> > >   	mutex_lock(&vgasr_mutex);
> > >   	if (vgasr_priv.active) {
> > >   		id = vgasr_priv.handler->get_client_id(vga_dev);
> > > -		if (id < 0) {
> > > +		if ((int)id < 0) {
> > Hi,
> > 
> > I feel like you're using Smatch?  Which is great!  Fantastic!
> Yep, Smatch helps me  a lot to find these bugs! I really like this excellent
> tool!
> > 
> > Have you built the cross function database?  If you have there is a
> > command that's useful.
> Not yet, bu I want to build this.

Yeah.  It's super useful for kernel development.  It helps to understand
how functions are called and where variables are set etc.  The smatch
documentation is crap, I know.  But I did write a short blog about the
cross function DB.

https://staticthinking.wordpress.com/2023/05/02/the-cross-function-db/

It's simple to build, but it takes a long time.  Just run
smatch_scripts/build_kernel_data.sh

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-26  9:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26  2:10 [PATCH] vga_switcheroo: Fix impossible judgment condition Su Hui
2023-10-26  2:10 ` Su Hui
2023-10-26  4:44 ` Dan Carpenter
2023-10-26  4:44   ` Dan Carpenter
2023-10-26  8:46   ` Su Hui
2023-10-26  8:46     ` Su Hui
2023-10-26  9:04     ` Dan Carpenter
2023-10-26  9:04       ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.