Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp568535lqp; Fri, 5 Apr 2024 02:16:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVk7d1jCg/nLLjYwKlBU0iZAKcoNr1nsDTXbVccISWakLZu639McMhuCAE4obExniVqnbsO10VGOBAQ5SNSxrgJMPKq7nezMW8h/aI/9w== X-Google-Smtp-Source: AGHT+IGkK4Cyr2twS/q3mPML2vMLJjPHw8wSsH2p0pSyYv8ibvDEMoU+u0sU9HsANlen2QOo+pJS X-Received: by 2002:a17:902:f690:b0:1e0:648e:8336 with SMTP id l16-20020a170902f69000b001e0648e8336mr945761plg.4.1712308578271; Fri, 05 Apr 2024 02:16:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712308578; cv=pass; d=google.com; s=arc-20160816; b=FrjZuutxWlc6vMefvXx8sqPIJxEEnpkCHuVwCwSTwelFR5mmBOkdHNI1/+C7JuU3bv ewK4E1+yQuTnm6KZRSwBCIrrGiWeB6Np8t1+dIKCq5aDOjlMtk2LYgxLXPaKbwFPTeAk cFKC4dEMyIUebTpuu164lGE7NSVaqQrFP0MzFdgoOksuc3qitzsen2rQdJlAbwksTt6T oS9MHO9oAacLBCcGz3LZtGgQG3ppvdsAkx0c3xVtjQE4BzYovedLIxyaoG3COxiyI5zT 7I7gtCfSKH99l/OqqGy1LMVCJjlZuovtFZbTSyqCmnZRf36qLVGJrTl2CdJbv4nKDhJo CzEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=zuOn088+yOaLJNGYdIz8CcgATRefHw/GcjjgAtyzU/4=; fh=KsVfM5wJAwSmWlBDhQUIuzi3h8aTwgJEe33eqLJyRj0=; b=zmSDHrQT9G5ZDusjOO2/Wzk+7AeawI1nSROhFIzqC2Tx3sCteogbcVB1GgWxCHKoMg FEF7No0ngEpE+J6hRj0MyfT99zE4ktoEkDxY1S5EVf+G0qjbUVqKi49oYml5zOsxLBui FiqrvpSMb1uY29rEx7nzvQ6N2aowmDAgR2eQ53iMXmCf2/7lvhneIRnoAMvvOVAoU04R 6XKcexeYdcJ6nwUWkuABfuc5qSuUrPTlMFlLGkn0UE2X32qA6zojgh6ulkMLEGaoXx0g 3GCrJN6D7KT+hxUOUllo3PqDPvbB7jtNggsleK3Y336pqOssAK26LvZumMVsEHi89wLO H6qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=I1M8DpC7; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-132712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132712-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b8-20020a170902d50800b001e2bb09625fsi1044754plg.16.2024.04.05.02.16.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 02:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=I1M8DpC7; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-132712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132712-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 67F73B2281A for ; Fri, 5 Apr 2024 09:15:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61D3016089A; Fri, 5 Apr 2024 09:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I1M8DpC7" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 03F1116078F; Fri, 5 Apr 2024 09:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712308488; cv=none; b=Iw0jI1+3PoXJsPrthmye28Z0osWLglNrKBqTLDI9eg07IqKs5hX+BmV5GCEKhi4JnETOoJYdP25tu8W2XCSYfL1EmsQtzKrwEjSxBF8Z7DsonFrRjEk7T+jZJl+thGu9p5BKt40ZSe5JTJUhW++uNFzyzKB3+a1hx6BJgK5GpGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712308488; c=relaxed/simple; bh=ELI8oewYYbbwnpIW88NGWIlncp1y6aSu9PXgBDCA0Ko=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vih7QPfZ38zRAzGlQIsw8dxS0UPrS11CHmaJylts4RI8YJ2pZ1i95Q4C07cyCOXHbhJ/pR9pVDHYJPkLJVNBB/bQLFSgp7L/f9MwIP9kb790tfUpCjvN6wd+8/jgnVvvL8SQbqXQaX8QB/3KeR1mGejaNy/wiQ8fywEJ/kVLR9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=I1M8DpC7; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB2D6F0A; Fri, 5 Apr 2024 11:14:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712308444; bh=ELI8oewYYbbwnpIW88NGWIlncp1y6aSu9PXgBDCA0Ko=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=I1M8DpC741zgAa/IiVDMkphQWFwmbsOXnNcUpNvUWHi3P1qOXIKWAbqKgyp1lG+Jz 9uYr2X7Spm5XxU3hGsZLb7weBBd6v019vko38XEnPWOk55uWpXQ/udd3H63quP+Kbb LN9JRKdtzLUiTN//8IhxSqYeyK0viBS+QfN+CBZ8= From: Tomi Valkeinen Date: Fri, 05 Apr 2024 12:14:21 +0300 Subject: [PATCH v2 3/9] media: subdev: Add checks for subdev features 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240405-enable-streams-impro-v2-3-22bca967665d@ideasonboard.com> References: <20240405-enable-streams-impro-v2-0-22bca967665d@ideasonboard.com> In-Reply-To: <20240405-enable-streams-impro-v2-0-22bca967665d@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2128; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=ELI8oewYYbbwnpIW88NGWIlncp1y6aSu9PXgBDCA0Ko=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmD8D9YP56b5dScuJlvsojhKUzK6fiKF3/cSCKQ GEGoiQHDnmJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg/A/QAKCRD6PaqMvJYe 9VTlD/9d0TZn2qXB95p/F5QJl/0QbXM6BS+xUH/BLnTkj+mPTo7YLfM6lE8fDiBp5UnKVWVfV1H WIKmjhOMAuDXo+AyN+I48TuIN6+SSBQn31ZqlYuF+8KsZVwI4ndY0TkmF/o2I8K4N1st5xsP+1B Xq75XMw6NSqZ1wW3hqMF/RBX0cz0jUQwy3WQsagruBhR5K0jYHdR75Bu2wlHmOE/twYYjc/Ilmk DigjghXTvyk9bqySBI7QlErJUK4B/+1OVrpBmos5iKGHybx9/AEJLTOJesrN45eyV3VrPbEZ6uR v+9F3O7SgWru666pZAVyzh+Gk9jKsuWdWG751A6UffKBW/Z/vtiGe9n/wI8CwjBWDJpte1/haaY 9nWjlbKiT2gzYpE1dwYUNnuIAjDndycKI5JidbGPwYU9zAMINsucRso97Dd6JMPxkBFQSltrWro CbAEMfrWcM0Na+Q4yEOBL81e3eq/FqCukxd+t80CHWk2lIaM9WS4iT/tXDLRwHoXO/X7YQL1Vpm lt8n0c42lgtBBroIgjAmHyyGfSps6Ai8wA9xMIdA1Yr26/qKTWjlqvToSvMf6ocwiDYJARxy+Vp RuIw8Io/BYiWZxHyRG6a7RT6wQiwB2HoVQP9LyXmoFC0IqMN1trxIxZGpgetdYnAAaTiJ+Z97oP T6GlZq3P3RwGttg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Add some checks to verify that the subdev driver implements required features. A subdevice that supports streams (V4L2_SUBDEV_FL_STREAMS) must do one of the following: - Implement neither .enable/disable_streams() nor .s_stream(), if the subdev is part of a video driver that uses an internal method to enable the subdev. - Implement only .enable/disable_streams(), if support for legacy sink-side subdevices is not needed. - Implement .enable/disable_streams() and .s_stream(), if support for legacy sink-side subdevices is needed. At the moment the framework doesn't check this requirement. Add the check. Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index c8124919b92c..a15a41576918 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1532,6 +1532,33 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, struct lock_class_key *key) { struct v4l2_subdev_state *state; + struct device *dev = sd->dev; + bool has_disable_streams; + bool has_enable_streams; + bool has_s_stream; + + /* Check that the subdevice implements the required features */ + + has_s_stream = v4l2_subdev_has_op(sd, video, s_stream); + has_enable_streams = v4l2_subdev_has_op(sd, pad, enable_streams); + has_disable_streams = v4l2_subdev_has_op(sd, pad, disable_streams); + + if (has_enable_streams != has_disable_streams) { + dev_err(dev, + "subdev '%s' must implement both or neither of .enable_streams() and .disable_streams()\n", + sd->name); + return -EINVAL; + } + + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + if (has_s_stream && !has_enable_streams) { + dev_err(dev, + "subdev '%s' must implement .enable/disable_streams()\n", + sd->name); + + return -EINVAL; + } + } state = __v4l2_subdev_state_alloc(sd, name, key); if (IS_ERR(state)) -- 2.34.1