Skip to content

Commit 8574b5b

Browse files
author
Bartosz Golaszewski
committed
gpio: cdev: use correct pointer accessors with SRCU
We never dereference the chip pointer in character device code so we can use the lighter rcu_access_pointer() helper. This also makes lockep happier as it no longer complains about suspicious rcu_dereference() usage. Fixes: d83cee3 ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Acked-by: Paul E. McKenney <[email protected]>
1 parent 815a1b5 commit 8574b5b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
206206

207207
guard(srcu)(&lh->gdev->srcu);
208208

209-
if (!rcu_dereference(lh->gdev->chip))
209+
if (!rcu_access_pointer(lh->gdev->chip))
210210
return -ENODEV;
211211

212212
switch (cmd) {
@@ -1521,7 +1521,7 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,
15211521

15221522
guard(srcu)(&lr->gdev->srcu);
15231523

1524-
if (!rcu_dereference(lr->gdev->chip))
1524+
if (!rcu_access_pointer(lr->gdev->chip))
15251525
return -ENODEV;
15261526

15271527
switch (cmd) {
@@ -1552,7 +1552,7 @@ static __poll_t linereq_poll(struct file *file,
15521552

15531553
guard(srcu)(&lr->gdev->srcu);
15541554

1555-
if (!rcu_dereference(lr->gdev->chip))
1555+
if (!rcu_access_pointer(lr->gdev->chip))
15561556
return EPOLLHUP | EPOLLERR;
15571557

15581558
poll_wait(file, &lr->wait, wait);
@@ -1574,7 +1574,7 @@ static ssize_t linereq_read(struct file *file, char __user *buf,
15741574

15751575
guard(srcu)(&lr->gdev->srcu);
15761576

1577-
if (!rcu_dereference(lr->gdev->chip))
1577+
if (!rcu_access_pointer(lr->gdev->chip))
15781578
return -ENODEV;
15791579

15801580
if (count < sizeof(le))
@@ -1875,7 +1875,7 @@ static __poll_t lineevent_poll(struct file *file,
18751875

18761876
guard(srcu)(&le->gdev->srcu);
18771877

1878-
if (!rcu_dereference(le->gdev->chip))
1878+
if (!rcu_access_pointer(le->gdev->chip))
18791879
return EPOLLHUP | EPOLLERR;
18801880

18811881
poll_wait(file, &le->wait, wait);
@@ -1913,7 +1913,7 @@ static ssize_t lineevent_read(struct file *file, char __user *buf,
19131913

19141914
guard(srcu)(&le->gdev->srcu);
19151915

1916-
if (!rcu_dereference(le->gdev->chip))
1916+
if (!rcu_access_pointer(le->gdev->chip))
19171917
return -ENODEV;
19181918

19191919
/*
@@ -1996,7 +1996,7 @@ static long lineevent_ioctl(struct file *file, unsigned int cmd,
19961996

19971997
guard(srcu)(&le->gdev->srcu);
19981998

1999-
if (!rcu_dereference(le->gdev->chip))
1999+
if (!rcu_access_pointer(le->gdev->chip))
20002000
return -ENODEV;
20012001

20022002
/*
@@ -2510,7 +2510,7 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25102510
guard(srcu)(&gdev->srcu);
25112511

25122512
/* We fail any subsequent ioctl():s when the chip is gone */
2513-
if (!rcu_dereference(gdev->chip))
2513+
if (!rcu_access_pointer(gdev->chip))
25142514
return -ENODEV;
25152515

25162516
/* Fill in the struct and pass to userspace */
@@ -2595,7 +2595,7 @@ static __poll_t lineinfo_watch_poll(struct file *file,
25952595

25962596
guard(srcu)(&cdev->gdev->srcu);
25972597

2598-
if (!rcu_dereference(cdev->gdev->chip))
2598+
if (!rcu_access_pointer(cdev->gdev->chip))
25992599
return EPOLLHUP | EPOLLERR;
26002600

26012601
poll_wait(file, &cdev->wait, pollt);
@@ -2618,7 +2618,7 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
26182618

26192619
guard(srcu)(&cdev->gdev->srcu);
26202620

2621-
if (!rcu_dereference(cdev->gdev->chip))
2621+
if (!rcu_access_pointer(cdev->gdev->chip))
26222622
return -ENODEV;
26232623

26242624
#ifndef CONFIG_GPIO_CDEV_V1
@@ -2696,7 +2696,7 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
26962696
guard(srcu)(&gdev->srcu);
26972697

26982698
/* Fail on open if the backing gpiochip is gone */
2699-
if (!rcu_dereference(gdev->chip))
2699+
if (!rcu_access_pointer(gdev->chip))
27002700
return -ENODEV;
27012701

27022702
cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
@@ -2796,8 +2796,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
27962796

27972797
guard(srcu)(&gdev->srcu);
27982798

2799-
gc = rcu_dereference(gdev->chip);
2800-
if (!gc)
2799+
if (!rcu_access_pointer(gdev->chip))
28012800
return -ENODEV;
28022801

28032802
chip_dbg(gc, "added GPIO chardev (%d:%d)\n", MAJOR(devt), gdev->id);

0 commit comments

Comments
 (0)