Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp63422lqo; Tue, 7 May 2024 12:11:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcprQpdIUNfWSog7G9R7sq7/B21aWpkZ+jvDpPDNQieb7frbXkRcXrjYPzEdn1uemtTfZhe9RCHkRFzxOZSx9yeC9uqTQ6kBkirbj5jg== X-Google-Smtp-Source: AGHT+IEXrnM9Py+hnHOqQDemwusbsKiT7dbgBFQLZmNuKG4wyW8XOM92WNILvSGT89tWVCNaem56 X-Received: by 2002:a05:6a20:d04e:b0:1ac:e07f:e3aa with SMTP id adf61e73a8af0-1afc8dea276mr762244637.48.1715109103337; Tue, 07 May 2024 12:11:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715109103; cv=pass; d=google.com; s=arc-20160816; b=BipeS7CkJiggv8uwzCZRZhzPO7/erJhwaRZCZjAJju/QlcMX+HCkOUCvYCQbngLyZf sz/PnytoC4wiTyP2WklzXMsRCTpdKWIzHmeggz2gpVwmwX+E5+T+mxBJOPmlS0TKNowk NKpXaT3UBcmTzTCIzQBXMgYvK/7KZP6EE52093D6903/2aLwsoNSZuj8ojTUUDmpviyu t5qE/Z2k8HSKzG45wYroUak5Tp7XButXm58GG7TIJqJmLIqSUWhQrrUmZ2fRM5fFS/xJ hHk88pq6QMhb6hG6PYWspy5IpulRH8XKFlSCisuIf5jUuHQ2HUWLCgyt+eq1vQDUq/dF Dduw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=BN4zSJEVd5m8C84oQNz2ZRjVfHh5Lux8A4sPL5KObTs=; fh=EJZUXzC6zsV8cuQ3Xmi1H2HAIbQZdLodPGmYrqv3G+A=; b=otM3/ndX+QUDVN+vDhZVamOqo50lJUJ4L1/OLTq6HdMhMmRh/r/FX20V+yDdKzfC+T HQecJnyD1B0AS6+nrBpAQvOLLaGgefA0bhJymO92vdbq1ZD2yQ5BK/F3Iybgs4NfiL1A wp5yITF8kNNSSXqVLbPkwmux5BiwVIlUWoNOT0TJ7/NDNBojQzmVyvOa1eBaFK0jLda5 Ou4BkPIfJNIOFu3wFZYk0ub5CxRRLC+4XgNPTMMzg8JUuMSIx9xydrA9Hp0LfF69usez XuraQfYFYzfO76cpQ46czhL8ebu8Twv6UHLZbgpLkZud1irspVmlcm1ZHDHakZsaw8mz wGqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E1PjAJAT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ey14-20020a056a0038ce00b006f47258f9c5si5467161pfb.279.2024.05.07.12.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:11:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E1PjAJAT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172019-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D82C7B2224A for ; Tue, 7 May 2024 18:57:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3196916D9C9; Tue, 7 May 2024 18:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E1PjAJAT" 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 4042C14EC5F; Tue, 7 May 2024 18:57:14 +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=1715108235; cv=none; b=Ysy/dQuC9K5niB01pPvNZf0N1dT6hlWkTPEwPAOoH8kNq8EhB5UGo2KxSgDyOHbSDtW76+ueW0K2Fb528PV+uMRj1VI9wQJqF593GhF+HuhqERllUcbqmZW0vdBy3slZddpnMV1fTe3lDHca1NBn7lB66vrkjJ7h4kfMR8q3VX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715108235; c=relaxed/simple; bh=7MldFMh0WRj0UvMnQBIzOVOdcBxV2CBitHg5VApEhc8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CrCPIbTxBPDMkC2MWp14jLmaWVdlvTHisWO3d85D3l/zHhtNyE8NoDERyqgDTs+lcGePVxHJ3QhVFfMCBYmdWKBHbPaE/ojrypePKMMiyk7bl9NRuvlQBFeglZchL4FQa0+2H/7VeuD8pFLod8qhsEiy2elVkzdpE7R0Tlv901I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1PjAJAT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE65DC4DDE2; Tue, 7 May 2024 18:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715108234; bh=7MldFMh0WRj0UvMnQBIzOVOdcBxV2CBitHg5VApEhc8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=E1PjAJATWxldderSnURjfd5HR/y8+qH1w0WIr+8S2MGugZWT4/EHbg5T+2yCdlhPJ 1YZvCtvIRMdL6LDwFx0bHiaF7Vy80YYgIue5irmvWPzuhz9ZbWwRlTuHkuMWHeo7H6 cq0oxGRSif7PjbmWyqU1CAE8zASFCak0QK1lSoZypeJHvgMprLl6/euUz/elG+LWWN dIgPK0l/fjyywfbs9ErgMueVxpD1uGy0/smS851r1KvY3VLjEZ2GJjWJa8ElcI0ceb m/ujPN0giZxnajz5d0LixljIgTEHKdTc/L9LQYWjexTXZmBtaVw23NTzjAfRwySQ4T UhzImpdv2U3SA== Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5a9ef9ba998so796483eaf.1; Tue, 07 May 2024 11:57:14 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXyaxOA2JSXIiVfV+QECowVW6sJPBrqTuyng2mjSJm2jqvDkvt86g4/9kkZhw6nGOZe13P8qvj0boxP5wTDZsG4Qp9Zqj3IL9zYNj48AJUEfHk71DdYTxvUl4Sz3fbO4NGnUkdq55KsYzfouTceGrhb/0VC7BFWqQza4KLzvRG5RlD8zFBXNdfygUxndyaDzucBIypGtdpbX7w84Q5S3w== X-Gm-Message-State: AOJu0YzcAW7TCOrKQJ77css2eLd4une7YVQVuE5CpBKyxK1eT3LwmjW2 PznBWgUFMKebYc9xTnN3BMGInj70hxJgSDDeYCmUVdgjV0uCCcbTCH6A1UEgd9a0h7EK6ZlnBqq Ghq4fReCTe1uSPvNi0VR6vCbUo04= X-Received: by 2002:a05:6820:1f92:b0:5ac:6fc1:c2cb with SMTP id 006d021491bc7-5b24caad211mr401694eaf.0.1715108234007; Tue, 07 May 2024 11:57:14 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> <20240430142434.10471-6-Jonathan.Cameron@huawei.com> In-Reply-To: <20240430142434.10471-6-Jonathan.Cameron@huawei.com> From: "Rafael J. Wysocki" Date: Tue, 7 May 2024 20:57:02 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 05/19] ACPI: processor: Fix memory leaks in error paths of processor_add() To: Jonathan Cameron Cc: Thomas Gleixner , Peter Zijlstra , linux-pm@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, x86@kernel.org, Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo , Gavin Shan , Ingo Molnar , Borislav Petkov , Dave Hansen , linuxarm@huawei.com, justin.he@arm.com, jianyong.wu@arm.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 30, 2024 at 4:27=E2=80=AFPM Jonathan Cameron wrote: > > If acpi_processor_get_info() returned an error, pr and the associated > pr->throttling.shared_cpu_map were leaked. > > The unwind code was in the wrong order wrt to setup, relying on > some unwind actions having no affect (clearing variables that were > never set etc). That makes it harder to reason about so reorder > and add appropriate labels to only undo what was actually set up > in the first place. > > Signed-off-by: Jonathan Cameron Acked-by: Rafael J. Wysocki Thank you! > > --- > v9: New patch in response to Gavin noticing a memory leak later in the > series. > --- > drivers/acpi/acpi_processor.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) > > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.= c > index 5f062806ca40..16e36e55a560 100644 > --- a/drivers/acpi/acpi_processor.c > +++ b/drivers/acpi/acpi_processor.c > @@ -393,7 +393,7 @@ static int acpi_processor_add(struct acpi_device *dev= ice, > > result =3D acpi_processor_get_info(device); > if (result) /* Processor is not physically present or unavailable= */ > - return result; > + goto err_clear_driver_data; > > BUG_ON(pr->id >=3D nr_cpu_ids); > > @@ -408,7 +408,7 @@ static int acpi_processor_add(struct acpi_device *dev= ice, > "BIOS reported wrong ACPI id %d for the processor= \n", > pr->id); > /* Give up, but do not abort the namespace scan. */ > - goto err; > + goto err_clear_driver_data; > } > /* > * processor_device_array is not cleared on errors to allow buggy= BIOS > @@ -420,12 +420,12 @@ static int acpi_processor_add(struct acpi_device *d= evice, > dev =3D get_cpu_device(pr->id); > if (!dev) { > result =3D -ENODEV; > - goto err; > + goto err_clear_per_cpu; > } > > result =3D acpi_bind_one(dev, device); > if (result) > - goto err; > + goto err_clear_per_cpu; > > pr->dev =3D dev; > > @@ -436,10 +436,11 @@ static int acpi_processor_add(struct acpi_device *d= evice, > dev_err(dev, "Processor driver could not be attached\n"); > acpi_unbind_one(dev); > > - err: > - free_cpumask_var(pr->throttling.shared_cpu_map); > - device->driver_data =3D NULL; > + err_clear_per_cpu: > per_cpu(processors, pr->id) =3D NULL; > + err_clear_driver_data: > + device->driver_data =3D NULL; > + free_cpumask_var(pr->throttling.shared_cpu_map); > err_free_pr: > kfree(pr); > return result; > -- > 2.39.2 >