Received: by 2002:ab2:2441:0:b0:1f3:1f8c:d0c6 with SMTP id k1csp184749lqe; Thu, 4 Apr 2024 03:50:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmpyWBKTFh0kdkYK65uzWz9RIxHV2LjXN4851la+5yXyjcfK8vGQC1j7eBzlWLGEld3s4+/68kDF9BFCEnKCZmwtSozJ9B9kK69Cpgjg== X-Google-Smtp-Source: AGHT+IH5m2+BYdO3fbwEdrcvedJ/ZjA3Qx9Y7EwIBSgc7GWmVw/zXzcOBT1MDMPRXQW+PtTCY57z X-Received: by 2002:a50:aad7:0:b0:56b:9f7c:3c32 with SMTP id r23-20020a50aad7000000b0056b9f7c3c32mr1275113edc.12.1712227844145; Thu, 04 Apr 2024 03:50:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712227843; cv=pass; d=google.com; s=arc-20160816; b=BAI4bUQfa+Qovp/IO6RRrhMlihKM0/v3EjZJKDCtAvJMvaFbGft214UQ6nFQi48mTv s2V6vWFFQtY71XK01VvaOMBbymu3igJ6ZsYV8/N5NZYMGSsGTrO7dYbD2ynAgQawRW3J bGHP9ws1aufLPG66fHJ4ge0K3t9y1+YxfbtPER/unEQURDHpZdKsf2aDH2AdfJa3uE7d ajUVLkiNt+QtEs3kmp8t5UGb9ckBEhvcep6fgXpP4JuXvODvnOSdlAXsYW7uZOaccwmC 8gjeoUBpSwyT1l+QShUwK37H5aZ7RrwL2RwPADec0DGBvMl4NGNj1IKkHzwwYdS+nQPA h0Gg== 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=vvcy5qA/001P/DJn8qH6Es3PFWz6g4h0ZGJnWiBlPKY=; fh=KsVfM5wJAwSmWlBDhQUIuzi3h8aTwgJEe33eqLJyRj0=; b=yHP00UbU17jbchpIJJimyhxstwWpQ3KbAsDhHMHjsrV6kH3MoGbKDDwAAddZ/6Ysu3 /OvW8xO14s0radbpfjpbcYGj0UTUGQvAUxEemUHQRCioCnjErQYfuMmSa9TT2nGXWv+h ooKciz+pHrQB3iL6BNKkI6laV1nw0yd+AQa58VygiPee0sAdjp2Ev50WMlaS7rUgBBoh XlIq3p38vtkls4FjHkz+rsTP7FNq61ugKtCBnnD/glkCCsDZ7O27UDtbPlSmcYSSvPO0 /XMJSmRA+x+RtBVSuBosd/jbpdzml8NXkPg2HJzIbhGHsPCtBNtM1+5YlD70XiUsM+fk Jsxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OLh9z78u; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-131258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131258-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p19-20020a50cd93000000b0056df97dbff3si1943548edi.68.2024.04.04.03.50.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 03:50:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OLh9z78u; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-131258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131258-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 456D61F2214B for ; Thu, 4 Apr 2024 10:50:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F87581ADB; Thu, 4 Apr 2024 10:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OLh9z78u" 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 ED6D7763EE; Thu, 4 Apr 2024 10:50:21 +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=1712227823; cv=none; b=R/Kto6UkNegD+jxzLnZhpORoq4YoQ4dx9ppEWIQFvNYvcvJWuTw0fli+XntboWDyqoMTysZdZjKJJvbQvEobGIEdWlKm6fBvaocP8CVACYhxGVYcwRAN7QYaKFweLDxBHuzjx0F7ecN81f6hyssiamIy7C8Hke4sfM/dF+pBCzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712227823; c=relaxed/simple; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LfO+GYIJi9VCbB9WvBKhnDt8E9aHxXNKH0hQ4qLFfTI6Kwy4ko4zuMY+Od5wZgClXD53RYa5X9WP4/LQ1hSEyOrNKzoxR8G/TuEvSdEdydTAfrvwNXD4UcP1dJXYwCX07FqkfYW0J13aC1D4iyUEBr86m4e+lBL4TX2mTEBzhis= 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=OLh9z78u; 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 E98F0497; Thu, 4 Apr 2024 12:49:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712227782; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OLh9z78uq4/6oxcxx8HUKvN1cVGnWoTJd+O7pSlZyHtGgRsXXjptHt94pT1wMO9O2 IrE2lc2rp90y6SxkK26LFN5T48by6xG6QF99FFQwpu/LTo5xEaLBQVUhYYZNdK58Kn UOg46PcSPjWsqct/APPTy85f4n+sMBeHZ+taZ/Ds= From: Tomi Valkeinen Date: Thu, 04 Apr 2024 13:50:00 +0300 Subject: [PATCH 1/4] 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: <20240404-enable-streams-impro-v1-1-1017a35bbe07@ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> In-Reply-To: <20240404-enable-streams-impro-v1-0-1017a35bbe07@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=2166; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmDoXp9Ioox00px095fK3OkdCk2nenPvIPOBdo9 yS5VNab3nKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg6F6QAKCRD6PaqMvJYe 9dIrD/4ihVQivaoXNrP5+biyesLF18AwDelyQtwSl9Bv28mUwz2yiTbVSbKqe99MJcH1rGqDdMa sqTQflMpXgTffa0J5oaXnYN6Dz6dsu4Hz0xpjRtD5NlGemmVUfC5DbhrX1hMlZR97j8k0zAX/67 xzg+I+5HcvpN9tLG30hoSRawtF5nwWTKWFg/ktP6E78eqYcObuC+FBTJ9mzZp+I+1DAgnSlD8M7 52hFg+CzzJSCVOYw67dzk8fKMFfIBXyBZzxnnJvV64kXtK9w6S1vrHOaJSR1V3hW04Qc3dD3KjA ECJtGGYLLwTPCChhynw6SKMwgkkGvinzEjwE0e7sER8RzhYsaeqW/v6DGBS4Z7UFrYQ0pe099/p s5NJV71C24y4vbvWo6k6ZoUTvPM8RcW/y/xxu+p3jSWVBTCU9YQvUrkbh/KNxTyZn5yeEsUqxzO Y96DXVZHWJBwEJ/FGWieGnB4bub4l7aecID4m6+eWfntPPBKfwDwwM3BGxiSZuJGRAHRwoT8+Fr xE5Y2COyl8ILnKxdZqoBFNOEo5T6o2dJ+uLx9K2LJx3bvEjWnnw+o6NYILwC7M5q/8DC90XoSCz DI1Ik++/ZPEz5dzOZbkUuSJVDslzvbEfbjGVci385wj1wWvtfjckaWIxPi9gBrFZJWkzS2exDyJ WrcZ8ZyfGB+/S/A== 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 4c6198c48dd6..b90b5185e87f 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1519,6 +1519,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 = sd->ops && sd->ops->video && sd->ops->video->s_stream; + has_enable_streams = sd->ops && sd->ops->pad && sd->ops->pad->enable_streams; + has_disable_streams = sd->ops && sd->ops->pad && sd->ops->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