From patchwork Tue Jan 16 08:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13520577 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 E3554125B4 for ; Tue, 16 Jan 2024 08:42:42 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YKVOqW8c" Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E33AA15B5; Tue, 16 Jan 2024 09:41:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705394491; bh=Fsv79vfJVDgy16Ho0gzisenc13noK5AwdIDcfBOnqSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YKVOqW8cVvEfcidrnd03ip/sWE10yBZl2MjlyXAwLcgF3jH7c1pU3QPxVUtrCdfm0 yNlo5qbomddesajopZK0K1By8jhk/S70PbcQVdInQtAlWGDMueb279dcp+3BOKgNPE /Sqre8v2HRyLhn26ont4n8UslCmaCSyPcZVGnF68= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Alexander Shiyan , Fabio Estevam , Frieder Schrempf , Jacopo Mondi , Kieran Bingham , Marek Vasut , Martin Kepplinger , Rui Miguel Silva , Sakari Ailus , Tim Harvey , Purism Kernel Team Subject: [PATCH v2 2/7] media: mc: Fix flags handling when creating pad links Date: Tue, 16 Jan 2024 10:42:35 +0200 Message-ID: <20240116084240.14228-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116084240.14228-1-laurent.pinchart@ideasonboard.com> References: <20240116084240.14228-1-laurent.pinchart@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The media_create_pad_link() function doesn't correctly clear reject link type flags, nor does it set the DATA_LINK flag. It only works because the MEDIA_LNK_FL_DATA_LINK flag's value is 0. Fix it by returning an error if any link type flag is set. This doesn't introduce any regression, as nobody calls the media_create_pad_link() function with link type flags (easily checked by grepping for the flag in the source code, there are very few hits). Set the MEDIA_LNK_FL_DATA_LINK explicitly, which is a no-op that the compiler will optimize out, but is still useful to make the code more explicit and easier to understand. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus --- drivers/media/mc/mc-entity.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index a6f28366106f..7839e3f68efa 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -1092,6 +1092,11 @@ media_create_pad_link(struct media_entity *source, u16 source_pad, struct media_link *link; struct media_link *backlink; + if (flags & MEDIA_LNK_FL_LINK_TYPE) + return -EINVAL; + + flags |= MEDIA_LNK_FL_DATA_LINK; + if (WARN_ON(!source || !sink) || WARN_ON(source_pad >= source->num_pads) || WARN_ON(sink_pad >= sink->num_pads)) @@ -1107,7 +1112,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad, link->source = &source->pads[source_pad]; link->sink = &sink->pads[sink_pad]; - link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK; + link->flags = flags; /* Initialize graph object embedded at the new link */ media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,