dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
@ 2025-04-10 11:02 Purva Yeshi
  2025-04-10 19:40 ` Vinicius Costa Gomes
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Purva Yeshi @ 2025-04-10 11:02 UTC (permalink / raw)
  To: vinicius.gomes, dave.jiang, vkoul; +Cc: dmaengine, linux-kernel, Purva Yeshi

Fix Smatch-detected issue:
drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
uninitialized symbol 'sva'.

'sva' pointer may be used uninitialized in error handling paths.
Specifically, if PASID support is enabled and iommu_sva_bind_device()
returns an error, the code jumps to the cleanup label and attempts to
call iommu_sva_unbind_device(sva) without ensuring that sva was
successfully assigned. This triggers a Smatch warning about an
uninitialized symbol.

Initialize sva to NULL at declaration and add a check using
IS_ERR_OR_NULL() before unbinding the device. This ensures the
function does not use an invalid or uninitialized pointer during
cleanup.

Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
 drivers/dma/idxd/cdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index ff94ee892339..7bd031a60894 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
 	struct idxd_wq *wq;
 	struct device *dev, *fdev;
 	int rc = 0;
-	struct iommu_sva *sva;
+	struct iommu_sva *sva = NULL;
 	unsigned int pasid;
 	struct idxd_cdev *idxd_cdev;
 
@@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
 	if (device_user_pasid_enabled(idxd))
 		idxd_xa_pasid_remove(ctx);
 failed_get_pasid:
-	if (device_user_pasid_enabled(idxd))
+	if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))
 		iommu_sva_unbind_device(sva);
 failed:
 	mutex_unlock(&wq->wq_lock);
-- 
2.34.1


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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-10 11:02 [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open Purva Yeshi
@ 2025-04-10 19:40 ` Vinicius Costa Gomes
  2025-04-10 19:56   ` Purva Yeshi
  2025-04-10 21:00 ` Dave Jiang
  2025-04-17 15:18 ` Vinod Koul
  2 siblings, 1 reply; 7+ messages in thread
From: Vinicius Costa Gomes @ 2025-04-10 19:40 UTC (permalink / raw)
  To: Purva Yeshi, dave.jiang, vkoul; +Cc: dmaengine, linux-kernel, Purva Yeshi

Purva Yeshi <purvayeshi550@gmail.com> writes:

> Fix Smatch-detected issue:
> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
> uninitialized symbol 'sva'.
>
> 'sva' pointer may be used uninitialized in error handling paths.
> Specifically, if PASID support is enabled and iommu_sva_bind_device()
> returns an error, the code jumps to the cleanup label and attempts to
> call iommu_sva_unbind_device(sva) without ensuring that sva was
> successfully assigned. This triggers a Smatch warning about an
> uninitialized symbol.
>
> Initialize sva to NULL at declaration and add a check using
> IS_ERR_OR_NULL() before unbinding the device. This ensures the
> function does not use an invalid or uninitialized pointer during
> cleanup.
>
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> ---
>  drivers/dma/idxd/cdev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index ff94ee892339..7bd031a60894 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	struct idxd_wq *wq;
>  	struct device *dev, *fdev;
>  	int rc = 0;
> -	struct iommu_sva *sva;
> +	struct iommu_sva *sva = NULL;
>  	unsigned int pasid;
>  	struct idxd_cdev *idxd_cdev;
>  
> @@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	if (device_user_pasid_enabled(idxd))
>  		idxd_xa_pasid_remove(ctx);
>  failed_get_pasid:
> -	if (device_user_pasid_enabled(idxd))
> +	if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))

Optional: I would change this to only checking for the validity of
'sva', the other condition would be true if 'sva' is valid.

But for consistency with the condition above, I am not opposed to the
way this patch is written:

Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>


Cheers,
-- 
Vinicius

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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-10 19:40 ` Vinicius Costa Gomes
@ 2025-04-10 19:56   ` Purva Yeshi
  0 siblings, 0 replies; 7+ messages in thread
From: Purva Yeshi @ 2025-04-10 19:56 UTC (permalink / raw)
  To: Vinicius Costa Gomes, dave.jiang, vkoul; +Cc: dmaengine, linux-kernel

On 11/04/25 01:10, Vinicius Costa Gomes wrote:
> Purva Yeshi <purvayeshi550@gmail.com> writes:
> 
>> Fix Smatch-detected issue:
>> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
>> uninitialized symbol 'sva'.
>>
>> 'sva' pointer may be used uninitialized in error handling paths.
>> Specifically, if PASID support is enabled and iommu_sva_bind_device()
>> returns an error, the code jumps to the cleanup label and attempts to
>> call iommu_sva_unbind_device(sva) without ensuring that sva was
>> successfully assigned. This triggers a Smatch warning about an
>> uninitialized symbol.
>>
>> Initialize sva to NULL at declaration and add a check using
>> IS_ERR_OR_NULL() before unbinding the device. This ensures the
>> function does not use an invalid or uninitialized pointer during
>> cleanup.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
>> ---
>>   drivers/dma/idxd/cdev.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
>> index ff94ee892339..7bd031a60894 100644
>> --- a/drivers/dma/idxd/cdev.c
>> +++ b/drivers/dma/idxd/cdev.c
>> @@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>>   	struct idxd_wq *wq;
>>   	struct device *dev, *fdev;
>>   	int rc = 0;
>> -	struct iommu_sva *sva;
>> +	struct iommu_sva *sva = NULL;
>>   	unsigned int pasid;
>>   	struct idxd_cdev *idxd_cdev;
>>   
>> @@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>>   	if (device_user_pasid_enabled(idxd))
>>   		idxd_xa_pasid_remove(ctx);
>>   failed_get_pasid:
>> -	if (device_user_pasid_enabled(idxd))
>> +	if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))
> 
> Optional: I would change this to only checking for the validity of
> 'sva', the other condition would be true if 'sva' is valid.
> 
> But for consistency with the condition above, I am not opposed to the
> way this patch is written:
> 
> Acked-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
> 
> 
> Cheers,

Hi Vinicius,

Thank you for the review and the Acked-by tag.
I appreciate your feedback on the conditional check.

Best regards,
Purva

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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-10 11:02 [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open Purva Yeshi
  2025-04-10 19:40 ` Vinicius Costa Gomes
