linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] stm class: dummy_stm: Fix error return code in dummy_stm_init()
@ 2021-05-08  2:36 Zhen Lei
  2021-07-15  9:21 ` Leizhen (ThunderTown)
  0 siblings, 1 reply; 2+ messages in thread
From: Zhen Lei @ 2021-05-08  2:36 UTC (permalink / raw)
  To: Alexander Shishkin, Maxime Coquelin, Alexandre Torgue,
	Greg Kroah-Hartman, linux-stm32, linux-arm-kernel, linux-kernel
  Cc: Zhen Lei

Although 'ret' has been initialized to -ENOMEM, but it will be reassigned
by the "ret = stm_register_device(...)" statement in the for loop. So
that, the value of 'ret' is unknown when kasprintf() failed.

Fixes: bcfdf8afdebe ("stm class: dummy_stm: Create multiple devices")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 drivers/hwtracing/stm/dummy_stm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/stm/dummy_stm.c b/drivers/hwtracing/stm/dummy_stm.c
index 38528ffdc0b3..36d32e7afb35 100644
--- a/drivers/hwtracing/stm/dummy_stm.c
+++ b/drivers/hwtracing/stm/dummy_stm.c
@@ -68,7 +68,7 @@ static int dummy_stm_link(struct stm_data *data, unsigned int master,
 
 static int dummy_stm_init(void)
 {
-	int i, ret = -ENOMEM;
+	int i, ret;
 
 	if (nr_dummies < 0 || nr_dummies > DUMMY_STM_MAX)
 		return -EINVAL;
@@ -80,8 +80,10 @@ static int dummy_stm_init(void)
 
 	for (i = 0; i < nr_dummies; i++) {
 		dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i);
-		if (!dummy_stm[i].name)
+		if (!dummy_stm[i].name) {
+			ret = -ENOMEM;
 			goto fail_unregister;
+		}
 
 		dummy_stm[i].sw_start		= master_min;
 		dummy_stm[i].sw_end		= master_max;
-- 
2.25.1



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

* Re: [PATCH 1/1] stm class: dummy_stm: Fix error return code in dummy_stm_init()
  2021-05-08  2:36 [PATCH 1/1] stm class: dummy_stm: Fix error return code in dummy_stm_init() Zhen Lei
@ 2021-07-15  9:21 ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 2+ messages in thread
From: Leizhen (ThunderTown) @ 2021-07-15  9:21 UTC (permalink / raw)
  To: Alexander Shishkin, Maxime Coquelin, Alexandre Torgue,
	Greg Kroah-Hartman, linux-stm32, linux-arm-kernel, linux-kernel

Hi all:
  Can someone review it? Although it is unlikely that the OOM will
occur during initialization, this is indeed a coding error.

On 2021/5/8 10:36, Zhen Lei wrote:
> Although 'ret' has been initialized to -ENOMEM, but it will be reassigned
> by the "ret = stm_register_device(...)" statement in the for loop. So
> that, the value of 'ret' is unknown when kasprintf() failed.
> 
> Fixes: bcfdf8afdebe ("stm class: dummy_stm: Create multiple devices")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  drivers/hwtracing/stm/dummy_stm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwtracing/stm/dummy_stm.c b/drivers/hwtracing/stm/dummy_stm.c
> index 38528ffdc0b3..36d32e7afb35 100644
> --- a/drivers/hwtracing/stm/dummy_stm.c
> +++ b/drivers/hwtracing/stm/dummy_stm.c
> @@ -68,7 +68,7 @@ static int dummy_stm_link(struct stm_data *data, unsigned int master,
>  
>  static int dummy_stm_init(void)
>  {
> -	int i, ret = -ENOMEM;
> +	int i, ret;
>  
>  	if (nr_dummies < 0 || nr_dummies > DUMMY_STM_MAX)
>  		return -EINVAL;
> @@ -80,8 +80,10 @@ static int dummy_stm_init(void)
>  
>  	for (i = 0; i < nr_dummies; i++) {
>  		dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i);
> -		if (!dummy_stm[i].name)
> +		if (!dummy_stm[i].name) {
> +			ret = -ENOMEM;
>  			goto fail_unregister;
> +		}
>  
>  		dummy_stm[i].sw_start		= master_min;
>  		dummy_stm[i].sw_end		= master_max;
> 

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

end of thread, other threads:[~2021-07-15  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-08  2:36 [PATCH 1/1] stm class: dummy_stm: Fix error return code in dummy_stm_init() Zhen Lei
2021-07-15  9:21 ` Leizhen (ThunderTown)

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