lkml.org 
[lkml]   [2020]   [Sep]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 20/23] gpio: mockup: add a lock for dummy device list
Date
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We'll soon add the possibility to create chips dynamically over debugfs
attributes. Since multiple threads will be able to create devices at
once: add a mutex to protect the device list.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/gpio/gpio-mockup.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index bc4609e047ef..1353239dc315 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -517,6 +517,7 @@ struct gpio_mockup_device {
};

static LIST_HEAD(gpio_mockup_devices);
+static DEFINE_MUTEX(gpio_mockup_devices_lock);

static void gpio_mockup_unregister_one_device(struct gpio_mockup_device *dev)
{
@@ -534,10 +535,14 @@ static void gpio_mockup_unregister_devices(void)
struct gpio_mockup_device *mockup_dev;
struct list_head *curr, *next;

+ mutex_lock(&gpio_mockup_devices_lock);
+
list_for_each_safe(curr, next, &gpio_mockup_devices) {
mockup_dev = list_entry(curr, struct gpio_mockup_device, list);
gpio_mockup_unregister_one_device(mockup_dev);
}
+
+ mutex_unlock(&gpio_mockup_devices_lock);
}

static __init char **gpio_mockup_make_line_names(const char *label,
@@ -588,7 +593,9 @@ static int __init gpio_mockup_register_device(struct property_entry *properties)
return PTR_ERR(mockup_dev->pdev);
}

+ mutex_lock(&gpio_mockup_devices_lock);
list_add(&mockup_dev->list, &gpio_mockup_devices);
+ mutex_unlock(&gpio_mockup_devices_lock);

return 0;
}
--
2.26.1
\
 
 \ /
  Last update: 2020-09-04 17:49    [W:0.231 / U:1.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site