mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
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
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
* Copyright (c) 2021 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
|
||||
*/
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/counter.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
@@ -19,6 +21,7 @@ struct interrupt_cnt_priv {
|
||||
struct gpio_desc *gpio;
|
||||
int irq;
|
||||
bool enabled;
|
||||
struct mutex lock;
|
||||
struct counter_signal signals;
|
||||
struct counter_synapse synapses;
|
||||
struct counter_count cnts;
|
||||
@@ -41,6 +44,8 @@ static int interrupt_cnt_enable_read(struct counter_device *counter,
|
||||
{
|
||||
struct interrupt_cnt_priv *priv = counter_priv(counter);
|
||||
|
||||
guard(mutex)(&priv->lock);
|
||||
|
||||
*enable = priv->enabled;
|
||||
|
||||
return 0;
|
||||
@@ -51,6 +56,8 @@ static int interrupt_cnt_enable_write(struct counter_device *counter,
|
||||
{
|
||||
struct interrupt_cnt_priv *priv = counter_priv(counter);
|
||||
|
||||
guard(mutex)(&priv->lock);
|
||||
|
||||
if (priv->enabled == enable)
|
||||
return 0;
|
||||
|
||||
@@ -227,6 +234,8 @@ static int interrupt_cnt_probe(struct platform_device *pdev)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
mutex_init(&priv->lock);
|
||||
|
||||
ret = devm_counter_add(dev, counter);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(dev, ret, "Failed to add counter\n");
|
||||
|
||||
Reference in New Issue
Block a user