Skip to content

Commit 11498d9

Browse files
author
Bartosz Golaszewski
committed
gpio: sim: add lockdep asserts
We have three functions in gpio-sim that are called with the device lock already held. We use the "_unlocked" suffix in their names to indicate that. This has proven to be confusing though as the naming convention in the kernel varies between using "_locked" or "_unlocked" for this purpose. Naming convention also doesn't enforce anything. Let's remove the suffix and add lockdep annotation at the top of these functions. This makes it clear the function requires a lock to be held (and which one specifically!) as well as results in a warning if it's not the case. The only place where the information is lost is the place where the function is called but the caller doesn't care about that information anyway. Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent f837fe1 commit 11498d9

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/irq_sim.h>
2323
#include <linux/kernel.h>
2424
#include <linux/list.h>
25+
#include <linux/lockdep.h>
2526
#include <linux/minmax.h>
2627
#include <linux/mod_devicetable.h>
2728
#include <linux/module.h>
@@ -697,8 +698,10 @@ static struct gpio_sim_device *gpio_sim_hog_get_device(struct gpio_sim_hog *hog)
697698
return gpio_sim_line_get_device(line);
698699
}
699700

700-
static bool gpio_sim_device_is_live_unlocked(struct gpio_sim_device *dev)
701+
static bool gpio_sim_device_is_live(struct gpio_sim_device *dev)
701702
{
703+
lockdep_assert_held(&dev->lock);
704+
702705
return !!dev->pdev;
703706
}
704707

@@ -737,7 +740,7 @@ gpio_sim_device_config_live_show(struct config_item *item, char *page)
737740
bool live;
738741

739742
scoped_guard(mutex, &dev->lock)
740-
live = gpio_sim_device_is_live_unlocked(dev);
743+
live = gpio_sim_device_is_live(dev);
741744

742745
return sprintf(page, "%c\n", live ? '1' : '0');
743746
}
@@ -926,14 +929,16 @@ static bool gpio_sim_bank_labels_non_unique(struct gpio_sim_device *dev)
926929
return false;
927930
}
928931

929-
static int gpio_sim_device_activate_unlocked(struct gpio_sim_device *dev)
932+
static int gpio_sim_device_activate(struct gpio_sim_device *dev)
930933
{
931934
struct platform_device_info pdevinfo;
932935
struct fwnode_handle *swnode;
933936
struct platform_device *pdev;
934937
struct gpio_sim_bank *bank;
935938
int ret;
936939

940+
lockdep_assert_held(&dev->lock);
941+
937942
if (list_empty(&dev->bank_list))
938943
return -ENODATA;
939944

@@ -998,10 +1003,12 @@ static int gpio_sim_device_activate_unlocked(struct gpio_sim_device *dev)
9981003
return 0;
9991004
}
10001005

