gpiolib: Get rid of redundant 'else' (part 2)
PATCH 1/1 gpiolib: Get rid of redundant 'else' (part 2)
In the snippets like the following
if (...) return / goto / break / continue ...; else ...
the 'else' is redundant. Get rid of it by using switch-case pattern. Note that the pattern seems more usual for IOCTL handlers.
Signed-off-by Andy Shevchenko <[email protected]>
--- drivers/gpio/gpiolib-cdev.c | 66 ++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 31 deletions(-)
drivers/gpio/gpiolib-cdev.c +35 -31
@@ -197,16 +197,15 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,void __user *ip = (void __user *)arg;struct gpiohandle_data ghd;DECLARE_BITMAP (vals,GPIOHANDLES_MAX ); -int i; +unsigned int i; +int ret; -if (cmd ==GPIOHANDLE_GET_LINE_VALUES_IOCTL ) { -/* NOTE: It's ok to read values of output lines. */ -int ret =gpiod_get_array_value_complex (false, - true, - lh->num_descs, - lh->descs, -NULL , - vals); +switch (cmd) { +case GPIOHANDLE_GET_LINE_VALUES_IOCTL : +/* NOTE: It's okay to read values of output lines */ + ret =gpiod_get_array_value_complex (false, true, + lh->num_descs, lh->descs, +NULL , vals);if (ret)return ret;
@@ -218,7 +217,7 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,return -EFAULT ;return 0 ; - }else if (cmd ==GPIOHANDLE_SET_LINE_VALUES_IOCTL ) { +case GPIOHANDLE_SET_LINE_VALUES_IOCTL :/* * All line descriptors were created at once with the same * flags so just check if the first one is really output.
@@ -240,10 +239,11 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd, lh->descs,NULL , vals); - }else if (cmd ==GPIOHANDLE_SET_CONFIG_IOCTL ) { +case GPIOHANDLE_SET_CONFIG_IOCTL :return linehandle_set_config (lh, ip); +default : +return -EINVAL ; } -return -EINVAL ; }#ifdef CONFIG_COMPAT
@@ -1188,14 +1188,16 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,struct linereq *lr = file->private_data;void __user *ip = (void __user *)arg; -if (cmd ==GPIO_V2_LINE_GET_VALUES_IOCTL ) +switch (cmd) { +case GPIO_V2_LINE_GET_VALUES_IOCTL :return linereq_get_values (lr, ip); -else if (cmd ==GPIO_V2_LINE_SET_VALUES_IOCTL ) +case GPIO_V2_LINE_SET_VALUES_IOCTL :return linereq_set_values (lr, ip); -else if (cmd ==GPIO_V2_LINE_SET_CONFIG_IOCTL ) +case GPIO_V2_LINE_SET_CONFIG_IOCTL :return linereq_set_config (lr, ip); - -return -EINVAL ; +default : +return -EINVAL ; + } }#ifdef CONFIG_COMPAT
@@ -2113,28 +2115,30 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return -ENODEV ;/* Fill in the struct and pass to userspace */ -if (cmd ==GPIO_GET_CHIPINFO_IOCTL ) { +switch (cmd) { +case GPIO_GET_CHIPINFO_IOCTL :return chipinfo_get (cdev, ip);#ifdef CONFIG_GPIO_CDEV_V1 - }else if (cmd ==GPIO_GET_LINEHANDLE_IOCTL ) { +case GPIO_GET_LINEHANDLE_IOCTL :return linehandle_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEEVENT_IOCTL ) { +case GPIO_GET_LINEEVENT_IOCTL :return lineevent_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEINFO_IOCTL || - cmd ==GPIO_GET_LINEINFO_WATCH_IOCTL ) { -return lineinfo_get_v1 (cdev, ip, - cmd ==GPIO_GET_LINEINFO_WATCH_IOCTL ); +case GPIO_GET_LINEINFO_IOCTL : +return lineinfo_get_v1 (cdev, ip, false); +case GPIO_GET_LINEINFO_WATCH_IOCTL : +return lineinfo_get_v1 (cdev, ip, true);#endif /* CONFIG_GPIO_CDEV_V1 */ - }else if (cmd ==GPIO_V2_GET_LINEINFO_IOCTL || - cmd ==GPIO_V2_GET_LINEINFO_WATCH_IOCTL ) { -return lineinfo_get (cdev, ip, - cmd ==GPIO_V2_GET_LINEINFO_WATCH_IOCTL ); - }else if (cmd ==GPIO_V2_GET_LINE_IOCTL ) { +case GPIO_V2_GET_LINEINFO_IOCTL : +return lineinfo_get (cdev, ip, false); +case GPIO_V2_GET_LINEINFO_WATCH_IOCTL : +return lineinfo_get (cdev, ip, true); +case GPIO_V2_GET_LINE_IOCTL :return linereq_create (gdev, ip); - }else if (cmd ==GPIO_GET_LINEINFO_UNWATCH_IOCTL ) { +case GPIO_GET_LINEINFO_UNWATCH_IOCTL :return lineinfo_unwatch (cdev, ip); +default : +return -EINVAL ; } -return -EINVAL ; }#ifdef CONFIG_COMPAT
Signature · 1 line
2.35.1
Quoted 9 lines · Andy Shevchenko
In the snippets like the following
if (...) return / goto / break / continue ...; else ...the 'else' is redundant. Get rid of it by using switch-case pattern. Note that the pattern seems more usual for IOCTL handlers.
It appears that part 1 (as per subject) was never submitted before. So, I unify them in v2 of this patch.
Signature · 2 lines
With Best Regards, Andy Shevchenko