Commit b1b102bf authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'counter-fixes-for-6.15' of...

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
parents 81e9edc1 73513126
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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");