From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3D6A33EB06 for ; Mon, 23 Feb 2026 18:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771871542; cv=none; b=oAQQAMHcf/I5u0kfqIpQvdfo5mN90O4Gb5YaKmHRfeStVEBDqI+omwYiwG8glHyCV/m4TjW2wqc6fxmr4d2yPXlFMuu7Juhp+9bgu48R4x82oTq9yxdtjYZ6Jm9aMMwqj7FI/5/Ijnd6iTc47SwA8kxegrooiZYfzvyvmnX83Us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771871542; c=relaxed/simple; bh=v3+FRAqjRtsQmTAZeB7dmvPPRvfnEbhfGm1Zu6NB9/s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aTdjxxVHtjzJ6Z6BRW9g4XEiH/0AdA3CDnZc12n4oMJpBPHmPTHtwOHEWrHFqAfFXutbAPY/A5JIRKZZlDPxlNgoqh/yhNWldEVE7LqT3z2PyteCCbhS1r+nHRE1IIIIkxrSSUyW55OQUFkaJRMxqxHPO5PFb6MzmqX0QJ53Ydg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PVXER1qC; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PVXER1qC" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43626796202so3995083f8f.3 for ; Mon, 23 Feb 2026 10:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771871539; x=1772476339; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HmyupKJdg6mPX/153MnpkbuujC4Mu/oGomWgUFW6jc4=; b=PVXER1qCePolvPccOocsNY0jOiwqm48E5P4NKrQfrW66/JwXxxy+U7BkovVsOCwcpK nS4BDvQtYdf3ij9RvejD1OCaareLnqtoJ3dNYOznMF4z3zjPMf7YBWC5jzOfnnl+2IR/ AdoSc3CmblB1tWdVh/de9GMapVE5rfnHOsfGUKKIiNwbY2rhwh/V1U9w/KGqtkJLWWLn 0kNWz3XWUhW1GHrVCCqqpgMIw5uUad7qz06kS9cuw0/FfEB2On9Vnsagu45gcBcS0KoR o6O8/IpbvZO5r5oSD0EkQHtL/7+8+tdoBw76fds/LqG9rtJeaNWUvDFL/ijTu2IiF6Xh 2DfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771871539; x=1772476339; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HmyupKJdg6mPX/153MnpkbuujC4Mu/oGomWgUFW6jc4=; b=X9lcEKyyRlKCEkdtsAYyHCCPnSIIhDMpvp0GtLwR4EveGKqCAqamfW1mzvqTND0QjQ IcUCyQViOFiATMxPeGfwBshed1axhx1Zi+SP36DrvwugPseWlCuYoED5YYv8Aru4xNll u6svx8XP+PJ9+zlzTxYL3AW4X4ZWQlsjezMqpzzFVDLJWbwxjuxtIDCfRYaXy5hZysn2 2CYmdjP4XGcTnjUnw3yBngT0DEW4Rf0aSucpjqFaKT2/eDOPVKiTNNhw9FOKJSyr0Zj+ ne93Uqbi6tH+0TP4jB7JdsYHNsvoUtJr8Q8inI19g2rWW6jDFVDu4qTOaV0yDay+s8Ys X1+A== X-Forwarded-Encrypted: i=1; AJvYcCW+++iWOmDCIT6qCT+V7cOOmX1ML1upc/8cHw8YqR+2ho2NKoJPwTYmGW2A35EJG2CwFzrAel2bR4X2/AM=@vger.kernel.org X-Gm-Message-State: AOJu0YyFm4hJrVYXmGjCg91OUsSDnoA6rtWz7PlmTUivNAUP1as/loWJ D9nFCKFt4VWu4LV2lPl7GA4YaIw8YqsSte6I9osl2TK0xoao0u/y82k7 X-Gm-Gg: ATEYQzwRY/vnT61pP2qkMh8gIADCm85zSm27WesNfcocwTmW6/9wuvAh2kYPvZOpMzZ M99Kzx02+FynTDbGDyOiTWRGpFOaTxGSR9/i3chEKgx0mpABJZeK3HZvDIUoRPLC63dPWQNIZeu eSGYvMYm9LRLz71+n72+nhELnrPOHJAbpPbQxp7Xk1ltRv2bmarURHPKKM/H75qHgMyrHSeby8q M6Gjq2q15GMlF2fVbDknXcGSeHfHYPXg4PYJVyn6JlEkU2Fn9SS9xL1YQgT/9xo/2GmnM+tLtJz xgccj6d4A9oTJjHaBwUNmqOkhqRUWRTDd1UpPJxj6xRYBFHuJWz6fUu3yHOPwAOZwY3aIhcoWI+ mxoxSQdgm6xjXd8LUiqATbnv8/v88XNOtJjIGy+rK0aeeGNx+3FOIry8SaLjoGbBweTCpQdFWJg iMsD+xvUAKgrIiKl6A3h7h7gRhhXKi1J28SAw= X-Received: by 2002:a5d:5f83:0:b0:439:5ee1:f64f with SMTP id ffacd0b85a97d-4396f17b4a4mr15751428f8f.46.1771871538812; Mon, 23 Feb 2026 10:32:18 -0800 (PST) Received: from [192.168.0.131] ([194.183.54.57]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970bf9f77sm22730111f8f.5.2026.02.23.10.32.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Feb 2026 10:32:17 -0800 (PST) Message-ID: Date: Mon, 23 Feb 2026 19:32:16 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] media: v4l2-flash: Enter LED off state after file handle closed To: Sakari Ailus Cc: cy_huang@richtek.com, Mauro Carvalho Chehab , Bryan Wu , Kyungmin Park , roger-hy.wang@mediatek.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, laurent.pinchart@ideasonboard.com References: <1106c60cb96786ade1f60c692e566c408d7d8174.1768209230.git.cy_huang@richtek.com> Content-Language: en-US From: Jacek Anaszewski In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Sakari, On 2/23/26 10:43, Sakari Ailus wrote: > Hi Jacek, > > On Sat, Feb 21, 2026 at 04:48:48PM +0100, Jacek Anaszewski wrote: >> Hi ChiYuan, >> >> On 1/12/26 10:20, cy_huang@richtek.com wrote: >>> From: ChiYuan Huang >>> >>> To make sure LED enter off state after file handle is closed, initiatively >>> configure LED_MODE to NONE. This can guarantee whatever the previous state >>> is torch or strobe mode, the final state will be off. >>> >>> Cc: stable@vger.kernel.org >>> Fixes: 42bd6f59ae90 ("media: Add registration helpers for V4L2 flash sub-devices") >>> Signed-off-by: ChiYuan Huang >>> --- >>> Still cannot pass patch integration check, send v3 patch to fix all. >>> >>> v3 >>> - Remove 'Reported-by' tag >>> - Fix identation check for patch integration >>> >>> v2 >>> - Fix commit message redudant space cause patch robot parsing error >>> >>> Hi, >>> We encounter an issue. When the upper layer camera process is crashed, >>> if the new process did not reinit the LED, it will keeps the previous >>> state whatever it's in torch or strobe mode >>> >>> OS will handle the resource management. So when the process is crashed >>> or terminated, the 'close' API will be called to release resources. >>> That's why we add the initiative action to trigger LED off in file >>> handle close is called. >>> --- >>> drivers/media/v4l2-core/v4l2-flash-led-class.c | 6 ++++++ >>> 1 file changed, 6 insertions(+) >>> >>> diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c >>> index 355595a0fefa..46606f5cc192 100644 >>> --- a/drivers/media/v4l2-core/v4l2-flash-led-class.c >>> +++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c >>> @@ -623,6 +623,12 @@ static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) >>> return 0; >>> if (led_cdev) { >>> + /* If file handle is released, make sure LED enter off state */ >>> + ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[LED_MODE], >>> + V4L2_FLASH_LED_MODE_NONE); >>> + if (ret) >>> + return ret; >>> + >>> mutex_lock(&led_cdev->led_access); >>> if (v4l2_flash->ctrls[STROBE_SOURCE]) >>> >>> base-commit: 8ac28a6642d1cc8bac0632222e66add800b027fa >> >> The patch itself looks good, but while at it I started wondering >> if we shouldn't move below STROBE_SOURCE access before the lock. >> I don't see now, why we placed it there. >> >> Adding Sakari. > > Thanks for cc'ing me. > > The behaviour this patch changes has been around for a decade or so. I > wonder what breaks if we change it now. It works the same way as the sysfs > LED API, too, and I think common behaviour between the two APIs was the > reasoning back then as well. The thing is that v4l2_flash_open() disables LED sysfs interface via led_sysfs_disable() and v4l2_flash_close() enables it via led_sysfs_enable(). led_sysfs_{enable|disable}() modify the state of LED_SYSFS_DISABLE flag. Therefore it is only the led_sysfs_{enable|disable}() API that needs to be called under led_access lock, since the LED subsystem sysfs handlers test the LED_SYSFS_DISABLE flag under the same lock, and return -EBUSY in case it is set. The call to v4l2_flash_close() is synchronized internally in V4L2 core I believe. Therefore I think that we can safely move the "if (v4l2_flash->ctrls[STROBE_SOURCE])" condition before the lock. Otherwise we would have to put this new v4l2_ctrl_s_ctrl() call, added in this patch also under the lock because why not. It would spark questions in the future asking how it is different from the above "v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[LED_MODE]" case. -- Best regards, Jacek Anaszewski