From patchwork Tue Nov 5 15:33:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13863099 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2057.outbound.protection.outlook.com [40.107.244.57]) (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 3D6B2145B14; Tue, 5 Nov 2024 15:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730820849; cv=fail; b=Jc1K51sUmiDeHekFgn1FX5rNmkEHIdLEmY7D7l6fzyQVa/IcbyF0QCZOwY7fW7LgPqTsNzmL8U4txvF1tTAc5U0d1giCAU6hm8SK94ukwE81G5sCCNblA4Kh24iL5RBeNuYf7oi5bND4ni4UpTqsi3pCrl2mXrE51IqBNNa0Yeo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730820849; c=relaxed/simple; bh=CC88Q+zb9x+qJyFWT0r7BsGTISAdvYfUNOCDT0p7LSI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QvTQ6RbyUqf883WXlDUbLhth7HSq3dLp0dLY8Amaw/PYwP8mvGTVUBYlO+oLHgjwspLtAKw61XVUDIKaIhIXjrB2gYmULMgfwWCObOm3yidgV1IEqHxYgn2YelC79ZjhSykFMZvzLNCUCn+4HAo1V+O3aMWF+eq9Rdpz6oBvdhg= 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=Ib+hAAz3; arc=fail smtp.client-ip=40.107.244.57 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="Ib+hAAz3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lI6wIUIBDQdabPZ3W3tjs/3OxPk2PQpKgUHHIY6N0LpHMnk23EIxC6j9ZDZYcnSMzLGCPbWvVOYR6txmcwq7Ta+fbn+CtietX3mFu2ZR8ms5Ew7DXyKfTnXKratcIHAHKoc5HbC3iOdGg3G2E2AjVnHjLQxybx+tV7PCy4rHmAfTd6LrDm0NBeqJLxCT2O7wcNXcrKVMn00sAhid5LHwRJwjP6onTBziYzKIGjcomIsxggMm/P/ZNiiXBqo7UY580mp3Xr2KmiuITb5r0oN0j2bmEg4xNxiJ2+1XqWhjoDphHAu/aA7oPYxGEifWIX25iE1OjtRzPTgx+KbZNF/pFw== 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=DWrFpOP8j0p7ioctz6BKIQzkCfCwrDMVuzyTi8lgzZo=; b=PoCjjbvAaX9/qAC3/pBHkxLUfVijfw0fnXpTPTLnI9frIyngru/IxHbDRGjABPJlfVkYLtV3NawPABoZE/WbuKFxrynTrI3PzE54yvJdl2+LjYMEBIOd+599IRPpgUR4A+TaUv8ecCNT5oIEYQy8ooCrveWPCGHztJM/8Tj6jbbf28pqmS+ZL4p6EpzFuHId38TuoWJrwghunruggnEVlxPdFnlKNuwV+plsfDzDEqct2aRa3RStPVcGjYBkDMeRwZGIHmoKzQxe1S1K08aeoei6kVVS/0Qi0fq8NGLF4g+Q0tNaom23Fg5WRFc0ATVtKe+ZKIu+qVOZ1lArIE8Ozg== 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=DWrFpOP8j0p7ioctz6BKIQzkCfCwrDMVuzyTi8lgzZo=; b=Ib+hAAz32cTi4es0BxJlPOqXCD6OR9HNnwkcTFr5MenQAbczsOz6Lyo5cpVz/xGHk3AOH0N3ls0fM6m/6/IXFMAlquWfd7O/Yq1vPQZ/RdUCDl92HpMcKt+Pb+n5sNbMCsjJ4ZlrsUnvyv3D7kxhKX3wFSSFpWV/aN3Z3y0dnFA= Received: from MN0PR04CA0029.namprd04.prod.outlook.com (2603:10b6:208:52d::34) by DM4PR12MB6542.namprd12.prod.outlook.com (2603:10b6:8:89::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Tue, 5 Nov 2024 15:33:39 +0000 Received: from BN2PEPF000055DF.namprd21.prod.outlook.com (2603:10b6:208:52d:cafe::70) by MN0PR04CA0029.outlook.office365.com (2603:10b6:208:52d::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18 via Frontend Transport; Tue, 5 Nov 2024 15:33:39 +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 BN2PEPF000055DF.mail.protection.outlook.com (10.167.245.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.0 via Frontend Transport; Tue, 5 Nov 2024 15:33:39 +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; Tue, 5 Nov 2024 09:33:36 -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 Subject: [PATCH v4 07/20] ACPI: platform_profile: Use guard(mutex) for register/unregister Date: Tue, 5 Nov 2024 09:33:03 -0600 Message-ID: <20241105153316.378-8-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105153316.378-1-mario.limonciello@amd.com> References: <20241105153316.378-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: BN2PEPF000055DF:EE_|DM4PR12MB6542:EE_ X-MS-Office365-Filtering-Correlation-Id: 62af7fc0-497e-478f-c653-08dcfdaf38a7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?LUBNoVxvQSIs72eRkFKg2qXRYMWzBL4?= =?utf-8?q?uePslpgI6ILQirO77COjLSWftQyTWYf77SuCvRiUW4NH0QJbNt+HKFxudTb6Omck3?= =?utf-8?q?ujXWaHbylZvxXcrPFWgfBg0Igzjmgw7Hy/5hIAqY0vr1FNOlTNmzKa/0bQtqOsaHM?= =?utf-8?q?rCeOmpDaosdXYudVrivGSC2r46JADrWhJCoAi7X7qZyoBzFovdk89glv/TTXJ1bL5?= =?utf-8?q?jL/XkcXGJYSHba2R5SM57bUQ5y1tp/YeI1X3WSa4UWz8uPZuwWDcePFVDxuQi+tAH?= =?utf-8?q?33M61o7uVZJ9iVGkPbBOwDIBogJoCNrS8rANh89DwuJGHW/LKyE1io5mqWeH4A43P?= =?utf-8?q?UxfJNooMQYN0nT8Or/dJaP0+DBGpF56jn3a6/pcpKvtSmCz/4J18bQLhQUWgAlXOF?= =?utf-8?q?8pqam+yhzbw04LJybnuWbWDGep9XcghyJf9HoWCzTfG3IMBqzIg6PyfaqPxZIHcUL?= =?utf-8?q?Rg+Jc2uHj25+lpc0BrOpmFya3Esz00f+SN4s1YfFhlmLwrr+e3qa0e/67l/viCWpu?= =?utf-8?q?IsEvVtEKtZrSd/IDMS8zrS2OCNJ7MeS0LqM6iYUb5m//Ow5ftMqN7xfZELe5iHTcH?= =?utf-8?q?lEiw9TEnQHHTfFCwt6sbSBDZDM7BWHDu8KvQHSvb5yOcfl6yNphzsJtf2oBIs/lvG?= =?utf-8?q?roeu80t5BWuoVMjGUtrWeda0EmKglhqfXEr5gAe4FLfEEcDkcBJjwiYrr7E20MVdo?= =?utf-8?q?f5yLnZWZf1RRXmXFUeEGAxxVRb1QaDR86+o2QnwbaPpb8prnRIYZnafrJEXyBP7Rj?= =?utf-8?q?Khq8ExVJGB/dPG9gHb9ydqzA5OEMr88Hnzf/z3tU6xwoY9T1KSdQVUZE8EbRqm/bf?= =?utf-8?q?hk4Xy4Co0g5BHMaAEI6k+KjsJ5UmU1nIyE5/cABQ4lgOh/V4I573Yn6riU6sM+Loj?= =?utf-8?q?TKgY0vR2kvrrFlTE4Ea7N7noQwLnxtWQxXLM+ndv1nXAWgwqWNCJ0zwPCsQ9OtCaY?= =?utf-8?q?FTKqLtpmulYRbWg3xtlYc0F2A9dRi4Uhob8cdMwAVyqFzxKtIyijsBxc2ESDvnW82?= =?utf-8?q?mJ6+ZmyDnAi/sIk5vHSr630t/qPa0pDSDmAFU9dnybuVzzPk5aw0VH4LH5IIQ5omV?= =?utf-8?q?B763tZFZU949EWja5zPtZESGbeyUEFfaEyoQsJ3WU/t9Am0ycZqO9shuo115o83wu?= =?utf-8?q?4B46TRI1DR5tPUVcrB6JV3gJ6Np4IohuR+6tvPBOBsLEa4YpYT8FwkLL0mN63YF8B?= =?utf-8?q?UR2y5IFAhamrY5Vpd24N2Rj6Vo3XQUSZosJWDgZUOIaBwKhJmxZNe55WKr0Kdiifi?= =?utf-8?q?89Ut1W7FplmNlOb6RLgd+UH/QyhuZoXEmls5b9vDGqvYyA/+jGp/Qxszj+xg5oGth?= =?utf-8?q?9bIC7F/JRm7PicyS22IObT6IMX73uiE3UA=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)(376014)(7416014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 15:33:39.0766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62af7fc0-497e-478f-c653-08dcfdaf38a7 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: BN2PEPF000055DF.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6542 guard(mutex) can be used to automatically release mutexes when going out of scope. Tested-by: Matthew Schwartz Reviewed-by: Hans de Goede Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello Reviewed-by: Armin Wolf --- 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 70e7f1ba68676..4454c4a903c8f 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -188,32 +188,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);