From patchwork Fri May 5 21:52:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 679837 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 82A79C7EE24 for ; Fri, 5 May 2023 21:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233551AbjEEVxK (ORCPT ); Fri, 5 May 2023 17:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbjEEVxH (ORCPT ); Fri, 5 May 2023 17:53:07 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9725C4C28 for ; Fri, 5 May 2023 14:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683323586; x=1714859586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fNdRQN/ML/8GxcbXUmF20S5kNZdqQ0oPBrnqJLIEGAk=; b=b2eYmtErHpNrpbPTQwz/ebIJVi89gU4Mi7LiZtrcB1Gszt8eSMjFWKAm t6cQOLcJh5ugTYAot9qoQn5IcBlpOLt5stl3yb1zPZYysPUNDeloZaonN gBb/efIAhqJz2eREg3h6vfkolsf86JjkWpkR1SDUsEEuH9ypSSVpUxziA q3xcD3mv+9LAgMyWjltAf+wDRhK3nksD1CD1OlzaLRD2Oj2rhon9sH9QS rPKlgoE1CaK4/+PhVLthe5k5p5h16BUqGXKLiqaR+UL3ynmfCia9Yrxi0 BfVWlv+Rgp2oGNDFgsNJefwVKOtPc49iqLOx8fsvIjiK2lP6zCfZQraUH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="328925842" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="328925842" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 14:53:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="700626140" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="700626140" Received: from turnipsi.fi.intel.com (HELO kekkonen.fi.intel.com) ([10.237.72.44]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 14:53:05 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id 60B25122707; Sat, 6 May 2023 00:53:02 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, tomi.valkeinen@ideasonboard.com, bingbu.cao@intel.com, hongju.wang@intel.com Subject: [RFC 4/7] media: mc: Check pad flag validity Date: Sat, 6 May 2023 00:52:54 +0300 Message-Id: <20230505215257.60704-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230505215257.60704-1-sakari.ailus@linux.intel.com> References: <20230505215257.60704-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 --- drivers/media/mc/mc-entity.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index ed99160a2487..c1bc48c4d239 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,6 +211,15 @@ 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 | + MEDIA_PAD_FL_INTERNAL_SOURCE)) + != 1) { + ret = -EINVAL; + break; + } + if (mdev) media_gobj_create(mdev, MEDIA_GRAPH_PAD, &iter->graph_obj); @@ -218,7 +228,7 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, if (mdev) mutex_unlock(&mdev->graph_mutex); - return 0; + return ret; } EXPORT_SYMBOL_GPL(media_entity_pads_init);