Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3743899pxk; Tue, 29 Sep 2020 05:19:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+FzxR/gC1Z4cqbUnMeIgZHecoFdiOwqUnECx9BUIYPEHrWlPnO9/DMtJJqlB+1Mcm++xd X-Received: by 2002:a50:cd5d:: with SMTP id d29mr3048256edj.318.1601381964785; Tue, 29 Sep 2020 05:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601381964; cv=none; d=google.com; s=arc-20160816; b=FT0Mx9WRt6bgzppWYzU8W07eYWLxbKjdfim/S2PfPQWZX7zxIenXh109MmZsZsjZCL ZMQhs3W5mxaQrv67GbAbBC++fCc8IjTcb2F8PwVdgfYsQHPe/wS22InwCWMBe9fez2DO ZdpFXWTnRQ0DaJYhE1S7S3Z1uKfuhQ8vEJ94mNwmFrEaYyXj9ckfq4puTO3sbNberWPV A19LYzEL8D+84Emn4H+jiaunmyW9vmXmLqLZRSpiERzr4RuvXZhtenJmE93O2N0GtKz6 /lDN2Rn5q3FhAJrNoxChhj7eAPdh+S7b3LwNxXBEUWFWfw532tjAdRYfWP+gnvMfGoYJ y7Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=so7Oq8UUHx8BVs3QQ7AKrJ6XJzKJIno0tBS2vU92sxk=; b=hnVH233v9D0uaoSd2ka8l9ArlGrH6E7VV5YU+uXHB16bYLCS5zu7XllaKGZToz0vK3 BH+EImBMRtCe4B3pw9GFC/BEI0UxXoUqzbtctwxTnP5gK1tL10XYZ0m7c2JBZvRvWcQp tpWFBoDljCDmMyrc+VHx2iKsmpi77nOAghXPO0fHYbyfjHNxm3Ku0Fzm6f04Lb9RB7jM JfCMgJ6f3XOromc7yy+mlxf06UINQkt7mJHaLIp2yFVL4/b62XaoGyLIHyWjM2PLzGg2 ElAAwAu/r8eOcMOc6sxudzAPZeS7s3WAmQCKD6+6qYXz4fzrN/rKK3SYXevTvnCkTwCy rTBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aZYS1KRb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o15si2476652eds.367.2020.09.29.05.19.00; Tue, 29 Sep 2020 05:19:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aZYS1KRb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732220AbgI2MRl (ORCPT + 99 others); Tue, 29 Sep 2020 08:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:53440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730004AbgI2Lgx (ORCPT ); Tue, 29 Sep 2020 07:36:53 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D9E9E23E55; Tue, 29 Sep 2020 11:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379122; bh=ZWXCHAIhOxLvBohGGN9gIS4oL85Z+wVf83WCgrQzrfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZYS1KRbQoKX62rF09/qAmC2IrMSNaT1s3heox7XISoYCP79MxpIWPT0W036vP6Ym NsBeGRrkY6olCbXFlXAZft7HTJRP644Z14e1RcUOEz/uItbwJK9ZZkAavKdYQs68oT x9fhtKezVF00YSLSGUmM/HFwfuQiM9jpE5M47GGs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , zhengbin , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.4 005/388] media: mc-device.c: fix memleak in media_device_register_entity Date: Tue, 29 Sep 2020 12:55:36 +0200 Message-Id: <20200929110010.738488281@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: zhengbin [ Upstream commit 713f871b30a66dc4daff4d17b760c9916aaaf2e1 ] In media_device_register_entity, if media_graph_walk_init fails, need to free the previously memory. Reported-by: Hulk Robot Signed-off-by: zhengbin Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- 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 e19df5165e78c..da80883511352 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; -- 2.25.1