From patchwork Thu Nov 7 06:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 841425 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2052.outbound.protection.outlook.com [40.107.94.52]) (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 E3D28197A7E; Thu, 7 Nov 2024 06:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959421; cv=fail; b=oilVhqzBSdS9Tdhsgksd9GxIeiUS9kmJoX0mm6JktV98lha0/0D/SYtx7sXYFx/9Aa99qLu5BssNO13TJBfdiIuUVJTrlmacPvNqCkrq9scs0hhqQ4ooU1M+iCWknnZ0zDz9dS9y/PZFHFc100Izyd6kYNj+erbKz3ORxesKvbE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959421; c=relaxed/simple; bh=M8a3jlvXTMdc/FFBVebMJsQ8wdXj4ZIXAyA82jD0/18=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RSl9IxJYTBT8iURUy9L1+YLsfnV6k10KAtvnFWNPzgoyCRIvCkqpSPGFQ26NKh1HT+8QVhhpt8XT7QtNpiFeb9klCqSb7fd7bgkNC0z8ZjZSarZuIW0Y1Thye71ZGF9+KU2V4dF45960fC9kKrfTdQb0QiNgnQqLUw5RIwFx/Fk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=238mT48P; arc=fail smtp.client-ip=40.107.94.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="238mT48P" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HeRZw1Wkad5JcdLYb/sm1BCmjkf5mk4KvQbNkm621xCcY8bgTlAoddXoD8umq5NpIQPxUNw8I04Q/EPPCVMZp3LuxxKgXvDDxDLh+457sWOIHQ0vxoP1xgAXt/fO44Gy9gqVmaMSy7tZqBiI/HnC4/3JDdIRTFPA51NS0KlEHQfYZ+CGge0iNgwEUcM0d4oohmgw2UdmfV9nB4Cp+yxtdrulJfqfwuaFLx+OBN3jaQBp2fVRURe1sXajDKN8I1AE9sYGROWd5STl6f8yQ1NkgMQ9tOzcfSf/XVtUGSbvccRZnkAcL5riEm9+yicdNfvRs413gNHW7dvQqHfvOxKGGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wnfyT3tMCL5FCDOuR+WuRHGXHAYbYss7SLrNrf80Y7w=; b=oRG10fke0HdSeqABf1E7OnkTJIVm/6XWHE1wke04MKIaFVqfXtA5oWXssWls+fFtALUXED+AXtN6QCEeTHUnAUEBfPlGfVtoEb07DE1hO/61kAZrxQ/vmSq1+pBxMkPCSXTXGXEcKH6oG6xkx2XfJYHmwg2Tald8a81vfOC831t1QZ6Fp3hGoMdqbE6xZmOJrPvJ241Zywd5ukryM75Mlu1XiN7PrZ+m5AR0dWjCaBao3r9TcZNNvWUGwpeRVXVyfRdXXw1Vf5EPeOM0YoEWcK8RQzF4+8+Na7bEbBiVYgGlMq3T2Q+fO7eg/4INmZvsONaDLC9KS+ggu23lzlePpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wnfyT3tMCL5FCDOuR+WuRHGXHAYbYss7SLrNrf80Y7w=; b=238mT48PuHuV111jTjNXMa0+Ba9qdw8j5a9JRiSQhxNXvHgyogPSM5CL4VQCNCzDPfuw82EtJ50dtGc2orHHGMZniFgEG1NemOhgMJ3o9N0FbSMIRChCmPwkZRSXtvvd+rMJZ1ZDb2hwYgz/ZtQsowm8gaQ1BBoTR5+BT6uPhyY= Received: from CH5P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:610:1ee::14) by CH2PR12MB9519.namprd12.prod.outlook.com (2603:10b6:610:27c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19; Thu, 7 Nov 2024 06:03:37 +0000 Received: from CH2PEPF0000014A.namprd02.prod.outlook.com (2603:10b6:610:1ee:cafe::4e) by CH5P222CA0013.outlook.office365.com (2603:10b6:610:1ee::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.20 via Frontend Transport; Thu, 7 Nov 2024 06:03:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH2PEPF0000014A.mail.protection.outlook.com (10.167.244.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8137.17 via Frontend Transport; Thu, 7 Nov 2024 06:03:37 +0000 Received: from AUS-P9-MLIMONCI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 7 Nov 2024 00:03:34 -0600 From: Mario Limonciello To: Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= CC: "Rafael J . Wysocki" , Len Brown , Maximilian Luz , Lee Chun-Yi , "Shyam Sundar S K" , Corentin Chary , "Luke D . Jones" , Ike Panhc , Henrique de Moraes Holschuh , "Alexis Belmonte" , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Ai Chao , Gergo Koteles , open list , "open list:ACPI" , "open list:MICROSOFT SURFACE PLATFORM PROFILE DRIVER" , "open list:THINKPAD ACPI EXTRAS DRIVER" , Mark Pearson , Matthew Schwartz , Mario Limonciello , Armin Wolf Subject: [PATCH v5 06/20] ACPI: platform_profile: Use guard(mutex) for register/unregister Date: Thu, 7 Nov 2024 00:02:40 -0600 Message-ID: <20241107060254.17615-7-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107060254.17615-1-mario.limonciello@amd.com> References: <20241107060254.17615-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000014A:EE_|CH2PR12MB9519:EE_ X-MS-Office365-Filtering-Correlation-Id: d38d4228-dc94-45ed-99e1-08dcfef1eba1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?jZHpcrzlmebX8ZAyWPJ0nZtjCUcNtTx?= =?utf-8?q?HeJ642OlUW5vbBveJE+4rNlKPeGJUnyXNtZeQUaYI2TljDwwtO2zLUHebUFw9IRLh?= =?utf-8?q?QHr46a7fZdsziPAhOreKSmBifWTMQb2YFTGyuJE2+qNnAvs7ZjvEfM/f2fiZBgS7n?= =?utf-8?q?U6sU8FWfq0HXR3LMsHS4tAU6NFUtmhINHVg9iFGDuuN3p7K9r5+tOHC2CG8z3/1lz?= =?utf-8?q?SxzZUsvoDvJ0KHLeq4M0QlBfaZnbFsh+HOLbvzcs/P6vNURnGZtwsunabfvhmxlWb?= =?utf-8?q?jIyBzqZwJEvrXUXK4RPknm1eLT7yteuUNDi4R+oU4AnDR7F9apUUqwD+ZNQWIwC8V?= =?utf-8?q?ELvjz2fB+ZSG8KlmldFytI66YulKuFixxKO8vUu2DoQqFLRG2oktISS2kMmatzUnc?= =?utf-8?q?Ivdhsfz7WO2mflZNHcUf8w4dXTPaU7DzFlyNGNncziMfVseG51FS1xrcqo5zalbBN?= =?utf-8?q?gdVX4sxEr39bIoCaq+JBjTN/WLEWYWbGbcBG1RoaYLsO8x8/WJ1uSxfH8BNrIH1DU?= =?utf-8?q?7JYDZlRAiY/N/VvbmCnxrJxR3KQYfzAE+s4RBtTk4P3OArcKXzCz951vGZt+M7OAR?= =?utf-8?q?I0ckyaB1bK11EW1cHGOUu99mFfjjfr1RlS2z5WHgZt/6VrDVA4liw9kdVsm9nStpw?= =?utf-8?q?hsTQvhVXOHYG4OKlZf41qnqyrTvHxFb68vWx2nLx67xMsxURkLbyhGkZYopfk9EZt?= =?utf-8?q?lcY+4ZRwFMV1+2v0Y9mg6E27PEv7TtALvfhWu4MhlAo/dau8inCavuyy3ZGdPUoAf?= =?utf-8?q?eZHXy02ps5QOGFy9WF73rdpMMutufSIUl8TMTIhjNFQiDQqWkruNmH1IPh/ZYtyrS?= =?utf-8?q?vCEmcGsntfnNYds0SoWRTS6agspEebe7L/27X3PAFVvnDlpiRf3Qo7aZbqq1JZUAS?= =?utf-8?q?/1QdmiCXWffzFXauAq/57A6PjCPntMf8X4+JWPSF3SP5cLcyGaUQzxD9UVf2HbIRd?= =?utf-8?q?V8PxaFEaglfJsu8i7oklUs3HArm66UoAYbN6yLvT+1YthfqXtkPU6kVYMHJ+oRwZa?= =?utf-8?q?XS5Y7qbZLvj18bt1rzMabm85qhZt+KaAjnuKwZseKw9NsIa4PC1gzdTPQUxG3kgH/?= =?utf-8?q?6qfR/wE/7r0slpdSopzN5cyfB+YMERQTrgBNeXREdlQq79IrfW+Ztaig4Fl9qF6bt?= =?utf-8?q?HX+gpH+SP4Y0yVaItY36gTAJFA/wp0VMxuHZ/o6EB/71HNm9feNj5Kvva/pluvMHs?= =?utf-8?q?dD/U4q2UbDnVtYluo0qh3mGcxe0SLSBtjacREOtaI9HS79UnIX5mXqRn6D5yemjhj?= =?utf-8?q?Olx8JQc0uxtcvbHriT9RE3IFMW81EuooSJsNc605XVnfQOdg10vZ0XWYmp9I2vqDd?= =?utf-8?q?Dn+T/9W8rj58n+OaL1FytKDOWNRP9LZT/w=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 06:03:37.2015 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d38d4228-dc94-45ed-99e1-08dcfef1eba1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000014A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB9519 guard(mutex) can be used to automatically release mutexes when going out of scope. Tested-by: Mark Pearson Tested-by: Matthew Schwartz Reviewed-by: Hans de Goede Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Reviewed-by: Armin Wolf Signed-off-by: Mario Limonciello --- drivers/acpi/platform_profile.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index fbdf3cdf1141d..548eb99253958 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -184,32 +184,26 @@ int platform_profile_register(struct platform_profile_handler *pprof) return -EINVAL; } - mutex_lock(&profile_lock); + guard(mutex)(&profile_lock); /* We can only have one active profile */ - if (cur_profile) { - mutex_unlock(&profile_lock); + if (cur_profile) return -EEXIST; - } err = sysfs_create_group(acpi_kobj, &platform_profile_group); - if (err) { - mutex_unlock(&profile_lock); + if (err) return err; - } cur_profile = pprof; - mutex_unlock(&profile_lock); return 0; } EXPORT_SYMBOL_GPL(platform_profile_register); int platform_profile_remove(struct platform_profile_handler *pprof) { - sysfs_remove_group(acpi_kobj, &platform_profile_group); + guard(mutex)(&profile_lock); - mutex_lock(&profile_lock); + sysfs_remove_group(acpi_kobj, &platform_profile_group); cur_profile = NULL; - mutex_unlock(&profile_lock); return 0; } EXPORT_SYMBOL_GPL(platform_profile_remove);