Message ID | 20231002105557.28972-18-sakari.ailus@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Small fixes and cleanups (ov2740 and ccs) | expand |
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);