@@ -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);