From patchwork Mon Jan 15 10:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 762959 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 B2BC317BA2 for ; Mon, 15 Jan 2024 10:30:36 +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="CUipmUTt" Received: from pendragon.ideasonboard.com (89-27-53-110.bb.dnainternet.fi [89.27.53.110]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 79EB4735; Mon, 15 Jan 2024 11:29:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1705314560; bh=lLbgP/nqLrL1K3LSTPxWpIdsU8Pb3+TB8aNct/6Qmuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CUipmUTt4mPSuRPTZTFZyw+DezK6BntulyGnTOzCH0JZY0LGltPxjwKZN+AFd8Wdp 9GOrzRb8a+Xxs8++ka3JA/8dISMgK1ToYyXQu41GgL813MAXxsGAMEVOK93BRmQWdy hhJzBtrNKdBgeujqGvLJmW5Pzrc/zOsvjDmxLWWo= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Sakari Ailus , Jacopo Mondi , Alexander Shiyan , Fabio Estevam , Frieder Schrempf , Marek Vasut , Martin Kepplinger , Rui Miguel Silva , Tim Harvey , Purism Kernel Team Subject: [PATCH 2/7] media: mc: Fix flags handling when creating pad links Date: Mon, 15 Jan 2024 12:30:24 +0200 Message-ID: <20240115103029.28055-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115103029.28055-1-laurent.pinchart@ideasonboard.com> References: <20240115103029.28055-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 --- 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,