@ 2025-04-10 21:00 ` Dave Jiang
  2025-04-17  5:39   ` Purva Yeshi
  2025-04-17 15:18 ` Vinod Koul
  2 siblings, 1 reply; 7+ messages in thread
From: Dave Jiang @ 2025-04-10 21:00 UTC (permalink / raw)
  To: Purva Yeshi, vinicius.gomes, vkoul; +Cc: dmaengine, linux-kernel



On 4/10/25 4:02 AM, Purva Yeshi wrote:
> Fix Smatch-detected issue:
> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
> uninitialized symbol 'sva'.
> 
> 'sva' pointer may be used uninitialized in error handling paths.
> Specifically, if PASID support is enabled and iommu_sva_bind_device()
> returns an error, the code jumps to the cleanup label and attempts to
> call iommu_sva_unbind_device(sva) without ensuring that sva was
> successfully assigned. This triggers a Smatch warning about an
> uninitialized symbol.
> 
> Initialize sva to NULL at declaration and add a check using
> IS_ERR_OR_NULL() before unbinding the device. This ensures the
> function does not use an invalid or uninitialized pointer during
> cleanup.
> 
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/dma/idxd/cdev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index ff94ee892339..7bd031a60894 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	struct idxd_wq *wq;
>  	struct device *dev, *fdev;
>  	int rc = 0;
> -	struct iommu_sva *sva;
> +	struct iommu_sva *sva = NULL;
>  	unsigned int pasid;
>  	struct idxd_cdev *idxd_cdev;
>  
> @@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>  	if (device_user_pasid_enabled(idxd))
>  		idxd_xa_pasid_remove(ctx);
>  failed_get_pasid:
> -	if (device_user_pasid_enabled(idxd))
> +	if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))
>  		iommu_sva_unbind_device(sva);
>  failed:
>  	mutex_unlock(&wq->wq_lock);


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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-10 21:00 ` Dave Jiang
@ 2025-04-17  5:39   ` Purva Yeshi
  0 siblings, 0 replies; 7+ messages in thread
From: Purva Yeshi @ 2025-04-17  5:39 UTC (permalink / raw)
  To: Dave Jiang, vinicius.gomes, vkoul; +Cc: dmaengine, linux-kernel

On 11/04/25 02:30, Dave Jiang wrote:
> 
> 
> On 4/10/25 4:02 AM, Purva Yeshi wrote:
>> Fix Smatch-detected issue:
>> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
>> uninitialized symbol 'sva'.
>>
>> 'sva' pointer may be used uninitialized in error handling paths.
>> Specifically, if PASID support is enabled and iommu_sva_bind_device()
>> returns an error, the code jumps to the cleanup label and attempts to
>> call iommu_sva_unbind_device(sva) without ensuring that sva was
>> successfully assigned. This triggers a Smatch warning about an
>> uninitialized symbol.
>>
>> Initialize sva to NULL at declaration and add a check using
>> IS_ERR_OR_NULL() before unbinding the device. This ensures the
>> function does not use an invalid or uninitialized pointer during
>> cleanup.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> 
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>

Hi Dave,

Thank you for the review and the Reviewed-by tag.

>> ---
>>   drivers/dma/idxd/cdev.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
>> index ff94ee892339..7bd031a60894 100644
>> --- a/drivers/dma/idxd/cdev.c
>> +++ b/drivers/dma/idxd/cdev.c
>> @@ -222,7 +222,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>>   	struct idxd_wq *wq;
>>   	struct device *dev, *fdev;
>>   	int rc = 0;
>> -	struct iommu_sva *sva;
>> +	struct iommu_sva *sva = NULL;
>>   	unsigned int pasid;
>>   	struct idxd_cdev *idxd_cdev;
>>   
>> @@ -317,7 +317,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
>>   	if (device_user_pasid_enabled(idxd))
>>   		idxd_xa_pasid_remove(ctx);
>>   failed_get_pasid:
>> -	if (device_user_pasid_enabled(idxd))
>> +	if (device_user_pasid_enabled(idxd) && !IS_ERR_OR_NULL(sva))
>>   		iommu_sva_unbind_device(sva);
>>   failed:
>>   	mutex_unlock(&wq->wq_lock);
> 

Best regards,
Purva

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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-10 11:02 [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open Purva Yeshi
  2025-04-10 19:40 ` Vinicius Costa Gomes
  2025-04-10 21:00 ` Dave Jiang
@ 2025-04-17 15:18 ` Vinod Koul
  2025-04-18  8:33   ` Purva Yeshi
  2 siblings, 1 reply; 7+ messages in thread
From: Vinod Koul @ 2025-04-17 15:18 UTC (permalink / raw)
  To: vinicius.gomes, dave.jiang, Purva Yeshi; +Cc: dmaengine, linux-kernel


On Thu, 10 Apr 2025 16:32:16 +0530, Purva Yeshi wrote:
> Fix Smatch-detected issue:
> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
> uninitialized symbol 'sva'.
> 
> 'sva' pointer may be used uninitialized in error handling paths.
> Specifically, if PASID support is enabled and iommu_sva_bind_device()
> returns an error, the code jumps to the cleanup label and attempts to
> call iommu_sva_unbind_device(sva) without ensuring that sva was
> successfully assigned. This triggers a Smatch warning about an
> uninitialized symbol.
> 
> [...]

Applied, thanks!

[1/1] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
      commit: 97994333de2b8062d2df4e6ce0dc65c2dc0f40dc

Best regards,
-- 
~Vinod



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

* Re: [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
  2025-04-17 15:18 ` Vinod Koul
