diff mbox series

[v8-rc1,12/20] sqaush! max9286: Lock format changes

Message ID 20200416104052.2643098-13-jacopo+renesas@jmondi.org (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series GMSL: max9286-v8-rc1 + RDAMC20-v8 | expand

Commit Message

Jacopo Mondi April 16, 2020, 10:40 a.m. UTC
From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

Provide a mutex to protect against format changes on the pads.  The
mutex can also be used to protect against control changes, or other
userspace facing interactions as necessary

Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 drivers/media/i2c/max9286.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 84173b8c2706..49b4d1830747 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -18,6 +18,7 @@ 
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/of_graph.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
@@ -157,6 +158,9 @@  struct max9286_priv {
 
 	struct v4l2_mbus_framefmt fmt[MAX9286_N_SINKS];
 
+	/* Protects controls and fmt structures */
+	struct mutex mutex;
+
 	unsigned int nsources;
 	unsigned int source_mask;
 	unsigned int route_mask;
@@ -680,7 +684,9 @@  static int max9286_set_fmt(struct v4l2_subdev *sd,
 	if (!cfg_fmt)
 		return -EINVAL;
 
+	mutex_lock(&priv->mutex);
 	*cfg_fmt = format->format;
+	mutex_unlock(&priv->mutex);
 
 	return 0;
 }
@@ -699,7 +705,9 @@  static int max9286_get_fmt(struct v4l2_subdev *sd,
 	if (!cfg_fmt)
 		return -EINVAL;
 
+	mutex_lock(&priv->mutex);
 	format->format = *cfg_fmt;
+	mutex_unlock(&priv->mutex);
 
 	return 0;
 }
@@ -1148,6 +1156,8 @@  static int max9286_probe(struct i2c_client *client)
 	if (!priv)
 		return -ENOMEM;
 
+	mutex_init(&priv->mutex);
+
 	priv->client = client;
 	i2c_set_clientdata(client, priv);