From nobody Sun Feb 8 02:26:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8BF3227E95; Wed, 21 Jan 2026 10:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768993051; cv=none; b=HomLhrlY+e5nInzqCoqg3E6UxfVDtFeT0vB7r1pTfObnxsb/pdGPiA9Utt2D/SVuacwY+90rtnbGpNenAiEoJ6zJCpPzXAyVqrzEsbnoa4pD9E7hVJUhX6PWHh6MvvgyLFK4+fNJd4NDZbmqsKy8czHYjv1wZT2pwlXioJEh1u4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768993051; c=relaxed/simple; bh=5P/Dz4zGB39RUC3qzDnTz05zg88xu8PNygS91jV43AY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DMNUE8leZ8VjDjZFnVy3zd8DA7aYAsbNUeOw+RoTPWeLLv1zLkFnzCPlEoKyEss+r5ncy5P3faoJ7mbKSVDaW5jKmYGKc0ezAxUhusvsIeowKKRG5UNi+tupKX9syYhwycU3e6hp7WdevMAVT4FKWhOxWiOWXz70UVS/3+W23JQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GwPwvmUV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GwPwvmUV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52842C116D0; Wed, 21 Jan 2026 10:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768993051; bh=5P/Dz4zGB39RUC3qzDnTz05zg88xu8PNygS91jV43AY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GwPwvmUVwTal0S1t2Ge7QqazBzWENjTkkQ8Tbi7li5RS8Bjd8cn4rjduf1mR6ChNh 1uRu7uYmYWDYw325mPfR8oGRoIb6qL64uBsJW8YA3A8WX60rbNZsWO9QVzwW/IkIJc Qsu5TUnAd1DVXAWT5LloeB44yBV8wfqnMxr6fn9kP3CpiC2BPSF1auWijHMLRChVq/ XWfe7xA4EiTKVnYiDRwMntMKEiKh4HdAvmeWPhPZ0LIXsdG0HTjw2QpqDPB9DB81Br VlHIzT99oheIsOWrsO/XycUCdLQS5IebBnj4ajkc+wEdz6gRNEzGdgV0kwgR309+a6 Rvvct60Bx0NjA== From: "Rafael J. Wysocki" To: Hans de Goede , Ilpo =?ISO-8859-1?Q?J=E4rvinen?= Cc: LKML , Linux ACPI , Kenneth Chan , platform-driver-x86@vger.kernel.org, Azael Avalos , Matthew Garrett 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 Message-ID: <12823935.O9o76ZdvQC@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <10789244.nUPlyArG6x@rafael.j.wysocki> References: <3026924.e9J7NaK4W3@rafael.j.wysocki> <10789244.nUPlyArG6x@rafael.j.wysocki> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On Tuesday, January 20, 2026 4:44:23 PM CET Rafael J. Wysocki wrote: > From: Rafael J. Wysocki >=20 > toshiba_haps_add() leaks the haps object allocated by it if it returns > an error after allocating that object successfully. >=20 > toshiba_haps_remove() does not free the object pointed to by > toshiba_haps before clearing that pointer, so it becomes unreachable > allocated memory. >=20 > 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 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 --- v1 -> v2: * Use devm_kzalloc() for memory allocation and drop the rest of the chan= ges. --- 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_ =20 pr_info("Toshiba HDD Active Protection Sensor device\n"); =20 - haps =3D kzalloc(sizeof(struct toshiba_haps_dev), GFP_KERNEL); + haps =3D devm_kzalloc(&acpi_dev->dev, sizeof(*haps), GFP_KERNEL); if (!haps) return -ENOMEM;