From patchwork Sat Nov 30 14:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 846305 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2063.outbound.protection.outlook.com [40.107.100.63]) (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 1037319E810; Sat, 30 Nov 2024 14:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732975545; cv=fail; b=DowBcg1y5AOChr84a8GrYsSFZNUhU09P3PHADHVQNj9tfYgQmR8HhgxbdnhZIOi2ritiTr/zJmKftUB1zD+pjQe+Id/kjBMNSJPZCTq1VCCU8pBRpyWgH4jhpJNuQy2bQKijizrbC+SjQYxZMGIxOMp6Vlr6BABTwKka1zXwJRE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732975545; c=relaxed/simple; bh=V3j6Quiii/WwfOPqQqSXcjQgntdEWqh0e4XnsPoRYZ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lviAeeV0U9L1VX+hkr6ri4GT33BVkwfX0zQLxllv3nzbhuE0r2zbDAPf1P/Qa4DsJx6YX6yKVgLCVKOIRtBslTZ69OYSR0CLu1oH6T+cUKTUW+VMscTuxyoK5XfpwyjCIhGP0LYn3zpylRhsOtqcGOyI0Z/Sr7nInQC+0kB62tk= 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=vwyS8QH9; arc=fail smtp.client-ip=40.107.100.63 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="vwyS8QH9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dPDdZcHTH6aUjoE8I8HJ5UuSv+kMDAiI6BM0c8PT+6vM7S1VXepaL+hbkr/L3ZrL/kdTdfaDyCuZZwt4BS9m53zSmo73mt8WFAfEg5BIORgH8/XPHsJUb7Gs52yhTMuSn6vgfqSlCgWYbHhi6TghWC5aDCE1fjGd6YtwBwrTrZOQ20Smt7PbUqmUNzUdF64E9V8pG4kV89GvwdU0S0k3PYqUpAnFtGEfzt6kkgUKNxo9KvDxpSdXYT9gTX2X2UGMqA+C8KOgKx+dmgQX5dPN+uZQ4GQzjY9xGXzH/13SVZQ7aSuu37S68T3NPFtGOZ37xnZFFPX5gsUhVuQdS/c8jg== 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=gFzS4aCzkKI1sKuTsJPHF2D67+jU+JB8yqsEk0kOkA0=; b=im0yF9FdmnEYIz1EDgSs84Iw5tyYms+5SOA/rkluzN1FWOAnS2Nzk2go4gfQA4RQxi/6aZYGgK23lBRDGV60LvmLWDzsSWAv1XJej+cLx3niYmDyKDDhebS7W1XMTjzh3Rie7TFjciBJknGiB2Wih5oZCWMmNoYqNgkRBfUOC57/yFTT2j4SC6VC/OMAgzZeJsw7STDhNqf5leXExw6wV6oBnDHmcmgMJx7m6l18F8fHDdSOeEuYBu8M2bR0lZ5OqP0GqgqE8r2GYqKKniTkxzwcWVSOtUxGSlwX/x8HiiORUuzI4xs4PQSoWn0mZ0pHGJy8ujMcdXGLyDBjjuFpfw== 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=gFzS4aCzkKI1sKuTsJPHF2D67+jU+JB8yqsEk0kOkA0=; b=vwyS8QH9hrRqL2PP3N6VhxJmTYPZ2Uabf3FU558UuLJv5FMdhaoiU0liBJKl2Ws0cfbs2Gd5rdZrsxLGbLxQn3eJd0WJlXArqA5ajB2PGolZwhtpfQQLbdjkuXQOR24Ru/cMpURDsb/1o4jN8OTXfriApgnnvcREntMGBd4rwWI= Received: from PH8PR05CA0014.namprd05.prod.outlook.com (2603:10b6:510:2cc::7) by CY8PR12MB8339.namprd12.prod.outlook.com (2603:10b6:930:7e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.14; Sat, 30 Nov 2024 14:05:38 +0000 Received: from CY4PEPF0000EDD5.namprd03.prod.outlook.com (2603:10b6:510:2cc:cafe::fa) by PH8PR05CA0014.outlook.office365.com (2603:10b6:510:2cc::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.6 via Frontend Transport; Sat, 30 Nov 2024 14:05: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 CY4PEPF0000EDD5.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Sat, 30 Nov 2024 14:05: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; Sat, 30 Nov 2024 08:05:35 -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 v8 09/22] ACPI: platform_profile: Use `scoped_cond_guard` Date: Sat, 30 Nov 2024 08:04:41 -0600 Message-ID: <20241130140454.455-10-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241130140454.455-1-mario.limonciello@amd.com> References: <20241130140454.455-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD5:EE_|CY8PR12MB8339:EE_ X-MS-Office365-Filtering-Correlation-Id: 22e2d806-bfcb-466c-debc-08dd114810ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|7416014|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?4nOh6grUE57oUNVWduHYcCuqOF3o240?= =?utf-8?q?qWny/wbsVU7YH7qpJzRpbx8OShtvYsxD/8CY1PPbSbgsRZj3lQuGLv1s29gNiVxGJ?= =?utf-8?q?N0zxcptzGe6Jm/lc80WrsAxpNfyEZrZ3hkUcgIqsLB920yOmmw0Jqb7DOPM/AVHPE?= =?utf-8?q?0RJJrhEsBYJZKrf90+jJrfybuaEGhtg/0VB7NQEp32BWl0wbm8MLkGxY4Z4ZtazFj?= =?utf-8?q?3efDTFam+Tt39y5rCBjaF6p4uNPUHpBTHV8LhiqIRuLPcq0UYGqZr28FYQHe6h/16?= =?utf-8?q?8J52A4u8I0EunwX33VBptuUiJdLDk3dRbkUvm1v4ZoS5Q5RPavstsFS5JWMCVg1Vf?= =?utf-8?q?iq0aNqRJi5McJgAVZ+GDJPlWWqgAFfPTailoXM9RAZ6UucAxu38qSnu4Lix2rNUV4?= =?utf-8?q?xeocKxmjCUPkE+QAxDPcJY6dBZi1XS4MXQGZgj+H+eFG91hGq/uE49+Topa3oWLEp?= =?utf-8?q?LzGYK+QvURhFtnRduQGT11Z2iPhCbGVChQ6wIXgS99M+dKzRDui8x1QN9+0uHeudw?= =?utf-8?q?SJyZb0dZNrbfHcjub4sRic72ikMFmVDduMOFyI3meBH/aFSamASLkOaoeSqtVswAw?= =?utf-8?q?dU4vPcG+H9yB4DKaIGvKBW7blGxKl8y5fYPwbmkw1oqgg1gCH23GDjC9nNxct2O/5?= =?utf-8?q?/onUFN7lAIEMFcv8NfgJDvcMTvOnMuA05nEuYVSL1tTA5DnY/77AW/zGDTXpjOtjq?= =?utf-8?q?yA2tQLYJqZi4h9mRy5pvDTVVsjX3O27qlnSFypUTMtmtoyTjvbPI0SyNdIS0uur8h?= =?utf-8?q?HjklG0uyTMNZ1NroiZPddZFhJLu6Zu7xxyZvS0PznP3UVOi6UinHevfgIid0av4+i?= =?utf-8?q?UTUsiYrVFGkPqvtHx4GGClfNtDg9bQAxShj+bFHlHPe6XiaVJ5qaD5s0lcP6he7sa?= =?utf-8?q?8eTUwSxAv0Fyn7CActkJNse2LQZ7jFxJ9dyOr6xGlcopIUTAE4cBaWS6rOziWzp98?= =?utf-8?q?v00sl31aLPI4WyeqxSbwcpiA5G5qDvWtYjieVtLgdKOQCyOGxdQLBweMDY+sO0n33?= =?utf-8?q?t8hcAbG4rDkseLKWTWO+h4BYzulNhx+dGT77O0RNnUAaLAHcfDoT088xa7NP+Kiuc?= =?utf-8?q?MKgWd2jmyQtVCrQCiJZcGDu/+Vd+ND8lcTFYE8yH3CFPPSxuMb8mfSWHzzSVCpDZq?= =?utf-8?q?r3f5IB85224w6cGgC0hcOdLY2yYTgxUbFuecJScvQtYNmmgk2m4L3PnpBTaB9+73K?= =?utf-8?q?7ktJUwSU3g8OIBaZVAc3WZYi3eAn74MT7L7AaBaxYCLqZGIdJhCWmpOmwxZK7KF13?= =?utf-8?q?RoP/+I8peibTaUsCKR/QFEQRMIuViSH37F3hep84cqu0h9DaRnJhqQ4RjxgTCHL5O?= =?utf-8?q?eb9rDVlWEirP++8NG8Qg8+Rw61wEcwHkGo5Y5cunB+3SaXkTdQuiQzqrwuLRdnpZ6?= =?utf-8?q?vz8dlUIZv8K?= 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)(36860700013)(7416014)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2024 14:05:37.4102 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22e2d806-bfcb-466c-debc-08dd114810ed 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: CY4PEPF0000EDD5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8339 Migrate away from using an interruptible mutex to scoped_cond_guard in all functions. While changing, move the sysfs notification used in platform_profile_store() outside of mutex scope. Reviewed-by: Armin Wolf Tested-by: Mark Pearson Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello --- drivers/acpi/platform_profile.c | 111 +++++++++++++------------------- 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 9729543df6333..32affb75e782d 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -27,25 +27,20 @@ static ssize_t platform_profile_choices_show(struct device *dev, char *buf) { int len = 0; - int err, i; - - err = mutex_lock_interruptible(&profile_lock); - if (err) - return err; - - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; - } - - for_each_set_bit(i, cur_profile->choices, PLATFORM_PROFILE_LAST) { - if (len == 0) - len += sysfs_emit_at(buf, len, "%s", profile_names[i]); - else - len += sysfs_emit_at(buf, len, " %s", profile_names[i]); + int i; + + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; + for_each_set_bit(i, cur_profile->choices, PLATFORM_PROFILE_LAST) { + if (len == 0) + len += sysfs_emit_at(buf, len, "%s", profile_names[i]); + else + len += sysfs_emit_at(buf, len, " %s", profile_names[i]); + } } len += sysfs_emit_at(buf, len, "\n"); - mutex_unlock(&profile_lock); + return len; } @@ -56,20 +51,15 @@ static ssize_t platform_profile_show(struct device *dev, enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED; int err; - err = mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; + err = cur_profile->profile_get(cur_profile, &profile); + if (err) + return err; } - err = cur_profile->profile_get(cur_profile, &profile); - mutex_unlock(&profile_lock); - if (err) - return err; - /* Check that profile is valid index */ if (WARN_ON((profile < 0) || (profile >= ARRAY_SIZE(profile_names)))) return -EIO; @@ -88,28 +78,21 @@ static ssize_t platform_profile_store(struct device *dev, if (i < 0) return -EINVAL; - err = mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; - } + /* Check that platform supports this profile choice */ + if (!test_bit(i, cur_profile->choices)) + return -EOPNOTSUPP; - /* Check that platform supports this profile choice */ - if (!test_bit(i, cur_profile->choices)) { - mutex_unlock(&profile_lock); - return -EOPNOTSUPP; + err = cur_profile->profile_set(cur_profile, i); + if (err) + return err; } - err = cur_profile->profile_set(cur_profile, i); - if (!err) - sysfs_notify(acpi_kobj, NULL, "platform_profile"); + sysfs_notify(acpi_kobj, NULL, "platform_profile"); - mutex_unlock(&profile_lock); - if (err) - return err; return count; } @@ -140,36 +123,28 @@ int platform_profile_cycle(void) enum platform_profile_option next; int err; - err = mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; - } + err = cur_profile->profile_get(cur_profile, &profile); + if (err) + return err; - err = cur_profile->profile_get(cur_profile, &profile); - if (err) { - mutex_unlock(&profile_lock); - return err; - } + next = find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST, + profile + 1); - next = find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST, - profile + 1); + if (WARN_ON(next == PLATFORM_PROFILE_LAST)) + return -EINVAL; - if (WARN_ON(next == PLATFORM_PROFILE_LAST)) { - mutex_unlock(&profile_lock); - return -EINVAL; + err = cur_profile->profile_set(cur_profile, next); + if (err) + return err; } - err = cur_profile->profile_set(cur_profile, next); - mutex_unlock(&profile_lock); - - if (!err) - sysfs_notify(acpi_kobj, NULL, "platform_profile"); + sysfs_notify(acpi_kobj, NULL, "platform_profile"); - return err; + return 0; } EXPORT_SYMBOL_GPL(platform_profile_cycle);