* [PATCH 0/2] rcar-csi2: Serialize format cfg and improve mutex handling
@ 2021-08-15 2:49 Niklas Söderlund
2021-08-15 2:49 ` [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail Niklas Söderlund
2021-08-15 2:49 ` [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt Niklas Söderlund
0 siblings, 2 replies; 5+ messages in thread
From: Niklas Söderlund @ 2021-08-15 2:49 UTC (permalink / raw)
To: Hans Verkuil, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund
Hello Hans,
This series improves the mutex handling of the R-Car CSI-2 driver. While
working with other drivers it have surfaced that drivers are responsible
to serialize format configuration.
Patch 1/2 adds a bit of housekeeping to the mutex used in the driver
while patch 2/2 adds the format serialization.
The series is based on the latest media-tree and tested on M3-N and H3
ES2.0 without any regressions found.
Niklas Söderlund (2):
media: rcar-csi2: Cleanup mutex on remove and fail
media: rcar-csi2: Serialize access to set_fmt and get_fmt
drivers/media/platform/rcar-vin/rcar-csi2.c | 25 +++++++++++++++------
1 file changed, 18 insertions(+), 7 deletions(-)
--
2.32.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail
2021-08-15 2:49 [PATCH 0/2] rcar-csi2: Serialize format cfg and improve mutex handling Niklas Söderlund
@ 2021-08-15 2:49 ` Niklas Söderlund
2021-08-17 7:31 ` Jacopo Mondi
2021-08-15 2:49 ` [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt Niklas Söderlund
1 sibling, 1 reply; 5+ messages in thread
From: Niklas Söderlund @ 2021-08-15 2:49 UTC (permalink / raw)
To: Hans Verkuil, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund
The mutex was not destroyed on remove or failed probe, fix this.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/platform/rcar-vin/rcar-csi2.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index e28eff0396888f2d..a02573dbd5da4f62 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -1245,14 +1245,14 @@ static int rcsi2_probe(struct platform_device *pdev)
ret = rcsi2_probe_resources(priv, pdev);
if (ret) {
dev_err(priv->dev, "Failed to get resources\n");
- return ret;
+ goto error_mutex;
}
platform_set_drvdata(pdev, priv);
ret = rcsi2_parse_dt(priv);
if (ret)
- return ret;
+ goto error_mutex;
priv->subdev.owner = THIS_MODULE;
priv->subdev.dev = &pdev->dev;
@@ -1272,21 +1272,23 @@ static int rcsi2_probe(struct platform_device *pdev)
ret = media_entity_pads_init(&priv->subdev.entity, NR_OF_RCAR_CSI2_PAD,
priv->pads);
if (ret)
- goto error;
+ goto error_async;
pm_runtime_enable(&pdev->dev);
ret = v4l2_async_register_subdev(&priv->subdev);
if (ret < 0)
- goto error;
+ goto error_async;
dev_info(priv->dev, "%d lanes found\n", priv->lanes);
return 0;
-error:
+error_async:
v4l2_async_notifier_unregister(&priv->notifier);
v4l2_async_notifier_cleanup(&priv->notifier);
+error_mutex:
+ mutex_destroy(&priv->lock);
return ret;
}
@@ -1301,6 +1303,8 @@ static int rcsi2_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
+ mutex_destroy(&priv->lock);
+
return 0;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt
2021-08-15 2:49 [PATCH 0/2] rcar-csi2: Serialize format cfg and improve mutex handling Niklas Söderlund
2021-08-15 2:49 ` [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail Niklas Söderlund
@ 2021-08-15 2:49 ` Niklas Söderlund
2021-08-17 7:33 ` Jacopo Mondi
1 sibling, 1 reply; 5+ messages in thread
From: Niklas Söderlund @ 2021-08-15 2:49 UTC (permalink / raw)
To: Hans Verkuil, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund
The access to the internal storage of the format rcar_csi2.mf should be
serialized, extend the exciting lock mutex to also cover this.
While at it document the mutex.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/platform/rcar-vin/rcar-csi2.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index a02573dbd5da4f62..2fdfdc38de424c72 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -370,9 +370,8 @@ struct rcar_csi2 {
struct v4l2_subdev *remote;
unsigned int remote_pad;
+ struct mutex lock; /* Protects mf and stream_count. */
struct v4l2_mbus_framefmt mf;
-
- struct mutex lock;
int stream_count;
unsigned short lanes;
@@ -725,6 +724,8 @@ static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
struct rcar_csi2 *priv = sd_to_csi2(sd);
struct v4l2_mbus_framefmt *framefmt;
+ mutex_lock(&priv->lock);
+
if (!rcsi2_code_to_fmt(format->format.code))
format->format.code = rcar_csi2_formats[0].code;
@@ -735,6 +736,8 @@ static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
*framefmt = format->format;
}
+ mutex_unlock(&priv->lock);
+
return 0;
}
@@ -744,11 +747,15 @@ static int rcsi2_get_pad_format(struct v4l2_subdev *sd,
{
struct rcar_csi2 *priv = sd_to_csi2(sd);
+ mutex_lock(&priv->lock);
+
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
format->format = priv->mf;
else
format->format = *v4l2_subdev_get_try_format(sd, sd_state, 0);
+ mutex_unlock(&priv->lock);
+
return 0;
}
--
2.32.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail
2021-08-15 2:49 ` [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail Niklas Söderlund
@ 2021-08-17 7:31 ` Jacopo Mondi
0 siblings, 0 replies; 5+ messages in thread
From: Jacopo Mondi @ 2021-08-17 7:31 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: Hans Verkuil, linux-media, linux-renesas-soc
Hi Niklas,
On Sun, Aug 15, 2021 at 04:49:14AM +0200, Niklas Söderlund wrote:
> The mutex was not destroyed on remove or failed probe, fix this.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Looks good!
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Thanks
j
> ---
> drivers/media/platform/rcar-vin/rcar-csi2.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index e28eff0396888f2d..a02573dbd5da4f62 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -1245,14 +1245,14 @@ static int rcsi2_probe(struct platform_device *pdev)
> ret = rcsi2_probe_resources(priv, pdev);
> if (ret) {
> dev_err(priv->dev, "Failed to get resources\n");
> - return ret;
> + goto error_mutex;
> }
>
> platform_set_drvdata(pdev, priv);
>
> ret = rcsi2_parse_dt(priv);
> if (ret)
> - return ret;
> + goto error_mutex;
>
> priv->subdev.owner = THIS_MODULE;
> priv->subdev.dev = &pdev->dev;
> @@ -1272,21 +1272,23 @@ static int rcsi2_probe(struct platform_device *pdev)
> ret = media_entity_pads_init(&priv->subdev.entity, NR_OF_RCAR_CSI2_PAD,
> priv->pads);
> if (ret)
> - goto error;
> + goto error_async;
>
> pm_runtime_enable(&pdev->dev);
>
> ret = v4l2_async_register_subdev(&priv->subdev);
> if (ret < 0)
> - goto error;
> + goto error_async;
>
> dev_info(priv->dev, "%d lanes found\n", priv->lanes);
>
> return 0;
>
> -error:
> +error_async:
> v4l2_async_notifier_unregister(&priv->notifier);
> v4l2_async_notifier_cleanup(&priv->notifier);
> +error_mutex:
> + mutex_destroy(&priv->lock);
>
> return ret;
> }
> @@ -1301,6 +1303,8 @@ static int rcsi2_remove(struct platform_device *pdev)
>
> pm_runtime_disable(&pdev->dev);
>
> + mutex_destroy(&priv->lock);
> +
> return 0;
> }
>
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt
2021-08-15 2:49 ` [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt Niklas Söderlund
@ 2021-08-17 7:33 ` Jacopo Mondi
0 siblings, 0 replies; 5+ messages in thread
From: Jacopo Mondi @ 2021-08-17 7:33 UTC (permalink / raw)
To: Niklas Söderlund; +Cc: Hans Verkuil, linux-media, linux-renesas-soc
Hi Niklas,
On Sun, Aug 15, 2021 at 04:49:15AM +0200, Niklas Söderlund wrote:
> The access to the internal storage of the format rcar_csi2.mf should be
> serialized, extend the exciting lock mutex to also cover this.
truly an exciting lock mutex indeed! :D
>
> While at it document the mutex.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Thanks
j
> ---
> drivers/media/platform/rcar-vin/rcar-csi2.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index a02573dbd5da4f62..2fdfdc38de424c72 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -370,9 +370,8 @@ struct rcar_csi2 {
> struct v4l2_subdev *remote;
> unsigned int remote_pad;
>
> + struct mutex lock; /* Protects mf and stream_count. */
> struct v4l2_mbus_framefmt mf;
> -
> - struct mutex lock;
> int stream_count;
>
> unsigned short lanes;
> @@ -725,6 +724,8 @@ static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
> struct rcar_csi2 *priv = sd_to_csi2(sd);
> struct v4l2_mbus_framefmt *framefmt;
>
> + mutex_lock(&priv->lock);
> +
> if (!rcsi2_code_to_fmt(format->format.code))
> format->format.code = rcar_csi2_formats[0].code;
>
> @@ -735,6 +736,8 @@ static int rcsi2_set_pad_format(struct v4l2_subdev *sd,
> *framefmt = format->format;
> }
>
> + mutex_unlock(&priv->lock);
> +
> return 0;
> }
>
> @@ -744,11 +747,15 @@ static int rcsi2_get_pad_format(struct v4l2_subdev *sd,
> {
> struct rcar_csi2 *priv = sd_to_csi2(sd);
>
> + mutex_lock(&priv->lock);
> +
> if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
> format->format = priv->mf;
> else
> format->format = *v4l2_subdev_get_try_format(sd, sd_state, 0);
>
> + mutex_unlock(&priv->lock);
> +
> return 0;
> }
>
> --
> 2.32.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-17 7:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-15 2:49 [PATCH 0/2] rcar-csi2: Serialize format cfg and improve mutex handling Niklas Söderlund
2021-08-15 2:49 ` [PATCH 1/2] media: rcar-csi2: Cleanup mutex on remove and fail Niklas Söderlund
2021-08-17 7:31 ` Jacopo Mondi
2021-08-15 2:49 ` [PATCH 2/2] media: rcar-csi2: Serialize access to set_fmt and get_fmt Niklas Söderlund
2021-08-17 7:33 ` Jacopo Mondi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).