gpio: Use traditional pattern when checking error codes
PATCH 1/1 gpio: Use traditional pattern when checking error codes
Instead of 'if (ret == 0)' switch to "check for the error first" rule.
---
While it gives a "+" (plus) statistics it makes the code easier to read and maintain (when, e.g., want to add somethning in between touched lines).
drivers/gpio/gpiolib.c | 104 ++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 48 deletions(-)
drivers/gpio/gpiolib.c +56 -48
@@ -2674,10 +2674,11 @@ int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) ret =gpio_set_config_with_argument_optional (desc,PIN_CONFIG_INPUT_DEBOUNCE , debounce); -if (!ret) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }/**
@@ -2697,16 +2698,17 @@ int gpiod_direction_input(struct gpio_desc *desc)VALIDATE_DESC (desc); ret =gpiod_direction_input_nonotify (desc); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_input);int gpiod_direction_input_nonotify (struct gpio_desc *desc) { -int ret =0 ; +int ret;CLASS (gpio_chip_guard, guard)(desc);if (!guard.gc)
@@ -2733,6 +2735,8 @@ int gpiod_direction_input_nonotify(struct gpio_desc *desc)if (guard.gc->direction_input) { ret = guard.gc->direction_input (guard.gc,gpio_chip_hwgpio (desc)); +if (ret) + goto out_trace_direction; }else if (guard.gc->get_direction && (guard.gc->get_direction (guard.gc,gpio_chip_hwgpio (desc)) !=1 )) {
@@ -2741,11 +2745,11 @@ int gpiod_direction_input_nonotify(struct gpio_desc *desc) __func__);return -EIO ; } -if (ret ==0 ) { -clear_bit (FLAG_IS_OUT , &desc->flags); - ret =gpio_set_bias (desc); - } +clear_bit (FLAG_IS_OUT , &desc->flags); + ret =gpio_set_bias (desc); + +out_trace_direction:trace_gpio_direction (desc_to_gpio (desc),1 , ret);return ret;
@@ -2774,6 +2778,8 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)if (guard.gc->direction_output) { ret = guard.gc->direction_output (guard.gc,gpio_chip_hwgpio (desc), val); +if (ret) + goto out_trace_value_and_direction; }else {/* Check that we are in output mode if we can */ if (guard.gc->get_direction &&
@@ -2790,8 +2796,9 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) guard.gc->set (guard.gc,gpio_chip_hwgpio (desc), val); } -if (!ret) -set_bit (FLAG_IS_OUT , &desc->flags); +set_bit (FLAG_IS_OUT , &desc->flags); + +out_trace_value_and_direction:trace_gpio_value (desc_to_gpio (desc),0 , val);trace_gpio_direction (desc_to_gpio (desc),0 , ret);return ret;
@@ -2816,10 +2823,11 @@ int gpiod_direction_output_raw(struct gpio_desc *desc, int value)VALIDATE_DESC (desc); ret =gpiod_direction_output_raw_commit (desc, value); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_output_raw);
@@ -2843,10 +2851,11 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)VALIDATE_DESC (desc); ret =gpiod_direction_output_nonotify (desc, value); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_output);
@@ -2877,19 +2886,15 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)if (!ret) goto set_output_value;/* Emulate open drain by not actively driving the line high */ -if (value) { - ret =gpiod_direction_input_nonotify (desc); +if (value) goto set_output_flag; - } }else if (test_bit (FLAG_OPEN_SOURCE , &flags)) { ret =gpio_set_config (desc,PIN_CONFIG_DRIVE_OPEN_SOURCE );if (!ret) goto set_output_value;/* Emulate open source by not actively driving the line low */ -if (!value) { - ret =gpiod_direction_input_nonotify (desc); +if (!value) goto set_output_flag; - } }else {gpio_set_config (desc,PIN_CONFIG_DRIVE_PUSH_PULL ); }
@@ -2901,15 +2906,17 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)return gpiod_direction_output_raw_commit (desc, value); set_output_flag: + ret =gpiod_direction_input_nonotify (desc); +if (ret) +return ret;/* * When emulating open-source or open-drain functionalities by not * actively driving the line (setting mode to input) we still need to * set the IS_OUT flag or otherwise we won't be able to set the line * value anymore. */ -if (ret ==0 ) -set_bit (FLAG_IS_OUT , &desc->flags); -return ret; +set_bit (FLAG_IS_OUT , &desc->flags); +return 0 ; }/**
@@ -2994,25 +3001,25 @@ int gpiod_set_config(struct gpio_desc *desc, unsigned long config)VALIDATE_DESC (desc); ret =gpio_do_set_config (desc, config); -if (!ret) { -/* These are the only options we notify the userspace about. */ -switch (pinconf_to_config_param (config)) { -case PIN_CONFIG_BIAS_DISABLE : -case PIN_CONFIG_BIAS_PULL_DOWN : -case PIN_CONFIG_BIAS_PULL_UP : -case PIN_CONFIG_DRIVE_OPEN_DRAIN : -case PIN_CONFIG_DRIVE_OPEN_SOURCE : -case PIN_CONFIG_DRIVE_PUSH_PULL : -case PIN_CONFIG_INPUT_DEBOUNCE : -gpiod_line_state_notify (desc, -GPIO_V2_LINE_CHANGED_CONFIG ); -break ; -default : -break ; - } +if (ret) +return ret; + +/* These are the only options we notify the userspace about */ +switch (pinconf_to_config_param (config)) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_DRIVE_OPEN_DRAIN : +case PIN_CONFIG_DRIVE_OPEN_SOURCE : +case PIN_CONFIG_DRIVE_PUSH_PULL : +case PIN_CONFIG_INPUT_DEBOUNCE : +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +break ; +default : +break ; } -return ret; +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_set_config);
@@ -3730,10 +3737,11 @@ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)VALIDATE_DESC (desc); ret =desc_set_label (desc, name); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_set_consumer_name);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Quoted 3 lines · Andy Shevchenko
Instead of 'if (ret == 0)' switch to "check for the error first" rule.
Signed-off-by Andy Shevchenko <[email protected]>
This makes a lot of sense.
Yours,
Linus Walleij
Quoted 2 lines · Andy Shevchenko
Instead of 'if (ret == 0)' switch to "check for the error first" rule.
Well there's much more to this patch than that and I have some issues with it.
Quoted 5 lines
Signed-off-by Andy Shevchenko <[email protected]>---
While it gives a "+" (plus) statistics it makes the code easier to read
Not only does it increase the footprint but it also adds completely unnecessary goto labels.
Quoted 2 lines
and maintain (when, e.g., want to add somethning in between touched lines).
The single line calls to the notifier chain are unlikely to be extended anytime soon but even then I think we should cross that bridge when we get there.
Quoted 10 lines
drivers/gpio/gpiolib.c | 104 ++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 48 deletions(-)drivers/gpio/gpiolib.c +0
-0@@ -2674,10 +2674,11 @@ int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) ret = gpio_set_config_with_argument_optional(desc, PIN_CONFIG_INPUT_DEBOUNCE,
drivers/gpio/gpiolib.c int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) · line 2682
Quoted 10 lines
drivers/gpio/gpiolib.c +4
-3debounce); -if (!ret) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }
I really don't see how this makes it better. The logic here is: if the underlying set config worked fine - emit the event. Otherwise continue with the function (even if there's nothing there now). If anything you're making it more difficult to modify later because logically the notification is just an optional step on the way to returning from the function.
drivers/gpio/gpiolib.c int gpiod_direction_input(struct gpio_desc *desc) · line 2703
Quoted 11 lines
drivers/gpio/gpiolib.c +2
-2/** @@ -2697,16 +2698,17 @@ int gpiod_direction_input(struct gpio_desc *desc)VALIDATE_DESC (desc); ret =gpiod_direction_input_nonotify (desc); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret;
Ok, for consistency I could take it but please put this into a separate commit doing just that (here and elsewhere).
Quoted 25 lines
drivers/gpio/gpiolib.c +5
-2-return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_input);int gpiod_direction_input_nonotify (struct gpio_desc *desc) { -int ret =0 ; +int ret;CLASS (gpio_chip_guard, guard)(desc);if (!guard.gc)@@ -2733,6 +2735,8 @@ int gpiod_direction_input_nonotify(struct gpio_desc *desc)if (guard.gc->direction_input) { ret = guard.gc->direction_input (guard.gc,gpio_chip_hwgpio (desc)); +if (ret) + goto out_trace_direction; }else if (guard.gc->get_direction && (guard.gc->get_direction (guard.gc,gpio_chip_hwgpio (desc)) !=1 )) {@@ -2741,11 +2745,11 @@ int gpiod_direction_input_nonotify(struct gpio_desc *desc) __func__);return -EIO ;
drivers/gpio/gpiolib.c int gpiod_direction_input_nonotify(struct gpio_desc *desc) · line 2752
Quoted 10 lines
drivers/gpio/gpiolib.c +4
-4} -if (ret ==0 ) { -clear_bit (FLAG_IS_OUT , &desc->flags); - ret =gpio_set_bias (desc); - } +clear_bit (FLAG_IS_OUT , &desc->flags); + ret =gpio_set_bias (desc); + +out_trace_direction:
This makes it worse! We can't just apply the "return fast" rule indiscriminately. Sometimes it does make sense to go "if the previous step worked, do this, otherwise keep going".
Also: adding more labels for no reason?
Quoted 77 lines
drivers/gpio/gpiolib.c +15
-14trace_gpio_direction (desc_to_gpio (desc),1 , ret);return ret;@@ -2774,6 +2778,8 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)if (guard.gc->direction_output) { ret = guard.gc->direction_output (guard.gc,gpio_chip_hwgpio (desc), val); +if (ret) + goto out_trace_value_and_direction; }else {/* Check that we are in output mode if we can */ if (guard.gc->get_direction &&@@ -2790,8 +2796,9 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) guard.gc->set (guard.gc,gpio_chip_hwgpio (desc), val); } -if (!ret) -set_bit (FLAG_IS_OUT , &desc->flags); +set_bit (FLAG_IS_OUT , &desc->flags); + +out_trace_value_and_direction:trace_gpio_value (desc_to_gpio (desc),0 , val);trace_gpio_direction (desc_to_gpio (desc),0 , ret);return ret;@@ -2816,10 +2823,11 @@ int gpiod_direction_output_raw(struct gpio_desc *desc, int value)VALIDATE_DESC (desc); ret =gpiod_direction_output_raw_commit (desc, value); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_output_raw);@@ -2843,10 +2851,11 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)VALIDATE_DESC (desc); ret =gpiod_direction_output_nonotify (desc, value); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_direction_output);@@ -2877,19 +2886,15 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)if (!ret) goto set_output_value;/* Emulate open drain by not actively driving the line high */ -if (value) { - ret =gpiod_direction_input_nonotify (desc); +if (value) goto set_output_flag; - } }else if (test_bit (FLAG_OPEN_SOURCE , &flags)) { ret =gpio_set_config (desc,PIN_CONFIG_DRIVE_OPEN_SOURCE );if (!ret) goto set_output_value;/* Emulate open source by not actively driving the line low */ -if (!value) { - ret =gpiod_direction_input_nonotify (desc); +if (!value) goto set_output_flag; - } }else {gpio_set_config (desc,PIN_CONFIG_DRIVE_PUSH_PULL ); }
drivers/gpio/gpiolib.c int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value) · line 2909
Quoted 4 lines
drivers/gpio/gpiolib.c +1
-0@@ -2901,15 +2906,17 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)return gpiod_direction_output_raw_commit (desc, value); set_output_flag: + ret =gpiod_direction_input_nonotify (desc);
This can't be right. Or am I just not getting it? In any case it's completely unreadable now. Go set output flag but start by setting direction to input first?
Quoted 26 lines
drivers/gpio/gpiolib.c +4
-9+if (ret) +return ret;/* * When emulating open-source or open-drain functionalities by not * actively driving the line (setting mode to input) we still need to * set the IS_OUT flag or otherwise we won't be able to set the line * value anymore. */ -if (ret ==0 ) -set_bit (FLAG_IS_OUT , &desc->flags); -return ret; +set_bit (FLAG_IS_OUT , &desc->flags); +return 0 ; }/** @@ -2994,25 +3001,25 @@ int gpiod_set_config(struct gpio_desc *desc, unsigned long config)VALIDATE_DESC (desc); ret =gpio_do_set_config (desc, config); -if (!ret) { -/* These are the only options we notify the userspace about. */ -switch (pinconf_to_config_param (config)) { -case PIN_CONFIG_BIAS_DISABLE : -case PIN_CONFIG_BIAS_PULL_DOWN : -case PIN_CONFIG_BIAS_PULL_UP :
drivers/gpio/gpiolib.c int gpiod_set_config(struct gpio_desc *desc, unsigned long config) · line 3012
Quoted 10 lines
drivers/gpio/gpiolib.c +0
-10-case PIN_CONFIG_DRIVE_OPEN_DRAIN : -case PIN_CONFIG_DRIVE_OPEN_SOURCE : -case PIN_CONFIG_DRIVE_PUSH_PULL : -case PIN_CONFIG_INPUT_DEBOUNCE : -gpiod_line_state_notify (desc, -GPIO_V2_LINE_CHANGED_CONFIG ); -break ; -default : -break ; - }
If you really want to get rid of one level of indentation here, I suggest moving it into a separate function.
Quoted 39 lines
drivers/gpio/gpiolib.c +21
-5+if (ret) +return ret; + +/* These are the only options we notify the userspace about */ +switch (pinconf_to_config_param (config)) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_DRIVE_OPEN_DRAIN : +case PIN_CONFIG_DRIVE_OPEN_SOURCE : +case PIN_CONFIG_DRIVE_PUSH_PULL : +case PIN_CONFIG_INPUT_DEBOUNCE : +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +break ; +default : +break ; } -return ret; +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_set_config);@@ -3730,10 +3737,11 @@ int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)VALIDATE_DESC (desc); ret =desc_set_label (desc, name); -if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }EXPORT_SYMBOL_GPL (gpiod_set_consumer_name); --
Quoted 2 lines
2.43.0.rc1.1336.g36b5255a03ac
Most of this is IMO pointless churn. You typically do a lot of great cleanups but this just doesn't make sense. Sorry but NAK.
Bart
Quoted 11 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Instead of 'if (ret == 0)' switch to "check for the error first" rule.
Well there's much more to this patch than that and I have some issues with it.
Quoted 1 line
While it gives a "+" (plus) statistics it makes the code easier to read
Not only does it increase the footprint but it also adds completely unnecessary goto labels.
These pieces can be dropped.
...
Quoted 5 lines
Quoted 1 line
and maintain (when, e.g., want to add somethning in between touched lines).
The single line calls to the notifier chain are unlikely to be extended anytime soon but even then I think we should cross that bridge when we get there.
Okay.
...
Quoted 10 lines
drivers/gpio/gpiolib.c int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) · line 2682
Quoted 9 lines
drivers/gpio/gpiolib.c +4
-3-if (!ret) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }
Quoted 6 lines
I really don't see how this makes it better. The logic here is: if the underlying set config worked fine - emit the event. Otherwise continue with the function (even if there's nothing there now). If anything you're making it more difficult to modify later because logically the notification is just an optional step on the way to returning from the function.
Optional steps are covered by flags, and not by checking the previous call for failure. So, I barely see the "optionality" of the notifications in these calls.
...
Quoted 8 lines
drivers/gpio/gpiolib.c int gpiod_direction_input(struct gpio_desc *desc) · line 2702
Quoted 5 lines
ret = gpiod_direction_input_nonotify(desc);drivers/gpio/gpiolib.c +2
-2-if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret;Ok, for consistency I could take it but please put this into a separate commit doing just that (here and elsewhere).
Based on the other comments from you in this email I'm not sure I understood this correctly. Do you want to reject the complete patch, or do you agree on some pieces out of it.
Quoted 3 lines
Quoted 3 lines
drivers/gpio/gpiolib.c +2
-1-return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ;
...
Quoted 18 lines
Quoted 7 lines
ret = gpio_do_set_config(desc, config);drivers/gpio/gpiolib.c +0
-6-if (!ret) { -/* These are the only options we notify the userspace about. */ -switch (pinconf_to_config_param (config)) { -case PIN_CONFIG_BIAS_DISABLE : -case PIN_CONFIG_BIAS_PULL_DOWN : -case PIN_CONFIG_BIAS_PULL_UP :drivers/gpio/gpiolib.c int gpiod_set_config(struct gpio_desc *desc, unsigned long config) · line 3012
Quoted 10 lines
drivers/gpio/gpiolib.c +0
-10-case PIN_CONFIG_DRIVE_OPEN_DRAIN : -case PIN_CONFIG_DRIVE_OPEN_SOURCE : -case PIN_CONFIG_DRIVE_PUSH_PULL : -case PIN_CONFIG_INPUT_DEBOUNCE : -gpiod_line_state_notify (desc, -GPIO_V2_LINE_CHANGED_CONFIG ); -break ; -default : -break ; - }
Quoted 2 lines
If you really want to get rid of one level of indentation here, I suggest moving it into a separate function.
Perhaps you suggested a separate change for that?
Quoted 20 lines
Quoted 20 lines
drivers/gpio/gpiolib.c +17
-1+if (ret) +return ret; + +/* These are the only options we notify the userspace about */ +switch (pinconf_to_config_param (config)) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_DRIVE_OPEN_DRAIN : +case PIN_CONFIG_DRIVE_OPEN_SOURCE : +case PIN_CONFIG_DRIVE_PUSH_PULL : +case PIN_CONFIG_INPUT_DEBOUNCE : +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +break ; +default : +break ; } -return ret; +return 0 ;
...
Quoted 2 lines
Most of this is IMO pointless churn. You typically do a lot of great cleanups but this just doesn't make sense. Sorry but NAK.
OK, I do one change out of that with deduplication of the direction input call, the rest is up to you, let's it be less readable.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 56 lines · Andy Shevchenko
Quoted 11 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Instead of 'if (ret == 0)' switch to "check for the error first" rule.
Well there's much more to this patch than that and I have some issues with it.
Quoted 1 line
While it gives a "+" (plus) statistics it makes the code easier to read
Not only does it increase the footprint but it also adds completely unnecessary goto labels.
These pieces can be dropped.
...
Quoted 5 lines
Quoted 1 line
and maintain (when, e.g., want to add somethning in between touched lines).
The single line calls to the notifier chain are unlikely to be extended anytime soon but even then I think we should cross that bridge when we get there.
Okay.
...
Quoted 10 lines
drivers/gpio/gpiolib.c int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce) · line 2682
Quoted 9 lines
drivers/gpio/gpiolib.c +4
-3-if (!ret) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret; -return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ; }Quoted 6 lines
I really don't see how this makes it better. The logic here is: if the underlying set config worked fine - emit the event. Otherwise continue with the function (even if there's nothing there now). If anything you're making it more difficult to modify later because logically the notification is just an optional step on the way to returning from the function.
Optional steps are covered by flags, and not by checking the previous call for failure. So, I barely see the "optionality" of the notifications in these calls.
...
Quoted 6 lines
Quoted 5 lines
ret = gpiod_direction_input_nonotify(desc);drivers/gpio/gpiolib.c +2
-2-if (ret ==0 ) -gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +if (ret) +return ret;
Quoted 7 lines
Quoted 2 lines
Ok, for consistency I could take it but please put this into a separate commit doing just that (here and elsewhere).
Based on the other comments from you in this email I'm not sure I understood this correctly. Do you want to reject the complete patch, or do you agree on some pieces out of it.
I want to reject most of the patch in this form. s/(ret == 0)/(!ret)/ is fine as a standalone change.
Quoted 24 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpio/gpiolib.c +2
-1-return ret; +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +return 0 ;...
Quoted 18 lines
Quoted 17 lines
ret = gpio_do_set_config(desc, config);drivers/gpio/gpiolib.c +0
-16-if (!ret) { -/* These are the only options we notify the userspace about. */ -switch (pinconf_to_config_param (config)) { -case PIN_CONFIG_BIAS_DISABLE : -case PIN_CONFIG_BIAS_PULL_DOWN : -case PIN_CONFIG_BIAS_PULL_UP : -case PIN_CONFIG_DRIVE_OPEN_DRAIN : -case PIN_CONFIG_DRIVE_OPEN_SOURCE : -case PIN_CONFIG_DRIVE_PUSH_PULL : -case PIN_CONFIG_INPUT_DEBOUNCE : -gpiod_line_state_notify (desc, -GPIO_V2_LINE_CHANGED_CONFIG ); -break ; -default : -break ; - }
Quoted 5 lines
Quoted 2 lines
If you really want to get rid of one level of indentation here, I suggest moving it into a separate function.
Perhaps you suggested a separate change for that?
This doesn't really bother me but if it triggers you then feel free to change it like:
if (!ret)
gpio_set_config_line_state_notify(desc);
Bart
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/gpio/gpiolib.c +17
-1+if (ret) +return ret; + +/* These are the only options we notify the userspace about */ +switch (pinconf_to_config_param (config)) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_DRIVE_OPEN_DRAIN : +case PIN_CONFIG_DRIVE_OPEN_SOURCE : +case PIN_CONFIG_DRIVE_PUSH_PULL : +case PIN_CONFIG_INPUT_DEBOUNCE : +gpiod_line_state_notify (desc,GPIO_V2_LINE_CHANGED_CONFIG ); +break ; +default : +break ; } -return ret; +return 0 ;...
Quoted 2 lines
Most of this is IMO pointless churn. You typically do a lot of great cleanups but this just doesn't make sense. Sorry but NAK.
OK, I do one change out of that with deduplication of the direction input call, the rest is up to you, let's it be less readable.