1001-
static void gpio_sim_device_deactivate_unlocked(struct gpio_sim_device *dev)
1006+
static void gpio_sim_device_deactivate(struct gpio_sim_device *dev)
10021007
{
10031008
struct fwnode_handle *swnode;
10041009

1010+
lockdep_assert_held(&dev->lock);
1011+
10051012
swnode = dev_fwnode(&dev->pdev->dev);
10061013
platform_device_unregister(dev->pdev);
10071014
gpio_sim_remove_hogs(dev);
@@ -1023,12 +1030,12 @@ gpio_sim_device_config_live_store(struct config_item *item,
10231030

10241031
guard(mutex)(&dev->lock);
10251032

1026-
if (live == gpio_sim_device_is_live_unlocked(dev))
1033+
if (live == gpio_sim_device_is_live(dev))
10271034
ret = -EPERM;
10281035
else if (live)
1029-
ret = gpio_sim_device_activate_unlocked(dev);
1036+
ret = gpio_sim_device_activate(dev);
10301037
else
1031-
gpio_sim_device_deactivate_unlocked(dev);
1038+
gpio_sim_device_deactivate(dev);
10321039

10331040
return ret ?: count;
10341041
}
@@ -1069,7 +1076,7 @@ static ssize_t gpio_sim_bank_config_chip_name_show(struct config_item *item,
10691076

10701077
guard(mutex)(&dev->lock);
10711078

1072-
if (gpio_sim_device_is_live_unlocked(dev))
1079+
if (gpio_sim_device_is_live(dev))
10731080
return device_for_each_child(&dev->pdev->dev, &ctx,
10741081
gpio_sim_emit_chip_name);
10751082

@@ -1098,7 +1105,7 @@ static ssize_t gpio_sim_bank_config_label_store(struct config_item *item,
10981105

10991106
guard(mutex)(&dev->lock);
11001107

1101-
if (gpio_sim_device_is_live_unlocked(dev))
1108+
if (gpio_sim_device_is_live(dev))
11021109
return -EBUSY;
11031110

11041111
trimmed = gpio_sim_strdup_trimmed(page, count);
@@ -1142,7 +1149,7 @@ gpio_sim_bank_config_num_lines_store(struct config_item *item,
11421149

11431150
guard(mutex)(&dev->lock);
11441151

1145-
if (gpio_sim_device_is_live_unlocked(dev))
1152+
if (gpio_sim_device_is_live(dev))
11461153
return -EBUSY;
11471154

11481155
bank->num_lines = num_lines;
@@ -1179,7 +1186,7 @@ static ssize_t gpio_sim_line_config_name_store(struct config_item *item,
11791186

11801187
guard(mutex)(&dev->lock);
11811188

1182-
if (gpio_sim_device_is_live_unlocked(dev))
1189+
if (gpio_sim_device_is_live(dev))
11831190
return -EBUSY;
11841191

11851192
trimmed = gpio_sim_strdup_trimmed(page, count);
@@ -1219,7 +1226,7 @@ static ssize_t gpio_sim_hog_config_name_store(struct config_item *item,
12191226

12201227
guard(mutex)(&dev->lock);
12211228

1222-
if (gpio_sim_device_is_live_unlocked(dev))
1229+
if (gpio_sim_device_is_live(dev))
12231230
return -EBUSY;
12241231

12251232
trimmed = gpio_sim_strdup_trimmed(page, count);
@@ -1274,7 +1281,7 @@ gpio_sim_hog_config_direction_store(struct config_item *item,
12741281

12751282
guard(mutex)(&dev->lock);
12761283

1277-
if (gpio_sim_device_is_live_unlocked(dev))
1284+
if (gpio_sim_device_is_live(dev))
12781285
return -EBUSY;
12791286

12801287
if (sysfs_streq(page, "input"))
@@ -1392,7 +1399,7 @@ gpio_sim_bank_config_make_line_group(struct config_group *group,
13921399

13931400
guard(mutex)(&dev->lock);
13941401

1395-
if (gpio_sim_device_is_live_unlocked(dev))
1402+
if (gpio_sim_device_is_live(dev))
13961403
return ERR_PTR(-EBUSY);
13971404

13981405
line = kzalloc(sizeof(*line), GFP_KERNEL);
@@ -1445,7 +1452,7 @@ gpio_sim_device_config_make_bank_group(struct config_group *group,
14451452

14461453
guard(mutex)(&dev->lock);
14471454

1448-
if (gpio_sim_device_is_live_unlocked(dev))
1455+
if (gpio_sim_device_is_live(dev))
14491456
return ERR_PTR(-EBUSY);
14501457

14511458
bank = kzalloc(sizeof(*bank), GFP_KERNEL);
@@ -1467,8 +1474,8 @@ static void gpio_sim_device_config_group_release(struct config_item *item)
14671474
struct gpio_sim_device *dev = to_gpio_sim_device(item);
14681475

14691476
scoped_guard(mutex, &dev->lock) {
1470-
if (gpio_sim_device_is_live_unlocked(dev))
1471-
gpio_sim_device_deactivate_unlocked(dev);
1477+
if (gpio_sim_device_is_live(dev))
1478+
gpio_sim_device_deactivate(dev);
14721479
}
14731480

14741481
mutex_destroy(&dev->lock);

0 commit comments

Comments
 (0)