Commit 1cef8b50 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bartosz Golaszewski

gpiolib: Get rid of redundant 'else'

In the snippets like the following

	if (...)
		return / goto / break / continue ...;
	else
		...

the 'else' is redundant. Get rid of it. In case of IOCTLs use
switch-case pattern that seems the usual in such cases.

While at it, clarify necessity of else in gpiod_direction_output()
by attaching else if to the closing curly brace on a previous line.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 265a3bf4
...@@ -197,16 +197,15 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd, ...@@ -197,16 +197,15 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
void __user *ip = (void __user *)arg; void __user *ip = (void __user *)arg;
struct gpiohandle_data ghd; struct gpiohandle_data ghd;
DECLARE_BITMAP(vals, GPIOHANDLES_MAX); DECLARE_BITMAP(vals, GPIOHANDLES_MAX);
int i; unsigned int i;
int ret;
if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { switch (cmd) {
/* NOTE: It's ok to read values of output lines. */ case GPIOHANDLE_GET_LINE_VALUES_IOCTL:
int ret = gpiod_get_array_value_complex(false, /* NOTE: It's okay to read values of output lines */
true, ret = gpiod_get_array_value_complex(false, true,
lh->num_descs, lh->num_descs, lh->descs,
lh->descs, NULL, vals);
NULL,
vals);
if (ret) if (ret)
return ret; return ret;
...@@ -218,7 +217,7 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd, ...@@ -218,7 +217,7 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
return -EFAULT; return -EFAULT;
return 0; 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 * All line descriptors were created at once with the same
* flags so just check if the first one is really output. * 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, ...@@ -240,10 +239,11 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
lh->descs, lh->descs,
NULL, NULL,
vals); vals);
} else if (cmd == GPIOHANDLE_SET_CONFIG_IOCTL) { case GPIOHANDLE_SET_CONFIG_IOCTL:
return linehandle_set_config(lh, ip); return linehandle_set_config(lh, ip);
default:
return -EINVAL;
} }
return -EINVAL;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -1188,14 +1188,16 @@ static long linereq_ioctl(struct file *file, unsigned int cmd, ...@@ -1188,14 +1188,16 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,
struct linereq *lr = file->private_data; struct linereq *lr = file->private_data;
void __user *ip = (void __user *)arg; 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); 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); 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 linereq_set_config(lr, ip);
default:
return -EINVAL; return -EINVAL;
}
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -2113,28 +2115,30 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -2113,28 +2115,30 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return -ENODEV; return -ENODEV;
/* Fill in the struct and pass to userspace */ /* 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); return chipinfo_get(cdev, ip);
#ifdef CONFIG_GPIO_CDEV_V1 #ifdef CONFIG_GPIO_CDEV_V1
} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) { case GPIO_GET_LINEHANDLE_IOCTL:
return linehandle_create(gdev, ip); return linehandle_create(gdev, ip);
} else if (cmd == GPIO_GET_LINEEVENT_IOCTL) { case GPIO_GET_LINEEVENT_IOCTL:
return lineevent_create(gdev, ip); return lineevent_create(gdev, ip);
} else if (cmd == GPIO_GET_LINEINFO_IOCTL || case GPIO_GET_LINEINFO_IOCTL:
cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) { return lineinfo_get_v1(cdev, ip, false);
return lineinfo_get_v1(cdev, ip, case GPIO_GET_LINEINFO_WATCH_IOCTL:
cmd == GPIO_GET_LINEINFO_WATCH_IOCTL); return lineinfo_get_v1(cdev, ip, true);
#endif /* CONFIG_GPIO_CDEV_V1 */ #endif /* CONFIG_GPIO_CDEV_V1 */
} else if (cmd == GPIO_V2_GET_LINEINFO_IOCTL || case GPIO_V2_GET_LINEINFO_IOCTL:
cmd == GPIO_V2_GET_LINEINFO_WATCH_IOCTL) { return lineinfo_get(cdev, ip, false);
return lineinfo_get(cdev, ip, case GPIO_V2_GET_LINEINFO_WATCH_IOCTL:
cmd == GPIO_V2_GET_LINEINFO_WATCH_IOCTL); return lineinfo_get(cdev, ip, true);
} else if (cmd == GPIO_V2_GET_LINE_IOCTL) { case GPIO_V2_GET_LINE_IOCTL:
return linereq_create(gdev, ip); return linereq_create(gdev, ip);
} else if (cmd == GPIO_GET_LINEINFO_UNWATCH_IOCTL) { case GPIO_GET_LINEINFO_UNWATCH_IOCTL:
return lineinfo_unwatch(cdev, ip); return lineinfo_unwatch(cdev, ip);
default:
return -EINVAL;
} }
return -EINVAL;
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
......
...@@ -189,9 +189,8 @@ static int gpiochip_find_base(int ngpio) ...@@ -189,9 +189,8 @@ static int gpiochip_find_base(int ngpio)
/* found a free space? */ /* found a free space? */
if (gdev->base + gdev->ngpio <= base) if (gdev->base + gdev->ngpio <= base)
break; break;
else /* nope, check the space right before the chip */
/* nope, check the space right before the chip */ base = gdev->base - ngpio;
base = gdev->base - ngpio;
} }
if (gpio_is_valid(base)) { if (gpio_is_valid(base)) {
...@@ -2401,8 +2400,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) ...@@ -2401,8 +2400,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
ret = gpiod_direction_input(desc); ret = gpiod_direction_input(desc);
goto set_output_flag; goto set_output_flag;
} }
} } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE); ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE);
if (!ret) if (!ret)
goto set_output_value; goto set_output_value;
...@@ -2559,9 +2557,9 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc) ...@@ -2559,9 +2557,9 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
static int gpio_chip_get_multiple(struct gpio_chip *gc, static int gpio_chip_get_multiple(struct gpio_chip *gc,
unsigned long *mask, unsigned long *bits) unsigned long *mask, unsigned long *bits)
{ {
if (gc->get_multiple) { if (gc->get_multiple)
return gc->get_multiple(gc, mask, bits); return gc->get_multiple(gc, mask, bits);
} else if (gc->get) { if (gc->get) {
int i, value; int i, value;
for_each_set_bit(i, mask, gc->ngpio) { for_each_set_bit(i, mask, gc->ngpio) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment