summaryrefslogtreecommitdiff
path: root/drivers/counter/counter-sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/counter/counter-sysfs.c')
-rw-r--r--drivers/counter/counter-sysfs.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
index 67a988851657..7cc4d1d523ea 100644
--- a/drivers/counter/counter-sysfs.c
+++ b/drivers/counter/counter-sysfs.c
@@ -11,6 +11,8 @@
#include <linux/kfifo.h>
#include <linux/kstrtox.h>
#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/types.h>
@@ -796,6 +798,7 @@ static int counter_events_queue_size_write(struct counter_device *counter,
{
DECLARE_KFIFO_PTR(events, struct counter_event);
int err;
+ unsigned long flags;
/* Allocate new events queue */
err = kfifo_alloc(&events, val, GFP_KERNEL);
@@ -803,8 +806,12 @@ static int counter_events_queue_size_write(struct counter_device *counter,
return err;
/* Swap in new events queue */
+ mutex_lock(&counter->events_out_lock);
+ spin_lock_irqsave(&counter->events_in_lock, flags);
kfifo_free(&counter->events);
counter->events.kfifo = events.kfifo;
+ spin_unlock_irqrestore(&counter->events_in_lock, flags);
+ mutex_unlock(&counter->events_out_lock);
return 0;
}