[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200904154547.3836-21-brgl@bgdev.pl>
Date: Fri, 4 Sep 2020 17:45:44 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Linus Walleij <linus.walleij@...aro.org>,
Jonathan Corbet <corbet@....net>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Kent Gibson <warthog618@...il.com>
Cc: linux-gpio@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: [PATCH 20/23] gpio: mockup: add a lock for dummy device list
From: Bartosz Golaszewski <bgolaszewski@...libre.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@...libre.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
Powered by blists - more mailing lists