From patchwork Fri Dec 6 03:19:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13896364 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2076.outbound.protection.outlook.com [40.107.220.76]) (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 87521193081; Fri, 6 Dec 2024 03:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455555; cv=fail; b=u/3W/jqYF7ooRdwPYO7y13VBeEWP9WFFXlm5q6yh6tftVb8GH+rqbL0+ENEAHuv+fjh8T2fQdo6kzA57ycT9KpqG4moczS1IILR9yTUiL1dTgvE2kdsL6QKXWUQV1Dq0VFHUkzvJSWF3Ky0DmWLFvjqArEoCQK4+OZsM9nhYXCE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733455555; c=relaxed/simple; bh=/qmctw3i+Wn7MreEBUXF/bnvNkGTZZxbxd5qgq8OyVs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SK2rDeqsLDdri19n0yxwYvXEPwtbGpqizBlDfNwYpklifAzMgleStjqPTz1l4MXaELCCtPX2HBqZG7nkL8jlDetk5UBO+TjvQ4rsu9fQmYs+GaETgSZfFNP1g9p+bnWfOZb8qMaacQRO6KPGuYOTTey5dRniOe0uubxkSqSqxO4= 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=FAieoQTt; arc=fail smtp.client-ip=40.107.220.76 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="FAieoQTt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=agOQ7weqXfaJ1IdVC3lR5bWT6Yt59Q4P2dNEuw0C4bHABOzyLCzqhg5i/moe6DnAvX7SUiRfD24a7n7jWoOzH+DLVCHQaM7MyqQIOVQiT4bv5/nCBmgl05UhyVWpfWIzxMNiJbwxW1XhF1OOpU8aa5R8OyaWk6csrhe1UuZ6gKD8cAdxkA969M3m/w+tMeTabyJUB9cuZJWbf65ynMHXY6HfAe5HsRaJjlfx+5fI4rn0Pt3FRiGL8hD0aQurXtmmJcQp3RpFIl4/eLW8z1aLn+OUhFDPw1ph8I2gCg2xuNB4ZAd8OUZYMHPkv8OuGqgyBqclm4LzUo45HKjHxIK9NQ== 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=Co2MBzyi5zV9sPvcG3WQUc/xYGa6VyD13j/k/x+NdOw=; b=Vj6g9OHZJIAVany2mN4ALQUDI3+BYYeHS8A7UTIr24o/IR1+KEW29Y7rUOXjfb9qLIdvDTJnvq8pUeRE2Jgdv+FraMp7rszCy+d7XMS+mYuKVmQ6XN5dFjQJpZrmxQlXAmHy9iGCycW6pH5cSz+56bjQG8GfdTlVB0zFsZVi+GwkCbik1AkeNoRo40ni9rNbO8H140WGdCuzvO7RHEZCKGqU0agFJrGqK0PMWrCYdjE/esn4KBMic1m817liVzHmEkWxkkOD3holzGHlw/7HBSlFWH78PtJ3ttrdGrxte/p+jVkCy/p0zAv+NOy2oiEf+vgULQyBd37iyYjIcyYrOw== 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=Co2MBzyi5zV9sPvcG3WQUc/xYGa6VyD13j/k/x+NdOw=; b=FAieoQTtwtuROXbDPE16w+T5kxoNMHscXSB9Cx3GByF5p3tuT0sT+N4DX9Z6GrsMc/D5hG3TD3Uatenz3T7eX1tNPB2+U5hdHEk66GJderuEO2CdFpW8rMUa8oGxnhOM/jfRQ1qFwJ6mimhrpBykxWu9V3esiFQACBanvtqkZ9Y= Received: from MW4PR04CA0052.namprd04.prod.outlook.com (2603:10b6:303:6a::27) by SA0PR12MB4478.namprd12.prod.outlook.com (2603:10b6:806:9c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.19; Fri, 6 Dec 2024 03:25:48 +0000 Received: from MWH0EPF000A6734.namprd04.prod.outlook.com (2603:10b6:303:6a:cafe::1b) by MW4PR04CA0052.outlook.office365.com (2603:10b6:303:6a::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.10 via Frontend Transport; Fri, 6 Dec 2024 03:25:47 +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 MWH0EPF000A6734.mail.protection.outlook.com (10.167.249.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Fri, 6 Dec 2024 03:25:47 +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, 5 Dec 2024 21:25:08 -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 v10 09/22] ACPI: platform_profile: Use `scoped_cond_guard` Date: Thu, 5 Dec 2024 21:19:05 -0600 Message-ID: <20241206031918.1537-10-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241206031918.1537-1-mario.limonciello@amd.com> References: <20241206031918.1537-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: platform-driver-x86@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: MWH0EPF000A6734:EE_|SA0PR12MB4478:EE_ X-MS-Office365-Filtering-Correlation-Id: d54a01b3-c9cb-4012-dcbc-08dd15a5ad31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|7416014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?q?lYz90L5TYyp+B3BLYoHIsk0wJkSPzYa?= =?utf-8?q?eRSmna4cTLBrfyzKnuV88hHzw7HQ/cfLTwhELbDntse/2L9H583INmwqrAm7qJIXK?= =?utf-8?q?7bY47ELppN/lU6Wvd74dSTnFePcCL1iZKY/61tnh0HFBb7c91ckYj7XlMEKm06CLx?= =?utf-8?q?bW60hTBGoYatyDrp32Z+1r8uQHEutF0Wxkob2SJG+srO4W/3oyTl1hmtYIMcspUeR?= =?utf-8?q?Kd6yLgGBrh9L7m8FSR8V/6/BUkwkgcKRBx+YjcHHvMZZm+YWCvqglJmCNV4/NqIkb?= =?utf-8?q?DSXx9x8750p/5e7nUC49AlM/sbvm5j5Qb1p5152ea3NyiUSbSfosYPlRXRKw0Q1RZ?= =?utf-8?q?BfejucfTD8w2EbDsfh+G1Jmc6m6TjtTMoRDHFRfkMLZLd82NTq2Fd5XT4QAmhHJOu?= =?utf-8?q?MqTjBq91WnA1nTTRH8qWi1+u8D3vcoHbPXKtP0Ds8ngIGLLx+0tI1r1Fc7IcH+L7z?= =?utf-8?q?kjI6QKHpBV1H3hx08nZB8mo92tS6vlfEZhZQli1pxqLI9d3Sc3tFj9dH2RlVQ0P/h?= =?utf-8?q?42yYcvGVSNpIWMDWSIxK5zazGuPv4P6sv+xTIX5ACAplQSv6Wfqolyg2MQ9w4VknX?= =?utf-8?q?X/3/Pi+rDB7AI8d/0J0lJqZicCMUVSao3M4HpNe9Jx9ETOfWEqcpigZZtwSVpw6hm?= =?utf-8?q?BrBRoqUer4cNI8AoA/DRMZ6S4gU0HyZ+3BweZe0Fcr4nOpTZVv9z/0mhS30m1WnMX?= =?utf-8?q?W3GpMXuXg0EwanakxtWuJTqQrr1ai2u/glHZ5CNKGxfB4VoyP0PzI/eDNLyyjQxgT?= =?utf-8?q?BP5z3YrP1bAppimp1GLUACJaiV+GxJ6HnrNSGIfnSiLLDzdVmw2BKe5cx8aSnt6+A?= =?utf-8?q?LPa1A32zzcZbTY2jPpI45OEFoU1U0+ZWEikbny5dqdU7g4gNwYgBVU2l5B0E2tdBm?= =?utf-8?q?gHkDyXMyzfwwZ8qIPJl1/eSfT5J/Ho2zVcM53kzFbk6RNl0OTfgkHwehwzEOnyvWF?= =?utf-8?q?wO8Quu99/PS1+lsgU0P+QUwDHuZJEPeHJn6SHbq7a1lVomwUIt95Tu0LFMT8Ltn3w?= =?utf-8?q?s5bHrIuPw6HSw6CEdROJvQ5svDLDuJj6QAZHLvaDhJt75iQgU9zuVZuBjpDYOKVHO?= =?utf-8?q?mE1pi5eVhKFb0ff3ReRaO+GnMSaZ96jqC9w8NmskZyYAcW04WE68CFKNj7CpyWVj+?= =?utf-8?q?KzH2PJ2ajAH2GyTXo0/ztl40uFTiSTaYpu6hvZIAn8JluUjrHU3X1NaCH0/nE4nnh?= =?utf-8?q?i3OIH+vyG+JzkonOG47J6b7QMVlYsEXkFJgecCGYIaEFMUdwJ973xaawW9O5f0mFm?= =?utf-8?q?LNrkRptVwH6gbMstbf4sB3LJo++CFA7pNyYbXOKyzcTWyfTdI+VchJ6k9MeBBKKSg?= =?utf-8?q?9xY2QwgL3veDkrPkjyEx4jcBQ4jjz88ujDatn49QDiztG2ehTilX8/+xZgjfwnKH/?= =?utf-8?q?EfCentFck3E?= 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)(376014)(7416014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2024 03:25:47.4272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d54a01b3-c9cb-4012-dcbc-08dd15a5ad31 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: MWH0EPF000A6734.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4478 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 | 105 ++++++++++++-------------------- 1 file changed, 38 insertions(+), 67 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 9729543df6333..a1f0378f15e62 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -27,25 +27,16 @@ 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; + int i; - 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]); + 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) + len += sysfs_emit_at(buf, len, len ? " %s": "%s", profile_names[i]); } len += sysfs_emit_at(buf, len, "\n"); - mutex_unlock(&profile_lock); + return len; } @@ -56,20 +47,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 +74,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 +119,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);