From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: zhengbin <zhengbin13@huawei.com>
Cc: sakari.ailus@linux.intel.com, mchehab@kernel.org,
linux-media@vger.kernel.org, yi.zhang@huawei.com
Subject: Re: [PATCH v2] media: mc-device.c: fix memleak in media_device_register_entity
Date: Fri, 6 Sep 2019 12:12:03 +0300 [thread overview]
Message-ID: <20190906091203.GB5019@pendragon.ideasonboard.com> (raw)
In-Reply-To: <1566179490-15413-1-git-send-email-zhengbin13@huawei.com>
Hello Zhengbin,
On Mon, Aug 19, 2019 at 09:51:30AM +0800, zhengbin wrote:
> In media_device_register_entity, if media_graph_walk_init fails,
> need to free the previously memory.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: zhengbin <zhengbin13@huawei.com>
This looks good to me.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
and applied to my tree, for v5.5.
> ---
> drivers/media/mc/mc-device.c | 65 ++++++++++++++++++++++----------------------
> 1 file changed, 33 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c
> index e19df51..da80883 100644
> --- a/drivers/media/mc/mc-device.c
> +++ b/drivers/media/mc/mc-device.c
> @@ -575,6 +575,38 @@ static void media_device_release(struct media_devnode *devnode)
> dev_dbg(devnode->parent, "Media device released\n");
> }
>
> +static void __media_device_unregister_entity(struct media_entity *entity)
> +{
> + struct media_device *mdev = entity->graph_obj.mdev;
> + struct media_link *link, *tmp;
> + struct media_interface *intf;
> + unsigned int i;
> +
> + ida_free(&mdev->entity_internal_idx, entity->internal_idx);
> +
> + /* Remove all interface links pointing to this entity */
> + list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
> + list_for_each_entry_safe(link, tmp, &intf->links, list) {
> + if (link->entity == entity)
> + __media_remove_intf_link(link);
> + }
> + }
> +
> + /* Remove all data links that belong to this entity */
> + __media_entity_remove_links(entity);
> +
> + /* Remove all pads that belong to this entity */
> + for (i = 0; i < entity->num_pads; i++)
> + media_gobj_destroy(&entity->pads[i].graph_obj);
> +
> + /* Remove the entity */
> + media_gobj_destroy(&entity->graph_obj);
> +
> + /* invoke entity_notify callbacks to handle entity removal?? */
> +
> + entity->graph_obj.mdev = NULL;
> +}
> +
> /**
> * media_device_register_entity - Register an entity with a media device
> * @mdev: The media device
> @@ -632,6 +664,7 @@ int __must_check media_device_register_entity(struct media_device *mdev,
> */
> ret = media_graph_walk_init(&new, mdev);
> if (ret) {
> + __media_device_unregister_entity(entity);
> mutex_unlock(&mdev->graph_mutex);
> return ret;
> }
> @@ -644,38 +677,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
> }
> EXPORT_SYMBOL_GPL(media_device_register_entity);
>
> -static void __media_device_unregister_entity(struct media_entity *entity)
> -{
> - struct media_device *mdev = entity->graph_obj.mdev;
> - struct media_link *link, *tmp;
> - struct media_interface *intf;
> - unsigned int i;
> -
> - ida_free(&mdev->entity_internal_idx, entity->internal_idx);
> -
> - /* Remove all interface links pointing to this entity */
> - list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
> - list_for_each_entry_safe(link, tmp, &intf->links, list) {
> - if (link->entity == entity)
> - __media_remove_intf_link(link);
> - }
> - }
> -
> - /* Remove all data links that belong to this entity */
> - __media_entity_remove_links(entity);
> -
> - /* Remove all pads that belong to this entity */
> - for (i = 0; i < entity->num_pads; i++)
> - media_gobj_destroy(&entity->pads[i].graph_obj);
> -
> - /* Remove the entity */
> - media_gobj_destroy(&entity->graph_obj);
> -
> - /* invoke entity_notify callbacks to handle entity removal?? */
> -
> - entity->graph_obj.mdev = NULL;
> -}
> -
> void media_device_unregister_entity(struct media_entity *entity)
> {
> struct media_device *mdev = entity->graph_obj.mdev;
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2019-09-06 9:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 1:51 [PATCH v2] media: mc-device.c: fix memleak in media_device_register_entity zhengbin
2019-09-04 8:46 ` zhengbin (A)
2019-09-06 9:12 ` Laurent Pinchart [this message]
2019-09-06 10:11 ` Sakari Ailus
2019-09-06 10:36 ` Laurent Pinchart
2019-09-06 10:59 ` Sakari Ailus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190906091203.GB5019@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=yi.zhang@huawei.com \
--cc=zhengbin13@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox