Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp639067lqb; Wed, 29 May 2024 06:37:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYUY0YRyBZ2ddMhobTCiI2zSfMWtMiunpkKgXVC626eQe4s/v2/bZ1NQ01hoT7YLIwrBCPII1V0fQZmyWv+khgjZPNmSwUN49SR1pOkw== X-Google-Smtp-Source: AGHT+IGfq3nwVDnXx6fYueoNrgWu0z5YI1qIur3F/1BMat3/v2zAjfDHBZOITN2pLgQC2526Ltj6 X-Received: by 2002:a17:902:f681:b0:1f4:6057:99fd with SMTP id d9443c01a7336-1f46057a33fmr172875615ad.42.1716989874988; Wed, 29 May 2024 06:37:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716989874; cv=pass; d=google.com; s=arc-20160816; b=rZbqg30npuATdcyv8dEe/iDEj+f7xFMFdcugi+xweNcpCrA/L7Q1YeSnNAxCn0EKXL EJQboQz3pFeieGPNdYpwFrRlAWLpzZvC7vVxtyreJ0zBNy6vJFQ03irs+HW3WrW1kVCK ria2c671hb2VzrrSDTdDShwqnAr8ozDQevUNa1EaWaJuaYo4gkqbcUtFqvkzbZr/X3KX UrhQ64wIkKH7VbxuRMdNeExft2Lm+pzd5XQARoooNsiPjilKehggvhEhf6qddfBrYsBm b+BzDnxVZlz5RuMapWT+iMLXxY85QtOAH2pFgLYXD1Y1zeHQ/Ha9TbT+r2LCwWJvzQyn 2vUg== 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=LFYLu77wIMuSVQVAFzs5k82d/jPQ1cH2g2gHqj8JhY4=; fh=NxmCHexitX7P6x/7ARv3vZBmyAUGQGWkF2RSnxwWsIo=; b=QbCd4asfUJcim9O8y8GkLQiIbaaD2AqJ5o6vkMiXAOqeG9j77Nvy7iGdZKEF1ofMc0 pXk9SBG7vfAUsMg8HakjZq2tjvx78spcBGopGnwYVY9KobPWSmKG8XIG+wypf0QvkGJI L2zYbpaHedY1akDT09kpHU25fOm7lCElJSTJ8nXDeenX9tYPfCXvCXQRJMLBDAP8cJsN TJuAGi1hH2xEYh4dafNJ+rzAnKWzm135Lm/Satcni11avcGx6hs06wwtqGXYg6tevryq b/KercPUgib/AafWvX1NAt/coZII6gwUW8YJtx1PuwIfswsuT4GEUUYA5oAZWyUrZwhD 261Q==; 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-194171-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194171-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 d9443c01a7336-1f44c9cd7d5si99871575ad.512.2024.05.29.06.37.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194171-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-194171-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194171-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 8173A28381D for ; Wed, 29 May 2024 13:37:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83F6018EA8; Wed, 29 May 2024 13:37:26 +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 711BE14292; Wed, 29 May 2024 13:37:24 +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=1716989846; cv=none; b=D283yE3VPKMUzO9gnrs6zkyqxYSA3X6h774mQPJIynGSnIB6nwfAKozwgJdjKfEoe63zUH7Ft3O0FkCrDET+GlMJcH/Qag76R+Qp/ixGAmAFWBHWEek9GEI1pyFeXLR78PEjkYq7TpJqq1TcORMy2IUHf/pByJexjwf2h1tY0G4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716989846; c=relaxed/simple; bh=z0Da+7oBgSj+MoexvSz2tuXmeO6MGtpZpInCdx9MGPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aUN5AxVgDJCd7M5v8k/5/7yZ5T61S8nQONtFB30yzxY26At1nJV5HUO7uWhPivqhTno8lRgrCfAnZZZNhkC2tRkxtJI4vd3ae4r7PuSdXCUPIpSXxgqGuZpKGzkBhS2akUJhJGrIs55t84E+BfNv1xV6k3Qvptb0lTqtE473Gt8= 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.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Vq9Lp4dsqz6JBFj; Wed, 29 May 2024 21:33:22 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id C2956140A78; Wed, 29 May 2024 21:37:21 +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.39; Wed, 29 May 2024 14:37:21 +0100 From: Jonathan Cameron To: Marc Zyngier , Will Deacon , Catalin Marinas , , , , , CC: Mark Rutland , Thomas Gleixner , Peter Zijlstra , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Hanjun Guo , Gavin Shan , Ingo Molnar , Borislav Petkov , Dave Hansen , , , Subject: [PATCH v10 05/19] ACPI: processor: Fix memory leaks in error paths of processor_add() Date: Wed, 29 May 2024 14:34:32 +0100 Message-ID: <20240529133446.28446-6-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240529133446.28446-1-Jonathan.Cameron@huawei.com> References: <20240529133446.28446-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: lhrpeml100001.china.huawei.com (7.191.160.183) 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. Acked-by: Rafael J. Wysocki Reviewed-by: Gavin Shan Signed-off-by: Jonathan Cameron --- 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