@ 2025-04-18  8:33   ` Purva Yeshi
  0 siblings, 0 replies; 7+ messages in thread
From: Purva Yeshi @ 2025-04-18  8:33 UTC (permalink / raw)
  To: Vinod Koul, vinicius.gomes, dave.jiang; +Cc: dmaengine, linux-kernel

On 17/04/25 20:48, Vinod Koul wrote:
> 
> On Thu, 10 Apr 2025 16:32:16 +0530, Purva Yeshi wrote:
>> Fix Smatch-detected issue:
>> drivers/dma/idxd/cdev.c:321 idxd_cdev_open() error:
>> uninitialized symbol 'sva'.
>>
>> 'sva' pointer may be used uninitialized in error handling paths.
>> Specifically, if PASID support is enabled and iommu_sva_bind_device()
>> returns an error, the code jumps to the cleanup label and attempts to
>> call iommu_sva_unbind_device(sva) without ensuring that sva was
>> successfully assigned. This triggers a Smatch warning about an
>> uninitialized symbol.
>>
>> [...]
> 
> Applied, thanks!
> 
> [1/1] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open
>        commit: 97994333de2b8062d2df4e6ce0dc65c2dc0f40dc
> 
> Best regards,

Hi Vinod,

Thank you for applying the patch!

Best regards,
Purva

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

end of thread, other threads:[~2025-04-18  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 11:02 [PATCH] dma: idxd: cdev: Fix uninitialized use of sva in idxd_cdev_open Purva Yeshi
2025-04-10 19:40 ` Vinicius Costa Gomes
2025-04-10 19:56   ` Purva Yeshi
2025-04-10 21:00 ` Dave Jiang
2025-04-17  5:39   ` Purva Yeshi
2025-04-17 15:18 ` Vinod Koul
2025-04-18  8:33   ` Purva Yeshi

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).