Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Johan Hovold <johan@kernel.org>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Won Chung <wonchung@google.com>
Subject: [PATCH] driver core: fix memory leak in physical location error path
Date: Mon,  2 Nov 2026 09:30:18 +0100	[thread overview]
Message-ID: <20261102083018.1275566-1-johan@kernel.org> (raw)

Make sure to free the physical location memory also in the unlikely
event that creating its sysfs attributes fails during probe.

Fixes: 6423d2951087 ("driver core: Add sysfs support for physical location of a device")
Closes: https://sashiko.dev/#/bug/linux-b178c32c-f23b-48fd-9463-70f321f2d91e
Cc: stable@vger.kernel.org	# 5.19
Cc: Won Chung <wonchung@google.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/base/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index cbe05197d4a0..bf97b06337a1 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3011,12 +3011,13 @@ static int device_add_attrs(struct device *dev)
 		error = device_add_group(dev,
 			&dev_attr_physical_location_group);
 		if (error)
-			goto err_remove_dev_removable;
+			goto err_free_physical_location;
 	}
 
 	return 0;
 
- err_remove_dev_removable:
+ err_free_physical_location:
+	kfree(dev->physical_location);
 	device_remove_file(dev, &dev_attr_removable);
  err_remove_dev_waiting_for_supplier:
 	device_remove_file(dev, &dev_attr_waiting_for_supplier);
-- 
2.55.0


                 reply	other threads:[~2026-11-02  8:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261102083018.1275566-1-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wonchung@google.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