From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Svyatoslav Ryhel <clamor95@gmail.com>
Cc: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Subject: Re: [PATCH v5 3/6] media: i2c: lm3560: Optimize mutex lock usage
Date: Mon, 4 May 2026 09:26:44 +0300 [thread overview]
Message-ID: <afg8JPS3KGMO4xj9@kekkonen.localdomain> (raw)
In-Reply-To: <20260503164445.215540-4-clamor95@gmail.com>
Hi Svyatoslav,
On Sun, May 03, 2026 at 07:44:42PM +0300, Svyatoslav Ryhel wrote:
> Pass the device's own mutex lock to the control handler so that the media
> framework can handle control access instead of managing it manually. The
> lock must be common to both sub-devices since they share same hardware,
> so the individual sub-device locks will not work here.
>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
> drivers/media/i2c/lm3560.c | 19 ++++++-------------
> 1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
> index edfb07587cab..5b568ed9536b 100644
> --- a/drivers/media/i2c/lm3560.c
> +++ b/drivers/media/i2c/lm3560.c
> @@ -162,14 +162,12 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
> int rval = -EINVAL;
>
> - mutex_lock(&flash->lock);
> -
> if (ctrl->id == V4L2_CID_FLASH_FAULT) {
> s32 fault = 0;
> unsigned int reg_val;
> rval = regmap_read(flash->regmap, REG_FLAG, ®_val);
> if (rval < 0)
> - goto out;
> + return rval;
> if (reg_val & FAULT_SHORT_CIRCUIT)
> fault |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
> if (reg_val & FAULT_OVERTEMP)
> @@ -179,8 +177,6 @@ static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> ctrl->cur.val = fault;
> }
>
> -out:
> - mutex_unlock(&flash->lock);
> return rval;
> }
>
> @@ -190,8 +186,6 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> u8 tout_bits;
> int rval = -EINVAL;
>
> - mutex_lock(&flash->lock);
> -
> switch (ctrl->id) {
> case V4L2_CID_FLASH_LED_MODE:
> flash->led_mode = ctrl->val;
> @@ -202,14 +196,12 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> case V4L2_CID_FLASH_STROBE_SOURCE:
> rval = regmap_update_bits(flash->regmap,
> REG_CONFIG1, 0x04, (ctrl->val) << 2);
> - if (rval < 0)
> - goto err_out;
> break;
>
> case V4L2_CID_FLASH_STROBE:
> if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) {
> rval = -EBUSY;
> - goto err_out;
> + break;
> }
> flash->led_mode = V4L2_FLASH_LED_MODE_FLASH;
> rval = lm3560_mode_ctrl(flash);
> @@ -218,7 +210,7 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> case V4L2_CID_FLASH_STROBE_STOP:
> if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH) {
> rval = -EBUSY;
> - goto err_out;
> + break;
> }
> flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
> rval = lm3560_mode_ctrl(flash);
> @@ -239,8 +231,6 @@ static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
> break;
> }
>
> -err_out:
> - mutex_unlock(&flash->lock);
> return rval;
> }
>
> @@ -328,6 +318,8 @@ static int lm3560_init_controls(struct lm3560_flash *flash,
> if (fault != NULL)
> fault->flags |= V4L2_CTRL_FLAG_VOLATILE;
>
> + hdl->lock = &flash->lock;
> +
> if (hdl->error)
> return hdl->error;
>
> @@ -363,6 +355,7 @@ static int lm3560_subdev_init(struct lm3560_flash *flash,
> if (rval < 0)
> goto err_out;
> flash->subdev_led[led_no].entity.function = MEDIA_ENT_F_FLASH;
> + flash->subdev_led[led_no].state_lock = &flash->lock;
I must have missed it earlier but you can use the control handler's mutex
here. As a result, I believe you can drop the driver's own mutex
altogether.
>
> rval = v4l2_async_register_subdev(&flash->subdev_led[led_no]);
> if (rval < 0) {
--
Kind regards,
Sakari Ailus
next prev parent reply other threads:[~2026-05-04 6:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 16:44 [PATCH v5 0/6] media: lm3560: convert to use OF bindings Svyatoslav Ryhel
2026-05-03 16:44 ` [PATCH v5 1/6] dt-bindings: leds: Document TI LM3560 Synchronous Boost Flash Driver Svyatoslav Ryhel
2026-05-03 16:44 ` [PATCH v5 2/6] media: i2c: lm3560: Fix v4l2 subdev registration Svyatoslav Ryhel
2026-05-03 16:44 ` [PATCH v5 3/6] media: i2c: lm3560: Optimize mutex lock usage Svyatoslav Ryhel
2026-05-04 6:26 ` Sakari Ailus [this message]
2026-05-04 7:37 ` Svyatoslav Ryhel
2026-05-04 7:56 ` Sakari Ailus
2026-05-03 16:44 ` [PATCH v5 4/6] media: i2c: lm3560: Convert to use OF bindings Svyatoslav Ryhel
2026-05-04 6:36 ` Sakari Ailus
2026-05-04 7:40 ` Svyatoslav Ryhel
2026-05-04 8:08 ` Sakari Ailus
2026-05-04 8:42 ` Svyatoslav Ryhel
2026-05-03 16:44 ` [PATCH v5 5/6] media: i2c: lm3560: Add support for PM features Svyatoslav Ryhel
2026-05-04 6:37 ` Sakari Ailus
2026-05-04 7:40 ` Svyatoslav Ryhel
2026-05-04 9:37 ` Svyatoslav Ryhel
2026-05-04 10:14 ` Sakari Ailus
2026-05-03 16:44 ` [PATCH v5 6/6] media: i2c: lm3560: Add proper support for LM3559 Svyatoslav Ryhel
2026-05-04 5:35 ` [PATCH v5 0/6] media: lm3560: convert to use OF bindings Svyatoslav Ryhel
2026-05-04 6:25 ` Sakari Ailus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afg8JPS3KGMO4xj9@kekkonen.localdomain \
--to=sakari.ailus@linux.intel.com \
--cc=clamor95@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=pavel@kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox