Message ID | 20231002105557.28972-18-sakari.ailus@linux.intel.com (mailing list archive) |
---|---|
State | Accepted |
Headers |
Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from <linux-media-owner@vger.kernel.org>) id 1qnGbN-003XUS-9E; Mon, 02 Oct 2023 10:56:37 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236592AbjJBK4h (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Mon, 2 Oct 2023 06:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236604AbjJBK41 (ORCPT <rfc822;linux-media@vger.kernel.org>); Mon, 2 Oct 2023 06:56:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9359DD7 for <linux-media@vger.kernel.org>; Mon, 2 Oct 2023 03:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696244185; x=1727780185; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p71jLwyaJ+cRA4wPi0IX6Mx4yaKEMlNV4iXy/0ENXCg=; b=TgLQdw5kRVJKXNzDYXfarVUvcSHO5Vto8/jwBGoXoFQn+nxNBwj/B25l p1L1OuHjS5kUuYuCOo/DFRrJFOweOScvqGbfmfvPJcJGGg1rGEZle2YAI TwkMiACDE8VYlmxENUOo8kLIkCvW5TNkn6ZKKKlIGYi/cdGpKHdNkkQ/Q 1NAuTfeQ9LdbIQi6RL9uKAXW4vjnkA9/cq5jK8obS2WwmHw2dOmXutBUI kFBUy6o1WTRUjMuz+I1PQq0LpwL2srSTCzim6KEa8LmZOVgjiHxH6aJ/7 xLOKpybtwUIDyQykx9Q1+dHni4MvXBCXAQc7q8e4sc0FgCt8dtXEz+VmF w==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="379896422" X-IronPort-AV: E=Sophos;i="6.03,194,1694761200"; d="scan'208";a="379896422" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 03:56:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="816251222" X-IronPort-AV: E=Sophos;i="6.03,194,1694761200"; d="scan'208";a="816251222" 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; 02 Oct 2023 03:56:22 -0700 Received: from svinhufvud.ger.corp.intel.com (localhost [IPv6:::1]) by kekkonen.fi.intel.com (Postfix) with ESMTP id D692E11F967; Mon, 2 Oct 2023 13:56:19 +0300 (EEST) From: Sakari Ailus <sakari.ailus@linux.intel.com> To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Tianshu Qiu <tian.shu.qiu@intel.com>, Bingbu Cao <bingbu.cao@intel.com>, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>, Jacopo Mondi <jacopo+renesas@jmondi.org>, Rui Miguel Silva <rmfrfs@gmail.com>, Martin Kepplinger <martink@posteo.de> Subject: [PATCH v7 17/19] media: mc: Check pad flag validity Date: Mon, 2 Oct 2023 13:55:55 +0300 Message-Id: <20231002105557.28972-18-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002105557.28972-1-sakari.ailus@linux.intel.com> References: <20231002105557.28972-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.4 (--) X-LSpam-Report: No, score=-2.4 required=5.0 tests=BAYES_00=-1.9,DKIMWL_WL_HIGH=0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no |
Series |
Small fixes and cleanups (ov2740 and ccs)
|
|
Commit Message
Sakari Ailus
Oct. 2, 2023, 10:55 a.m. UTC
Check the validity of pad flags on entity init. Exactly one of the flags must be set. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- drivers/media/mc/mc-entity.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
Comments
On (23/10/02 13:55), Sakari Ailus wrote: > > Check the validity of pad flags on entity init. Exactly one of the flags > must be set. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > drivers/media/mc/mc-entity.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c > index 83468d4a440b..543a392f8635 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,27 @@ 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; Can we please have some sort of WARN_ON() or pr_err() here? This is a pretty big change.
Hi Sergey, Thanks for the review. On Thu, Feb 01, 2024 at 06:17:13PM +0900, Sergey Senozhatsky wrote: > On (23/10/02 13:55), Sakari Ailus wrote: > > > > Check the validity of pad flags on entity init. Exactly one of the flags > > must be set. > > > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > drivers/media/mc/mc-entity.c | 15 ++++++++++++++- > > 1 file changed, 14 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c > > index 83468d4a440b..543a392f8635 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,27 @@ 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; > > Can we please have some sort of WARN_ON() or pr_err() here? > This is a pretty big change. Doing proper input validation is hardly anything unusual, is it? I'm fine with a WARN_ON() though, I'll add that to v8.
On (24/02/01 09:22), Sakari Ailus wrote: > Hi Sergey, > > Thanks for the review. Hi Sakari, > On Thu, Feb 01, 2024 at 06:17:13PM +0900, Sergey Senozhatsky wrote: > > On (23/10/02 13:55), Sakari Ailus wrote: [..] > > > @@ -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,27 @@ 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; > > > > Can we please have some sort of WARN_ON() or pr_err() here? > > This is a pretty big change. > > Doing proper input validation is hardly anything unusual, is it? Well, function requirements change quite significantly, to the point that drivers that worked before won't work after. > I'm fine with a WARN_ON() though, I'll add that to v8. Thanks!
On Thu, Feb 01, 2024 at 06:33:13PM +0900, Sergey Senozhatsky wrote: > On (24/02/01 09:22), Sakari Ailus wrote: > > Hi Sergey, > > > > Thanks for the review. > > Hi Sakari, > > > On Thu, Feb 01, 2024 at 06:17:13PM +0900, Sergey Senozhatsky wrote: > > > On (23/10/02 13:55), Sakari Ailus wrote: > [..] > > > > @@ -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,27 @@ 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; > > > > > > Can we please have some sort of WARN_ON() or pr_err() here? > > > This is a pretty big change. > > > > Doing proper input validation is hardly anything unusual, is it? > > Well, function requirements change quite significantly, to the point > that drivers that worked before won't work after. > > > I'm fine with a WARN_ON() though, I'll add that to v8. > > Thanks! Actually this was a patchset that was merged quite some time ago. I'll post separate patch on this.
On (24/02/01 11:05), Sakari Ailus wrote: [..] > > > > > if (num_pads >= MEDIA_ENTITY_MAX_PADS) > > > > > return -E2BIG; > > > > > @@ -210,15 +211,27 @@ 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; > > > > > > > > Can we please have some sort of WARN_ON() or pr_err() here? > > > > This is a pretty big change. > > > > > > Doing proper input validation is hardly anything unusual, is it? > > > > Well, function requirements change quite significantly, to the point > > that drivers that worked before won't work after. > > > > > I'm fine with a WARN_ON() though, I'll add that to v8. > > > > Thanks! > > Actually this was a patchset that was merged quite some time ago. I'll > post separate patch on this. Ack. I just debugged a driver that miraculously stopped working, and it turned out to be because of this media_entity_pads_init() change. I think I would have benefited from WARN_ON() or pr_err() there.
diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index 83468d4a440b..543a392f8635 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,27 @@ 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);