From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DADB33033D6; Mon, 4 May 2026 07:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777881400; cv=none; b=TNQOFLWxc9GobZLBNU4EMbePqIUOCTaazIr8huD5wCBorcX6oduEcghk8u/jiGVmBBrXK+aCb+OAEwu+Li7eG7laYEnzJBu64csosg1OFk/gjPf62BJorIMmN39BQv9UJsk0nyIaxqfzJPWQ6ng/vvSMv7dVvAdazsPLjT9u9gY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777881400; c=relaxed/simple; bh=EU6GNMPxyqZpjatfpAqkrmjlNPcqAxcQGexzOkAfu0w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ESSl03gMzroynf7IX4DcywvuygrBH7bphw+YmOSq01Ged/WhiM5hMf6wZTWaRD0OgYWJEUq8J2m1uuGwJUi5y9OQ38fFE/BCoAY8YJa8SpleWFg1s10u0lB8v8s4mDwBwjDW5gbV8Al3QSh4GpUDi05LfphMexXOYTS0rDtnPcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=LrXLITtU; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LrXLITtU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777881400; x=1809417400; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=EU6GNMPxyqZpjatfpAqkrmjlNPcqAxcQGexzOkAfu0w=; b=LrXLITtUxdHC4SWJ/MEhJWbn4KLyvQS1GeetJRLWcpyXOtDGWKqvA8sh b3O5XS233WdtJCrqLr4Pexw9+QLKEzWqGaPgL+wJzlBVbafSGnXImTOD3 C55eYmWtGG3hz60u91mj5lo9tg6du9JLqoqP+CWhJNdgEObQ0LB0g/Kze xYmmko+8x9D8CNQ8gKp1JKSradRi9l52t/JdyFjdvpfwQLUpRYIefOIRx TeAAdBXSd8NWtiROuBewxEtbk14NouM/Gdd+V2VAP1xqcsxIduIk7lIq9 v2CVpxwM/blXDsZeEI928C9ut5iDImqV13ZfEddKnbQxVWWnvzbLdp4Ki w==; X-CSE-ConnectionGUID: X6hIBdWnRWSufaSfY57znQ== X-CSE-MsgGUID: N60SBKrgTaijisu7eI4eXA== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="78441258" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="78441258" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 00:56:39 -0700 X-CSE-ConnectionGUID: lCvPEamETZq0u/3UJ7xUqg== X-CSE-MsgGUID: pT1gv9KjQPilMC7nT4onIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="235705935" Received: from fpallare-mobl4.ger.corp.intel.com (HELO kekkonen.fi.intel.com) ([10.245.245.114]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 00:56:36 -0700 Received: from kekkonen.localdomain (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id A7621121CC4; Mon, 04 May 2026 10:56:34 +0300 (EEST) Date: Mon, 4 May 2026 10:56:34 +0300 Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo From: Sakari Ailus To: Svyatoslav Ryhel Cc: Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Mauro Carvalho Chehab , 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 Message-ID: References: <20260503164445.215540-1-clamor95@gmail.com> <20260503164445.215540-4-clamor95@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Svyatoslav, On Mon, May 04, 2026 at 10:37:40AM +0300, Svyatoslav Ryhel wrote: > пн, 4 трав. 2026 р. о 09:26 Sakari Ailus пише: > > > > 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 > > > --- > > > 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. > > > > Control handler mutexes are per device, but both devices share the > same hardware so those mutexes will not prevent simultaneous access > from both devices. For this reason driver's own mutex is used. Right. You could still use one for the other handler. Feel free to keep it as-is, too. > > > > > > > rval = v4l2_async_register_subdev(&flash->subdev_led[led_no]); > > > if (rval < 0) { > > -- Sakari Ailus