Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp266174lqj; Wed, 10 Apr 2024 09:45:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKEJ5RbeHl25e1Fh0fje7zw3T/xelgz77zcMJcZCELzv9KfKyqvUvxQGMnW47Y8DsnuaDVZg+PxZVuqY40VMGmgZ9+GZCpDirWbErtbA== X-Google-Smtp-Source: AGHT+IF9WO7lIcfZPGsMgNdrlcBJosSaldTJHj6SDHhfvtjoIF6LaU4RVAzap2sk9GDgvbFlKOa0 X-Received: by 2002:a05:6a21:628:b0:1a9:6bd1:d11a with SMTP id ll40-20020a056a21062800b001a96bd1d11amr1381758pzb.11.1712767524198; Wed, 10 Apr 2024 09:45:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712767524; cv=pass; d=google.com; s=arc-20160816; b=Hw2rRiATcTJb4L7SpFgcZUrYOJD6Dr7Dba+o5JaAama8kloUd6JKdfrbqFQZoA/qOK aYjPv1J7jOnIietBdwuMnFV2X0XyIM/pIxDfXZz9mqJJTbVICkK2k8M27L9/fnp0tbmE tiIthnarEStIfUAf2Tga4GIpFIbjm9AJApYcWYzqcKesIvyBks69sPjha6Lic6G2EIwx j9kKMf8MsWxqaMaRMV3C3ZFaPSXlzP99ZQqNSzrPwZbj0F2yPu3vYzGZBoL0DynnLWBU DUDK1dEsUE2t2MIuBmgaLIXDzs47AvENqI27ywcYfgGiSfYSHRMo4gfbPGeozXuMQmxF Umww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tK1OfHlysgVeHM+931AjbUidn3YfWnfHaxOID9pQSjQ=; fh=n/K3bH7jJKdL6ZyR7yxmoOILQv5JQlwWgm4OAkDAfIU=; b=UGtwtpQuz1kSERi8fPhsnfhTE0T0kM1h/XkEHlFh83mroIY4hxPf9XOXD4RuKQa7BQ J7WgO7yu6IAAbyjbDZznc1GN90We4RGQHdFJqYz9TBL5ZR/7/ayQ75KRQ8e/Goe5dOea qkJVDB+T1RrAHUUKaR9vyI6aaYI7UImKIN4gwzo2nOpKrrJJeyqe5p2szbemEeBfwUfZ 3zZAx5SA2ucOQfyvyr5tjZ4kfD6TBt3AwoNxELeir5+0PnbQ4XGpYliB5/R2vv3zxGW7 udwEywtex8JHasHEgprSxACiDl1LJI13gAYJheBnMJzKm8YvddCxSAlaoo99+PXzDukm 7PTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QZZl6Ra4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-138418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n26-20020a63721a000000b005dc87f9cc78si11353099pgc.556.2024.04.10.09.45.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 09:45:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QZZl6Ra4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-138418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 69438284D55 for ; Wed, 10 Apr 2024 11:35:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7619215B0E0; Wed, 10 Apr 2024 11:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QZZl6Ra4" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 03B7015991C; Wed, 10 Apr 2024 11:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712748924; cv=none; b=PjUIAb5qFZDfAnHKRW8Gi/j4McgWoGc3jVPGDWOjACxy8nTJq/WAsRbcEtlkQ29L1VhQ8xikLK8jEPO15eKAm5CxqpkQeB3DOQYe9yElFb4eXEumuC1+JEnCLSJCALVig2u50pnYXWdUKTr7iqu/y8MunFmf1qely8841l5sskA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712748924; c=relaxed/simple; bh=WAPU6TZq94HOOrduRuV0iJLOXnqI/oChsgFnm0w5Lpk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MynsS8eHF6pEzSeHQuAVvJx1GW0pCOx53OtJZYa/8F9o9bTqqVxhQwkUMg85GLTfnT9+yWELYNpBQM80uvH4J1DdzVwa+T5b8TgTAVWu4aG71YPYw1zpS7vTRqs+9Wo1PWyLdf37d4pvDjEZjncOpe6QVkDUNzE19oi/jlW3aXs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QZZl6Ra4; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712748923; x=1744284923; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=WAPU6TZq94HOOrduRuV0iJLOXnqI/oChsgFnm0w5Lpk=; b=QZZl6Ra4oG2a12vRN+IBiEkUAZy7GzxIggX0+2QPq8Zo9p9waZHMFnws JP+vVO+LobQQAf8nuoYrLuijtILwvJmxnA2sWTsF49CZ48IpGB2fL+nvq S++fsvSO1po7AuJfFfdiylpsJCHF+XueRyPZvcUoZx/q6l3u1Ktycqxxq fQInLL6itwLNr9Bh07PPSR7P+/XHm3g6y/8zX992MpstN7qaQVjiEQv4o xesSWiSNdiI4XuJ1E1aXZrvrRNY0u2MDVyaapD0P21W/6JqY/T9T/EOJv eWZB4gur7rdTxymwxno0gu58UEBRx5KS26xmqtdZHPx4qmp1UvGbDrboO g==; X-CSE-ConnectionGUID: YPftoa8CT+OCGnXkArxrBA== X-CSE-MsgGUID: Ojx0L/DuQCSh7gdeYvQYCA== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="25546973" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="25546973" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2024 04:35:22 -0700 X-CSE-ConnectionGUID: 4nFa3ea5SeqBf/jYwJ/3rg== X-CSE-MsgGUID: FugMJMziSXO9/htfTrxK+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="20549649" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2024 04:35:21 -0700 Received: from kekkonen.localdomain (localhost [127.0.0.1]) by kekkonen.fi.intel.com (Postfix) with SMTP id D76D11203E6; Wed, 10 Apr 2024 14:35:17 +0300 (EEST) Date: Wed, 10 Apr 2024 11:35:17 +0000 From: Sakari Ailus To: Hans de Goede Cc: linux-media@vger.kernel.org, tomi.valkeinen@ideasonboard.com, Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Umang Jain , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] media: v4l: Don't turn on privacy LED if streamon fails Message-ID: References: <20240410100301.658824-1-sakari.ailus@linux.intel.com> <50457efb-f145-4eac-a625-28e3bfc8a7af@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Apr 10, 2024 at 11:31:48AM +0000, Sakari Ailus wrote: > Hi Hans, > > Thanks for the review. > > On Wed, Apr 10, 2024 at 12:12:33PM +0200, Hans de Goede wrote: > > Hi Sakari, > > > > Thank you for fixing this. > > > > On 4/10/24 12:03 PM, Sakari Ailus wrote: > > > Turn on the privacy LED only if streamon succeeds. This can be done after > > > enabling streaming on the sensor. > > > > > > Fixes: b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present") > > > Signed-off-by: Sakari Ailus > > > --- > > > drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++--------- > > > 1 file changed, 10 insertions(+), 9 deletions(-) > > > > > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c > > > index 4c6198c48dd6..acb7c3003ab6 100644 > > > --- a/drivers/media/v4l2-core/v4l2-subdev.c > > > +++ b/drivers/media/v4l2-core/v4l2-subdev.c > > > @@ -412,15 +412,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) > > > if (WARN_ON(!!sd->enabled_streams == !!enable)) > > > return 0; > > > > > > -#if IS_REACHABLE(CONFIG_LEDS_CLASS) > > > - if (!IS_ERR_OR_NULL(sd->privacy_led)) { > > > - if (enable) > > > - led_set_brightness(sd->privacy_led, > > > - sd->privacy_led->max_brightness); > > > - else > > > - led_set_brightness(sd->privacy_led, 0); > > > - } > > > -#endif > > > ret = sd->ops->video->s_stream(sd, enable); > > > > > > if (!enable && ret < 0) { > > > @@ -431,6 +422,16 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) > > > if (!ret) > > > sd->enabled_streams = enable ? BIT(0) : 0; > > > > > > +#if IS_REACHABLE(CONFIG_LEDS_CLASS) > > > + if (!IS_ERR_OR_NULL(sd->privacy_led) && !(enable && ret < 0)) { > > > > There already is a: > > > > if (!enable && ret < 0) > > ret = 0; > > > > block above to ignore stream-off errors, so you can just test for: > > > > if (!ret && !IS_ERR_OR_NULL(sd->privacy_led)) { > > ... > > } > > > > And then you can move the whole block to inside the existing: > > > > if (!ret) > > sd->enabled_streams = enable ? BIT(0) : 0; > > > > block, so you get something like this: > > > > if (!ret) { > > sd->enabled_streams = enable ? BIT(0) : 0; > > #if IS_REACHABLE(CONFIG_LEDS_CLASS) > > if (!IS_ERR_OR_NULL(sd->privacy_led)) { > > if (enable) > > led_set_brightness(sd->privacy_led, > > sd->privacy_led->max_brightness); > > else > > led_set_brightness(sd->privacy_led, 0); > > } > > #endif > > } > > Seems reasonable, I'll send v2. I was a bit too fast to hit y. ret will be non-zero if streamon fails (enable non-zero), in which case the LED needs to be turned off. So you can't have !ret condition for all LED control. > > > > > Which then cleans up nicely by Tomi's patch > > introducing the privacy LED helper functions, > > to something like this: > > > > if (!ret { > > if (enable) { > > sd->enabled_streams = BIT(0); > > v4l2_subdev_enable_privacy_led(sd); > > } else { > > sd->enabled_streams = 0; > > v4l2_subdev_disable_privacy_led(sd); > > } > > } > > > -- Sakari Ailus