Skip to content

Commit 32d8e3b

Browse files
warthog618Bartosz Golaszewski
authored andcommitted
gpiolib: cdev: replace locking wrappers for config_mutex with guards
After the adoption of guard(), the locking wrappers that hold the config_mutex for linereq_set_values() and linereq_set_config() no longer add value, so combine them into the functions they wrap. Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent b718fbf commit 32d8e3b

1 file changed

Lines changed: 24 additions & 39 deletions

File tree

drivers/gpio/gpiolib-cdev.c

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,14 +1454,19 @@ static long linereq_get_values(struct linereq *lr, void __user *ip)
14541454
return 0;
14551455
}
14561456

1457-
static long linereq_set_values_unlocked(struct linereq *lr,
1458-
struct gpio_v2_line_values *lv)
1457+
static long linereq_set_values(struct linereq *lr, void __user *ip)
14591458
{
14601459
DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX);
1460+
struct gpio_v2_line_values lv;
14611461
struct gpio_desc **descs;
14621462
unsigned int i, didx, num_set;
14631463
int ret;
14641464

1465+
if (copy_from_user(&lv, ip, sizeof(lv)))
1466+
return -EFAULT;
1467+
1468+
guard(mutex)(&lr->config_mutex);
1469+
14651470
/*
14661471
* gpiod_set_array_value_complex() requires compacted desc and val
14671472
* arrays, rather than the sparse ones in lv.
@@ -1472,12 +1477,12 @@ static long linereq_set_values_unlocked(struct linereq *lr,
14721477
bitmap_zero(vals, GPIO_V2_LINES_MAX);
14731478
/* scan requested lines to determine the subset to be set */
14741479
for (num_set = 0, i = 0; i < lr->num_lines; i++) {
1475-
if (lv->mask & BIT_ULL(i)) {
1480+
if (lv.mask & BIT_ULL(i)) {
14761481
/* setting inputs is not allowed */
14771482
if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags))
14781483
return -EPERM;
14791484
/* add to compacted values */
1480-
if (lv->bits & BIT_ULL(i))
1485+
if (lv.bits & BIT_ULL(i))
14811486
__set_bit(num_set, vals);
14821487
num_set++;
14831488
/* capture desc for the num_set == 1 case */
@@ -1493,7 +1498,7 @@ static long linereq_set_values_unlocked(struct linereq *lr,
14931498
if (!descs)
14941499
return -ENOMEM;
14951500
for (didx = 0, i = 0; i < lr->num_lines; i++) {
1496-
if (lv->mask & BIT_ULL(i)) {
1501+
if (lv.mask & BIT_ULL(i)) {
14971502
descs[didx] = lr->lines[i].desc;
14981503
didx++;
14991504
}
@@ -1507,39 +1512,36 @@ static long linereq_set_values_unlocked(struct linereq *lr,
15071512
return ret;
15081513
}
15091514

1510-
static long linereq_set_values(struct linereq *lr, void __user *ip)
1511-
{
1512-
struct gpio_v2_line_values lv;
1513-
1514-
if (copy_from_user(&lv, ip, sizeof(lv)))
1515-
return -EFAULT;
1516-
1517-
guard(mutex)(&lr->config_mutex);
1518-
1519-
return linereq_set_values_unlocked(lr, &lv);
1520-
}
1521-
1522-
static long linereq_set_config_unlocked(struct linereq *lr,
1523-
struct gpio_v2_line_config *lc)
1515+
static long linereq_set_config(struct linereq *lr, void __user *ip)
15241516
{
1517+
struct gpio_v2_line_config lc;
15251518
struct gpio_desc *desc;
15261519
struct line *line;
15271520
unsigned int i;
15281521
u64 flags, edflags;
15291522
int ret;
15301523

1524+
if (copy_from_user(&lc, ip, sizeof(lc)))
1525+
return -EFAULT;
1526+
1527+
ret = gpio_v2_line_config_validate(&lc, lr->num_lines);
1528+
if (ret)
1529+
return ret;
1530+
1531+
guard(mutex)(&lr->config_mutex);
1532+
15311533
for (i = 0; i < lr->num_lines; i++) {
15321534
line = &lr->lines[i];
15331535
desc = lr->lines[i].desc;
1534-
flags = gpio_v2_line_config_flags(lc, i);
1536+
flags = gpio_v2_line_config_flags(&lc, i);
15351537
gpio_v2_line_config_flags_to_desc_flags(flags, &desc->flags);
15361538
edflags = flags & GPIO_V2_LINE_EDGE_DETECTOR_FLAGS;
15371539
/*
15381540
* Lines have to be requested explicitly for input
15391541
* or output, else the line will be treated "as is".
15401542
*/
15411543
if (flags & GPIO_V2_LINE_FLAG_OUTPUT) {
1542-
int val = gpio_v2_line_config_output_value(lc, i);
1544+
int val = gpio_v2_line_config_output_value(&lc, i);
15431545

15441546
edge_detector_stop(line);
15451547
ret = gpiod_direction_output(desc, val);
@@ -1550,7 +1552,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,
15501552
if (ret)
15511553
return ret;
15521554

1553-
ret = edge_detector_update(line, lc, i, edflags);
1555+
ret = edge_detector_update(line, &lc, i, edflags);
15541556
if (ret)
15551557
return ret;
15561558
}
@@ -1562,23 +1564,6 @@ static long linereq_set_config_unlocked(struct linereq *lr,
15621564
return 0;
15631565
}
15641566

1565-
static long linereq_set_config(struct linereq *lr, void __user *ip)
1566-
{
1567-
struct gpio_v2_line_config lc;
1568-
int ret;
1569-
1570-
if (copy_from_user(&lc, ip, sizeof(lc)))
1571-
return -EFAULT;
1572-
1573-
ret = gpio_v2_line_config_validate(&lc, lr->num_lines);
1574-
if (ret)
1575-
return ret;
1576-
1577-
guard(mutex)(&lr->config_mutex);
1578-
1579-
return linereq_set_config_unlocked(lr, &lc);
1580-
}
1581-
15821567
static long linereq_ioctl_unlocked(struct file *file, unsigned int cmd,
15831568
unsigned long arg)
15841569
{

0 commit comments

Comments
 (0)