public inbox for linux-acpi@vger.kernel.org
 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 v2 2/2] platform/x86: toshiba_haps: Fix memory leaks in add/remove routines
Date: Wed, 21 Jan 2026 11:57:26 +0100	[thread overview]
Message-ID: <12823935.O9o76ZdvQC@rafael.j.wysocki> (raw)
In-Reply-To: <10789244.nUPlyArG6x@rafael.j.wysocki>

On Tuesday, January 20, 2026 4:44:23 PM CET Rafael J. Wysocki wrote:
> 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.

Actually, this one can use devm_kzalloc() for allocating memory instead,
so here's a v2.

---
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Subject: [PATCH v2 2/2] platform/x86: toshiba_haps: Fix memory leaks in add/remove routines

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 using devm_kzalloc() for allocating
the memory in question.

Fixes: 23d0ba0c908a ("platform/x86: Toshiba HDD Active Protection Sensor")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

v1 -> v2:
   * Use devm_kzalloc() for memory allocation and drop the rest of the changes.

---
 drivers/platform/x86/toshiba_haps.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/platform/x86/toshiba_haps.c
+++ b/drivers/platform/x86/toshiba_haps.c
@@ -183,7 +183,7 @@ static int toshiba_haps_add(struct acpi_
 
 	pr_info("Toshiba HDD Active Protection Sensor device\n");
 
-	haps = kzalloc(sizeof(struct toshiba_haps_dev), GFP_KERNEL);
+	haps = devm_kzalloc(&acpi_dev->dev, sizeof(*haps), GFP_KERNEL);
 	if (!haps)
 		return -ENOMEM;
 




  reply	other threads:[~2026-01-21 10:57 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 ` [PATCH v1 2/2] platform/x86: toshiba_haps: Fix memory leaks in add/remove routines Rafael J. Wysocki
2026-01-21 10:57   ` Rafael J. Wysocki [this message]
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=12823935.O9o76ZdvQC@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