Skip to content

Commit b1b102b

Browse files
committed
Merge tag 'counter-fixes-for-6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter into char-misc-next
William writes: Counter fixes for 6.15 A fix to prevent a race condition when accessing the Count enable component in interrupt-cnt. * tag 'counter-fixes-for-6.15' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/wbg/counter: counter: interrupt-cnt: Protect enable/disable OPs with mutex
2 parents 81e9edc + 7351312 commit b1b102b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/counter/interrupt-cnt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* Copyright (c) 2021 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
44
*/
55

6+
#include <linux/cleanup.h>
67
#include <linux/counter.h>
78
#include <linux/gpio/consumer.h>
89
#include <linux/interrupt.h>
910
#include <linux/irq.h>
1011
#include <linux/mod_devicetable.h>
1112
#include <linux/module.h>
13+
#include <linux/mutex.h>
1214
#include <linux/platform_device.h>
1315
#include <linux/types.h>
1416

@@ -19,6 +21,7 @@ struct interrupt_cnt_priv {
1921
struct gpio_desc *gpio;
2022
int irq;
2123
bool enabled;
24+
struct mutex lock;
2225
struct counter_signal signals;
2326
struct counter_synapse synapses;
2427
struct counter_count cnts;
@@ -41,6 +44,8 @@ static int interrupt_cnt_enable_read(struct counter_device *counter,
4144
{
4245
struct interrupt_cnt_priv *priv = counter_priv(counter);
4346

47+
guard(mutex)(&priv->lock);
48+
4449
*enable = priv->enabled;
4550

4651
return 0;
@@ -51,6 +56,8 @@ static int interrupt_cnt_enable_write(struct counter_device *counter,
5156
{
5257
struct interrupt_cnt_priv *priv = counter_priv(counter);
5358

59+
guard(mutex)(&priv->lock);
60+
5461
if (priv->enabled == enable)
5562
return 0;
5663

@@ -227,6 +234,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
227234
if (ret)
228235
return ret;
229236

237+
mutex_init(&priv->lock);
238+
230239
ret = devm_counter_add(dev, counter);
231240
if (ret < 0)
232241
return dev_err_probe(dev, ret, "Failed to add counter\n");

0 commit comments

Comments
 (0)