[PATCH 1/2] riscv: Fix sparse warning in __get_user_error()

Alexandre Ghiti posted 2 patches 4 weeks, 1 day ago
[PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
Posted by Alexandre Ghiti 4 weeks, 1 day ago
We used to assign 0 to x without an appropriate cast which results in
sparse complaining when x is a pointer:

>> block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer

So fix this by casting 0 to the correct type of x.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202508062321.gHv4kvuY-lkp@intel.com/
Fixes: f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
Cc: stable@vger.kernel.org
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 arch/riscv/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644
--- a/arch/riscv/include/asm/uaccess.h
+++ b/arch/riscv/include/asm/uaccess.h
@@ -209,7 +209,7 @@ do {									\
 		err = 0;						\
 		break;							\
 __gu_failed:								\
-		x = 0;							\
+		x = (__typeof__(x))0;					\
 		err = -EFAULT;						\
 } while (0)
 

-- 
2.34.1
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
Posted by Paul Walmsley 1 week, 6 days ago
On Wed, 3 Sep 2025, Alexandre Ghiti wrote:

> We used to assign 0 to x without an appropriate cast which results in
> sparse complaining when x is a pointer:
> 
> >> block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
> 
> So fix this by casting 0 to the correct type of x.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202508062321.gHv4kvuY-lkp@intel.com/
> Fixes: f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/include/asm/uaccess.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, this one was sent upstream as part of the last fixes PR.

- Paul
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
Posted by Paul Walmsley 3 weeks, 6 days ago
On Wed, 3 Sep 2025, Alexandre Ghiti wrote:

> We used to assign 0 to x without an appropriate cast which results in
> sparse complaining when x is a pointer:
> 
> >> block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
> 
> So fix this by casting 0 to the correct type of x.

Thanks, queued for v6.17-rc fixes.

- Paul
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
Posted by Clément Léger 4 weeks ago

On 03/09/2025 20:53, Alexandre Ghiti wrote:
> We used to assign 0 to x without an appropriate cast which results in
> sparse complaining when x is a pointer:
> 
>>> block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
> 
> So fix this by casting 0 to the correct type of x.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202508062321.gHv4kvuY-lkp@intel.com/
> Fixes: f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/include/asm/uaccess.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
> index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644
> --- a/arch/riscv/include/asm/uaccess.h
> +++ b/arch/riscv/include/asm/uaccess.h
> @@ -209,7 +209,7 @@ do {									\
>  		err = 0;						\
>  		break;							\
>  __gu_failed:								\
> -		x = 0;							\
> +		x = (__typeof__(x))0;					\
>  		err = -EFAULT;						\
>  } while (0)
>  
> 

Hi Alex,

I applied that and checked that the sparse warnings were fixed as well,
looks good to me.

Reviewed-by: Clément Léger <cleger@rivosinc.com>

Thanks,

Clément
Re: [PATCH 1/2] riscv: Fix sparse warning in __get_user_error()
Posted by Cyril Bur 4 weeks, 1 day ago
These two are on me. Sorry.

Thanks for fixing them Alexandre.

On 4/9/2025 4:53 am, Alexandre Ghiti wrote:
> We used to assign 0 to x without an appropriate cast which results in
> sparse complaining when x is a pointer:
> 
>>> block/ioctl.c:72:39: sparse: sparse: Using plain integer as NULL pointer
> 
> So fix this by casting 0 to the correct type of x.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202508062321.gHv4kvuY-lkp@intel.com/
> Fixes: f6bff7827a48 ("riscv: uaccess: use 'asm_goto_output' for get_user()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Reviewed-by: Cyril Bur <cyrilbur@tenstorrent.com>

> ---
>   arch/riscv/include/asm/uaccess.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
> index 22e3f52a763d1c0350e8185225e4c99aac3fc549..551e7490737effb2c238e6a4db50293ece7c9df9 100644
> --- a/arch/riscv/include/asm/uaccess.h
> +++ b/arch/riscv/include/asm/uaccess.h
> @@ -209,7 +209,7 @@ do {									\
>   		err = 0;						\
>   		break;							\
>   __gu_failed:								\
> -		x = 0;							\
> +		x = (__typeof__(x))0;					\
>   		err = -EFAULT;						\
>   } while (0)
>   
>