Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2077173lqa; Tue, 30 Apr 2024 07:38:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbeth9Rc8+decFvr2jnbAyZm8GCGMhV1XLr+Q/LEWmuf1pRJCMyWrejaabWMeadgsF+slWgyFOn1rUnjlp4beecHgw76d3GB9sQ9Y23Q== X-Google-Smtp-Source: AGHT+IHzZs12F6dXNA2p7wovKeRD12CSPz/0VUVXqreq4E3D1UZmXxQFDY0mTpCieo0+/lQxl2kn X-Received: by 2002:a17:903:32c7:b0:1eb:828:9a71 with SMTP id i7-20020a17090332c700b001eb08289a71mr4206899plr.31.1714487889074; Tue, 30 Apr 2024 07:38:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714487889; cv=pass; d=google.com; s=arc-20160816; b=SizkvOcBYpUdLJvLyPMKkgmuOC95VtJvux0VF4PfYh1+8A+tmEdxh4HqLXfKvX17Zo TOvN+BI5p92wMEyfoD22jNMsaziIOU9bPLlMjlzd8eEGG3k6Q9a2M9ez+9vOPxYDjtwe W+Vo0SeN6q0EY+Q6+uj7lKPjhd/ziv2sBzOvaFoqyBliJNVaMhzIozyBH7F8keBx1G3w 4/+gIeYl3KJSZgID7IIxQk5ze0obtxOoDqQGpEu4sixNvf6o9eGUDOoDPp2B/jbFZwh2 /H9d7B7np2ZjuLRZbT7aAanp/39Yj3PCZtfVxMTsV1dcoWU+UdED+oWIixEwwIS4opfQ 5ytA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=EMumuU/iIYEhzS6qPV6hXtaYJtfmeA5Fr+kWZ6tTldI=; fh=25IklNjpQtm3+ZI4w1ifckV22BkO2b6a/wyTwiBBJrk=; b=X+rrlGaCtv5KbGvdTUIqf4zXbz6Qg0Ii/lXFXtcGd8buZlVfEOeBcxMjFYAQDV1yix 42O64bRfPUmr637OceA89Bqg73+UI1jniNyU3hg//Bwd/DTMWJ0pyKSaujjOsbkYXZCu SnP24cZGJHbTSi5FyWQn4vH8myB8EjYK+GLj9f87bHlB+embWyW+jSG5k/dIrgYm3Ey0 qGzdkSJCGx4XRMZbf4W2c9nqm+eX5s/QldAknNaoEcuK5A63h8TWu+l41EKcvLv+4QYX P+itoFnb1YGQ7B8YO5U/gM9ZzaxWvXx5sMHudkfnoKoJTAObU+1Gz1CHo52QsNC2rXMw bciA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-164139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m8-20020a170902bb8800b001e2037d4657si21723883pls.174.2024.04.30.07.38.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-164139-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164139-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7EA54286DAB for ; Tue, 30 Apr 2024 14:32:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41BED17F37D; Tue, 30 Apr 2024 14:27:15 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 37F2517F362; Tue, 30 Apr 2024 14:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714487234; cv=none; b=GgK0xxQ1+TVqIsBe4hHdm3ZPWgOoHHKlP2PzRGP4GIrCtuLYzEn/b9HPEaKgDAUq1pRPYqog0vpUKaBkYU7sBsmb3QjOiifGVjdceVK7aWEnQcYWHMeKPfps+B8HYtcoUpzmhNXy3eYsz7lbS22h6U3R/DWXavPwFyp0kGjzLC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714487234; c=relaxed/simple; bh=aSVBOVzj40ilhIKPrA1EC8by5agTYqWDY8zUkE1YKzU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W5WsT24qVTgZPWMOYh4w0J48IBU0x6ueGEzvMNY+bcyYmhqxC9YQoDKTnBGu1GqlwUcbGIWvzR9ZOQwX2HJxirb+/TZfHLHBvp4tbiozW7szPpod/XV5fSA8Dx2kSJhfEwavm1776WBs2F58ai3I9IPDy4IzZq4V+eQT3XerKhU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VTMsD5tq2z67hPh; Tue, 30 Apr 2024 22:24:32 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 16B09140B3C; Tue, 30 Apr 2024 22:27:10 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 30 Apr 2024 15:27:09 +0100 From: Jonathan Cameron To: Thomas Gleixner , Peter Zijlstra , , , , , , , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo , Gavin Shan CC: Ingo Molnar , Borislav Petkov , Dave Hansen , , , Subject: [PATCH v9 05/19] ACPI: processor: Fix memory leaks in error paths of processor_add() Date: Tue, 30 Apr 2024 15:24:20 +0100 Message-ID: <20240430142434.10471-6-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> References: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500005.china.huawei.com (7.191.163.240) 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 --- 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 *device, result = 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 >= nr_cpu_ids); @@ -408,7 +408,7 @@ static int acpi_processor_add(struct acpi_device *device, "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 *device, dev = get_cpu_device(pr->id); if (!dev) { result = -ENODEV; - goto err; + goto err_clear_per_cpu; } result = acpi_bind_one(dev, device); if (result) - goto err; + goto err_clear_per_cpu; pr->dev = dev; @@ -436,10 +436,11 @@ static int acpi_processor_add(struct acpi_device *device, 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 = NULL; + err_clear_per_cpu: per_cpu(processors, pr->id) = NULL; + err_clear_driver_data: + device->driver_data = NULL; + free_cpumask_var(pr->throttling.shared_cpu_map); err_free_pr: kfree(pr); return result; -- 2.39.2