diff mbox series

[-next,v2,1/2] watchdog: Clean up error handlings of __watchdog_register_device

Message ID 20201103065217.67876-1-wangwensheng4@huawei.com (mailing list archive)
State Superseded
Headers show
Series [-next,v2,1/2] watchdog: Clean up error handlings of __watchdog_register_device | expand

Commit Message

Wang Wensheng Nov. 3, 2020, 6:52 a.m. UTC
Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
---
 drivers/watchdog/watchdog_core.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Christophe Leroy Nov. 3, 2020, 7:05 a.m. UTC | #1
Hi,

Can you provide in the commit a description of what you are doing and why ?

Christophe

Le 03/11/2020 à 07:52, Wang Wensheng a écrit :
> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
> ---
>   drivers/watchdog/watchdog_core.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
> index 423844757812..c73871f41142 100644
> --- a/drivers/watchdog/watchdog_core.c
> +++ b/drivers/watchdog/watchdog_core.c
> @@ -252,10 +252,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>   		wdd->id = id;
>   
>   		ret = watchdog_dev_register(wdd);
> -		if (ret) {
> -			ida_simple_remove(&watchdog_ida, id);
> -			return ret;
> -		}
> +		if (ret)
> +			goto id_remove;
>   	}
>   
>   	/* Module parameter to force watchdog policy on reboot. */
> @@ -273,9 +271,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>   		if (ret) {
>   			pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
>   			       wdd->id, ret);
> -			watchdog_dev_unregister(wdd);
> -			ida_simple_remove(&watchdog_ida, id);
> -			return ret;
> +			goto dev_unregister;
>   		}
>   	}
>   
> @@ -289,6 +285,13 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>   	}
>   
>   	return 0;
> +
> +dev_unregister:
> +	watchdog_dev_unregister(wdd);
> +id_remove:
> +	ida_simple_remove(&watchdog_ida, id);
> +
> +	return ret;
>   }
>   
>   /**
>
Guenter Roeck Nov. 3, 2020, 1:05 p.m. UTC | #2
On 11/2/20 11:05 PM, Christophe Leroy wrote:
> Hi,
> 
> Can you provide in the commit a description of what you are doing and why ?
> 

Also, I'd rather have this as second patch to make it easier (possible, actually)
to apply the first patch to -stable.

Guenter

> Christophe
> 
> Le 03/11/2020 à 07:52, Wang Wensheng a écrit :
>> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
>> ---
>>   drivers/watchdog/watchdog_core.c | 17 ++++++++++-------
>>   1 file changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
>> index 423844757812..c73871f41142 100644
>> --- a/drivers/watchdog/watchdog_core.c
>> +++ b/drivers/watchdog/watchdog_core.c
>> @@ -252,10 +252,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>>           wdd->id = id;
>>             ret = watchdog_dev_register(wdd);
>> -        if (ret) {
>> -            ida_simple_remove(&watchdog_ida, id);
>> -            return ret;
>> -        }
>> +        if (ret)
>> +            goto id_remove;
>>       }
>>         /* Module parameter to force watchdog policy on reboot. */
>> @@ -273,9 +271,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>>           if (ret) {
>>               pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
>>                      wdd->id, ret);
>> -            watchdog_dev_unregister(wdd);
>> -            ida_simple_remove(&watchdog_ida, id);
>> -            return ret;
>> +            goto dev_unregister;
>>           }
>>       }
>>   @@ -289,6 +285,13 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>>       }
>>         return 0;
>> +
>> +dev_unregister:
>> +    watchdog_dev_unregister(wdd);
>> +id_remove:
>> +    ida_simple_remove(&watchdog_ida, id);
>> +
>> +    return ret;
>>   }
>>     /**
>>
diff mbox series

Patch

diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 423844757812..c73871f41142 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -252,10 +252,8 @@  static int __watchdog_register_device(struct watchdog_device *wdd)
 		wdd->id = id;
 
 		ret = watchdog_dev_register(wdd);
-		if (ret) {
-			ida_simple_remove(&watchdog_ida, id);
-			return ret;
-		}
+		if (ret)
+			goto id_remove;
 	}
 
 	/* Module parameter to force watchdog policy on reboot. */
@@ -273,9 +271,7 @@  static int __watchdog_register_device(struct watchdog_device *wdd)
 		if (ret) {
 			pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
 			       wdd->id, ret);
-			watchdog_dev_unregister(wdd);
-			ida_simple_remove(&watchdog_ida, id);
-			return ret;
+			goto dev_unregister;
 		}
 	}
 
@@ -289,6 +285,13 @@  static int __watchdog_register_device(struct watchdog_device *wdd)
 	}
 
 	return 0;
+
+dev_unregister:
+	watchdog_dev_unregister(wdd);
+id_remove:
+	ida_simple_remove(&watchdog_ida, id);
+
+	return ret;
 }
 
 /**