linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saravana Kannan <saravanak@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Saravana Kannan <saravanak@google.com>
Cc: stable@vger.kernel.org, kernel-team@android.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1] driver core: Fix memory leak when adding SYNC_STATE_ONLY device links
Date: Sat, 16 May 2020 01:07:18 -0700	[thread overview]
Message-ID: <20200516080718.166676-1-saravanak@google.com> (raw)

When SYNC_STATE_ONLY support was added in commit 05ef983e0d65 ("driver
core: Add device link support for SYNC_STATE_ONLY flag"),
device_link_add() incorrectly skipped adding the new SYNC_STATE_ONLY
device link to the supplier's and consumer's "device link" list. So the
"device link" is lost forever from driver core if the caller didn't keep
track of it (typically isn't expected to).

If the same SYNC_STATE_ONLY device link is created again using
device_link_add(), instead of returning the pointer to the previously
created device link, a new device link is created and returned. This can
cause memory leaks in conjunction with fw_devlinks.

Cc: stable@vger.kernel.org
Fixes: 05ef983e0d65 ("driver core: Add device link support for SYNC_STATE_ONLY flag")
Signed-off-by: Saravana Kannan <saravanak@google.com>
---
 drivers/base/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 84c569726d75..d36e9289b2df 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -436,12 +436,16 @@ struct device_link *device_link_add(struct device *consumer,
 	    flags & DL_FLAG_PM_RUNTIME)
 		pm_runtime_resume(supplier);
 
+	list_add_tail_rcu(&link->s_node, &supplier->links.consumers);
+	list_add_tail_rcu(&link->c_node, &consumer->links.suppliers);
+
 	if (flags & DL_FLAG_SYNC_STATE_ONLY) {
 		dev_dbg(consumer,
 			"Linked as a sync state only consumer to %s\n",
 			dev_name(supplier));
 		goto out;
 	}
+
 reorder:
 	/*
 	 * Move the consumer and all of the devices depending on it to the end
@@ -452,12 +456,9 @@ struct device_link *device_link_add(struct device *consumer,
 	 */
 	device_reorder_to_tail(consumer, NULL);
 
-	list_add_tail_rcu(&link->s_node, &supplier->links.consumers);
-	list_add_tail_rcu(&link->c_node, &consumer->links.suppliers);
-
 	dev_dbg(consumer, "Linked as a consumer to %s\n", dev_name(supplier));
 
- out:
+out:
 	device_pm_unlock();
 	device_links_write_unlock();
 
-- 
2.26.2.761.g0e0b3e54be-goog


             reply	other threads:[~2020-05-16  8:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-16  8:07 Saravana Kannan [this message]
2020-05-18  7:48 ` [PATCH v1] driver core: Fix memory leak when adding SYNC_STATE_ONLY device links Saravana Kannan
2020-05-18  8:03   ` Greg Kroah-Hartman
2020-05-18 19:47     ` Saravana Kannan
2020-05-19  3:00     ` [PATCH v2] driver core: Fix SYNC_STATE_ONLY device link implementation Saravana Kannan
2020-05-19  5:48       ` Greg Kroah-Hartman
2020-05-19  6:30     ` [PATCH v3] " Saravana Kannan
2020-05-19 10:47       ` Rafael J. Wysocki
2020-05-22 18:41       ` Michael Walle
2020-05-22 22:21         ` Saravana Kannan
2020-05-22 22:47           ` Michael Walle
2020-05-25 11:31             ` Michael Walle
2020-05-25 18:39               ` Saravana Kannan
2020-05-25 19:04                 ` Michael Walle
2020-05-25 21:24                   ` Saravana Kannan
2020-05-25 21:38                     ` Michael Walle
2020-05-26  7:05                       ` [PATCH v1] driver core: Update device link status correctly for SYNC_STATE_ONLY links Saravana Kannan
2020-05-26  7:07                         ` Saravana Kannan
2020-05-26 11:04                           ` Michael Walle
2020-05-26 18:08                             ` Saravana Kannan
2020-05-26  8:28                         ` Rafael J. Wysocki
2020-05-26 19:43                       ` [PATCH v2] " Saravana Kannan
2020-05-26 21:13                         ` Michael Walle
2020-05-26 21:45                           ` Saravana Kannan
2020-05-26 21:53                             ` Michael Walle
2020-05-26 22:00                               ` Saravana Kannan
2020-05-26 22:09                       ` [PATCH v3] " Saravana Kannan
2020-05-27  8:26                         ` Rafael J. Wysocki
2020-05-28 16:09                           ` Saravana Kannan

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=20200516080718.166676-1-saravanak@google.com \
    --to=saravanak@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).