From patchwork Tue Sep 19 12:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 724550 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFFEBCD5BA0 for ; Tue, 19 Sep 2023 12:20:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232210AbjISMUk (ORCPT ); Tue, 19 Sep 2023 08:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232233AbjISMUY (ORCPT ); Tue, 19 Sep 2023 08:20:24 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40BB310CF for ; Tue, 19 Sep 2023 05:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695125983; x=1726661983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/3L2NxF7OYmSMvxGNO3/dIM9IMpSlNIboV+nvrkDjoU=; b=DmU2LsJuRs2bRpWoSktqc/O+p9hHtjVAMyQnJXLgkUPKYxRU4iusb2Xq V4qnp1NPwqTRxuW4yerhdu5xdE5jLI5oi5YMnDOJGvcJBO5smZuY6EP7w u8NgadefnrnLRD1b/yTDIZg5djEuPbJCFqu7cnL8GHG9TbxTd0N21d08S p6ZgMDtOESGrAKLyZlZY1EREbSXttOCSr4dWVTcr3R18xTmvyuz5duIHc MYPXmvlG26k6rZRW1xufL7jfE85hJLtFVGNoSEyIUbnEIVwr1NySEFPG5 9IqrzHtoqRPKIC4KkQDOx7SP81Pf/CBnBGaUF5JXG2OqJV8aAmMSAiPC3 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="466251057" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="466251057" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 05:17:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="811701708" X-IronPort-AV: E=Sophos;i="6.02,159,1688454000"; d="scan'208";a="811701708" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 05:17:49 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 6B653120C31; Tue, 19 Sep 2023 15:17:46 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Tianshu Qiu , Bingbu Cao , Tomi Valkeinen , Jacopo Mondi , Rui Miguel Silva , Martin Kepplinger Subject: [PATCH v3 12/12] media: mc: Check pad flag validity Date: Tue, 19 Sep 2023 15:17:28 +0300 Message-Id: <20230919121728.126781-13-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230919121728.126781-1-sakari.ailus@linux.intel.com> References: <20230919121728.126781-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Check the validity of pad flags on entity init. Exactly one of the flags must be set. Signed-off-by: Sakari Ailus Reviewed-by: Laurent Pinchart --- drivers/media/mc/mc-entity.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index 83468d4a440b..0a54cf8bcca2 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -197,6 +197,7 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, struct media_device *mdev = entity->graph_obj.mdev; struct media_pad *iter; unsigned int i = 0; + int ret = 0; if (num_pads >= MEDIA_ENTITY_MAX_PADS) return -E2BIG; @@ -210,15 +211,26 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, media_entity_for_each_pad(entity, iter) { iter->entity = entity; iter->index = i++; + + if (hweight32(iter->flags & (MEDIA_PAD_FL_SINK | + MEDIA_PAD_FL_SOURCE)) != 1) { + ret = -EINVAL; + break; + } + if (mdev) media_gobj_create(mdev, MEDIA_GRAPH_PAD, &iter->graph_obj); } + if (ret && mdev) + media_entity_for_each_pad(entity, iter) + media_gobj_destroy(&iter->graph_obj); + if (mdev) mutex_unlock(&mdev->graph_mutex); - return 0; + return ret; } EXPORT_SYMBOL_GPL(media_entity_pads_init);