From patchwork Mon Aug 24 20:01:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 9375 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D214ABE173 for ; Mon, 24 Aug 2020 20:02:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5FF576170D; Mon, 24 Aug 2020 22:02:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="tnH5K1f3"; dkim-atps=neutral Received: from mail4.protonmail.ch (mail4.protonmail.ch [185.70.40.27]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 703F5616B1 for ; Mon, 24 Aug 2020 22:02:02 +0200 (CEST) Date: Mon, 24 Aug 2020 20:01:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1598299321; bh=0h6Se78leWrMQeT6/dsgCSkpT/CITFXSoSXHcJ2jCdo=; h=Date:To:From:Reply-To:Subject:From; b=tnH5K1f3t60cWS+HeGRdrb80ItJ23WuXK7INOdYHwebg1HTKIb6jPjEn3M+8Ql3wX lw/6L27VwXkTvdCsZRB93M01w4SXG8RcP/6AvEtV0CD9Ifsq3iQlw2DveLbkB26OEj k16LEqCa3z1ekYglohUhUK+uoaMhT3b1V0GAkQhs= To: "libcamera-devel@lists.libcamera.org" From: Dan Scally Message-ID: <2fi0-eM0Z4VDp7ia9hJVx96VwN0n3oGU3Jv05Af9xKBJ5mGjXNJ5KV7SRbExyTImQblR8jBiGAtJnPhtuMVzDqrLBkYd_KQ2q77ScInUiSM=@protonmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Subject: [libcamera-devel] [PATCH] src/libcamera/media_device.cpp: Make MediaDevice::setupLink account for existing link flags X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Dan Scally Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The setupLink function fails (ioctl returns EINVAL) when it passes the MEDIA_LNK_FL_ENABLE flag to a link that is already flagged with MEDIA_LNK_FL_ENABLE and MEDIA_LNK_FL_IMMUTABLE. Contrast to media-ctl's equivalent media_setup_link() which ORs the new flags with the existing values. This patch modifies the behaviour of setupLink() to behave the same as media_setup_link() in media-ctl. ref https://git.linuxtv.org/v4l-utils.git/tree/utils/media-ctl/libmediactl.c#n210 Signed-off-by: Daniel Scally --- src/libcamera/media_device.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) linkDesc.source.index = source->index(); @@ -794,7 +803,7 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags) linkDesc.sink.index = sink->index(); linkDesc.sink.flags = MEDIA_PAD_FL_SINK; - linkDesc.flags = flags; + linkDesc.flags = flags | (elink->flags() & MEDIA_LNK_FL_IMMUTABLE); int ret = ioctl(fd_, MEDIA_IOC_SETUP_LINK, &linkDesc); if (ret) { diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index de18d57..cd44902 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -780,11 +780,20 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity) * * \return 0 on success or a negative error code otherwise */ -int MediaDevice::setupLink(const MediaLink *link, unsigned int flags) +int MediaDevice::setupLink(const MediaLink *nlink, unsigned int flags) { struct media_link_desc linkDesc = {}; - MediaPad *source = link->source(); - MediaPad *sink = link->sink(); + MediaPad *source = nlink->source(); + MediaPad *sink = nlink->sink(); + MediaLink *elink; // existing link + + elink = link(source, sink); + + if (elink == NULL) { + LOG(MediaDevice, Error) + << __func__ << ": Link not found\n"; + return -ENOENT; + } linkDesc.source.entity = source->entity()->id();