[PATCH] Drivers: hv: mshv: Fix uninitialized variable in hv_call_map_stat_page()

Dan Carpenter posted 1 patch 9 months ago
drivers/hv/mshv_root_hv_call.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] Drivers: hv: mshv: Fix uninitialized variable in hv_call_map_stat_page()
Posted by Dan Carpenter 9 months ago
If the hv_do_hypercall() succeeds on the first iteration then "ret" is
not initialized.  I re-arranged this code to make the loop clearer and
to make it more clear that we return zero on the last line.

Fixes: f5288d14069b ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/hv/mshv_root_hv_call.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
index b72b59a5068b..a74e13a32183 100644
--- a/drivers/hv/mshv_root_hv_call.c
+++ b/drivers/hv/mshv_root_hv_call.c
@@ -733,7 +733,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 	u64 status, pfn;
 	int ret;
 
-	do {
+	while (1) {
 		local_irq_save(flags);
 		input = *this_cpu_ptr(hyperv_pcpu_input_arg);
 		output = *this_cpu_ptr(hyperv_pcpu_output_arg);
@@ -756,11 +756,11 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
 					    hv_current_partition_id, 1);
 		if (ret)
 			return ret;
-	} while (!ret);
+	}
 
 	*addr = page_address(pfn_to_page(pfn));
 
-	return ret;
+	return 0;
 }
 
 int hv_call_unmap_stat_page(enum hv_stats_object_type type,
-- 
2.47.2
Re: [PATCH] Drivers: hv: mshv: Fix uninitialized variable in hv_call_map_stat_page()
Posted by Nuno Das Neves 9 months ago
On 3/21/2025 7:35 AM, Dan Carpenter wrote:
> If the hv_do_hypercall() succeeds on the first iteration then "ret" is
> not initialized.  I re-arranged this code to make the loop clearer and
> to make it more clear that we return zero on the last line.
> 
> Fixes: f5288d14069b ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/hv/mshv_root_hv_call.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> index b72b59a5068b..a74e13a32183 100644
> --- a/drivers/hv/mshv_root_hv_call.c
> +++ b/drivers/hv/mshv_root_hv_call.c
> @@ -733,7 +733,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
>  	u64 status, pfn;
>  	int ret;
>  
> -	do {
> +	while (1) {
>  		local_irq_save(flags);
>  		input = *this_cpu_ptr(hyperv_pcpu_input_arg);
>  		output = *this_cpu_ptr(hyperv_pcpu_output_arg);
> @@ -756,11 +756,11 @@ int hv_call_map_stat_page(enum hv_stats_object_type type,
>  					    hv_current_partition_id, 1);
>  		if (ret)
>  			return ret;
> -	} while (!ret);
> +	}
>  
>  	*addr = page_address(pfn_to_page(pfn));
>  
> -	return ret;
> +	return 0;
>  }
>  
>  int hv_call_unmap_stat_page(enum hv_stats_object_type type,

Thanks Dan, I already sent a fixup for this:
https://lore.kernel.org/linux-hyperv/1742492693-21960-1-git-send-email-nunodasneves@linux.microsoft.com/