mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: "Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Kenneth Chan <kenneth.t.chan@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	Azael Avalos <coproscefalo@gmail.com>,
	Matthew Garrett <matthew.garrett@nebula.com>
Subject: [PATCH v1 2/2] platform/x86: toshiba_haps: Fix memory leaks in add/remove routines
Date: Tue, 20 Jan 2026 16:44:23 +0100	[thread overview]
Message-ID: <10789244.nUPlyArG6x@rafael.j.wysocki> (raw)
In-Reply-To: <3026924.e9J7NaK4W3@rafael.j.wysocki>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

toshiba_haps_add() leaks the haps object allocated by it if it returns
an error after allocating that object successfully.

toshiba_haps_remove() does not free the object pointed to by
toshiba_haps before clearing that pointer, so it becomes unreachable
allocated memory.

Address these memory leaks by freeing the memory in question as
appropriate.

Fixes: 23d0ba0c908a ("platform/x86: Toshiba HDD Active Protection Sensor")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/platform/x86/toshiba_haps.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

--- a/drivers/platform/x86/toshiba_haps.c
+++ b/drivers/platform/x86/toshiba_haps.c
@@ -142,8 +142,8 @@ static void toshiba_haps_remove(struct a
 {
 	sysfs_remove_group(&device->dev.kobj, &haps_attr_group);
 
-	if (toshiba_haps)
-		toshiba_haps = NULL;
+	kfree(toshiba_haps);
+	toshiba_haps = NULL;
 }
 
 /* Helper function */
@@ -195,15 +195,20 @@ static int toshiba_haps_add(struct acpi_
 	/* Set the protection level, currently at level 2 (Medium) */
 	ret = toshiba_haps_protection_level(acpi_dev->handle, 2);
 	if (ret != 0)
-		return ret;
+		goto err;
 
 	ret = sysfs_create_group(&acpi_dev->dev.kobj, &haps_attr_group);
 	if (ret)
-		return ret;
+		goto err;
 
 	toshiba_haps = haps;
 
 	return 0;
+
+err:
+	kfree(haps);
+
+	return ret;
 }
 
 #ifdef CONFIG_PM_SLEEP




  parent reply	other threads:[~2026-01-20 15:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 15:42 [PATCH v1 0/2] platform/x86: Fixes for leaks in panasonic-laptop and toshiba-haps drivers Rafael J. Wysocki
2026-01-20 15:43 ` [PATCH v1 1/2] platform/x86: panasonic-laptop: Fix sysfs group leak in error path Rafael J. Wysocki
2026-01-20 15:44 ` Rafael J. Wysocki [this message]
2026-01-21 10:57   ` [PATCH v2 2/2] platform/x86: toshiba_haps: Fix memory leaks in add/remove routines Rafael J. Wysocki
2026-01-26 14:56 ` [PATCH v1 0/2] platform/x86: Fixes for leaks in panasonic-laptop and toshiba-haps drivers Ilpo Järvinen
2026-01-26 19:00   ` Rafael J. Wysocki
2026-01-27 11:04     ` Ilpo Järvinen
2026-01-27 13:36       ` Rafael J. Wysocki

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=10789244.nUPlyArG6x@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=coproscefalo@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kenneth.t.chan@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.garrett@nebula.com \
    --cc=platform-driver-x86@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

all inboxes | Powered by JetHome®