From patchwork Thu Nov 7 06:02: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: 13865851 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2049.outbound.protection.outlook.com [40.107.223.49]) (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 89182199951; Thu, 7 Nov 2024 06:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959424; cv=fail; b=s+BDBWPSxqu1QJpZZHyMx8HcB9hPi0ow6Fb0qs+nVIzqh7+EUNkcJxczZm7ciz6hkfR2j+sC1w2mzBOQOGQq8QffSN244xUDQbUVwftu28mgkRM1+0xim3nkM6gsrtY2IxbZkwT+Ne0S0BzVYgl5TLAuc+z45c4V1Ifug04zHXQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730959424; c=relaxed/simple; bh=Eh7GbAEhOApPgwe7sJ19hDwugoPdNvuFgJKEBageevo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JJluHLAa3ISo5iznx6e/QLWBZxuqqohfDWzMnpzL9RiKKNfGQVuOxgZG2eMvDM4zaD8ZT0uq4xedOc4PbTRbAve9t/e4bSYc3IopZxAjG+bTg11zDkWdEMxY0bhfakZQOcJqt1WHUagDEwtn3Lg4Fik6MGdX6RJJbA3zHRKgMq4= 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=pPsp9J2C; arc=fail smtp.client-ip=40.107.223.49 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="pPsp9J2C" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jp6yA3uyIHUbiNA2u3UPhPt45ry2qCNqqvumWw7q5BTi3Srs79BbK27UwodCrPAQCDz+4stZrJX6+7yBWWFqUlRGXQxZJnvkk5TZ82EoAlRLNNJshuZItGUt5vRBIEZzgJthQXlDVhPNVS2Jul2NB7ZmFnmG5ClFUSb6u7pJNhAqmcl2vn2eUz5NthfAtctUrSmOhFmMZMiIoigJqP+rU2H8PgG2MBqxCDgEmmYUMJG7w96BcluFUbrNvJJEj1XVZ6mdVOvzob6yTJqdDbluLUJFSwpv3XqVAX9fMDtq05AAp3dd5XsTWglrlupVMXSDEHs7Z2ZPKE2vM3Rue9ohdQ== 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=o78hvHLjyjWYhzj1ketM61l/Z9Bnrn7JPtZ4EHIBTBE=; b=yVlfBSqG1vY07IuDrRzMzF7/F2dNxbtGXDw1ZsBaMD/DvVzCYDhSEZs6Usch01igGTKBMAmJe4YERRcq/8T1sM6KoQZozGyLnPRtQrA107wSitqanzTrWeFGiJ1AcarvqWjpFn2fRVqmfTYsz/a6hXQr8vR6hDJx5o1PeD0n15C7qx2/3gfDAeF64u4eZ/yd0CqahK7E6DekLPV65JAWA+rCUpD+8TpQVwXDsGaW2JPyB2UHj59VbOgr042y3vLzCmQuHGetn6iz3KIa261lBQHBliv1TKmLfdFPKI55dKBrPpR2BdMdYwyIo8f6dzKVYZAAZ1S0PLnbct7wACQUSA== 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=o78hvHLjyjWYhzj1ketM61l/Z9Bnrn7JPtZ4EHIBTBE=; b=pPsp9J2CEdSAOVr5c/iRyGfdAu91HjHewI2mrOpwcLAX/F88ghju8eOcrAF4KRFibVdmnq7zd9xb9qFh3M+xoHNe5Jn4ZtRDZw4WrCTWApe9fGx0dgonAkWos/SMHq298EG4JZB68KN9EmZfrKRFweAZzsUqTpUHxAHp41jSqUg= Received: from CH0PR03CA0271.namprd03.prod.outlook.com (2603:10b6:610:e6::6) by DS0PR12MB7653.namprd12.prod.outlook.com (2603:10b6:8:13e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.33; Thu, 7 Nov 2024 06:03:38 +0000 Received: from CH2PEPF00000147.namprd02.prod.outlook.com (2603:10b6:610:e6:cafe::1c) by CH0PR03CA0271.outlook.office365.com (2603:10b6:610:e6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19 via Frontend Transport; Thu, 7 Nov 2024 06:03:38 +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 CH2PEPF00000147.mail.protection.outlook.com (10.167.244.104) 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:38 +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: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 v5 07/20] ACPI: platform_profile: Use `scoped_cond_guard` Date: Thu, 7 Nov 2024 00:02:41 -0600 Message-ID: <20241107060254.17615-8-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: 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: CH2PEPF00000147:EE_|DS0PR12MB7653:EE_ X-MS-Office365-Filtering-Correlation-Id: a8809ab8-8428-4f4b-7896-08dcfef1ec3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PKWCB+hAFejG+vXOk4ndjDF83WyPNiK?= =?utf-8?q?QMqnAjgLJ7yUq89rgVI/0sqnPtQ8k9u1am+RSR2CO2+YfDYjWOnfVzNcPfJn3E9Zn?= =?utf-8?q?5gb+r01PlGlwXioWD3O2ZsydaDE7evzZHTMG2jlcF+pDh9t3drC7K+T9aF25c/C9N?= =?utf-8?q?qzAIzpawR/gqlW7Iis0MSU1aXkEQkGFa6q+Bau4PWgaiGoRCGhfQJ6Gu1p+V2IiOo?= =?utf-8?q?96tc7/3NbDmqYhPkDTSEUSBuK8h/xvSBlUzVyhfrADfWjyIMZdNUUVAdBn0Cw5EVe?= =?utf-8?q?5jseBlGQv40+7xsA38DNipp1X18pfDq7yFJhrePuxDnBlH/OQFXEgEaeIvjWp61p7?= =?utf-8?q?6RxAN9cA6kDnYdLjZcqtK0Y1Z4VQxkhIgidYPUkBrkUO5ielRA9+dnMAU/aPPxs2D?= =?utf-8?q?pXhM6z5fNP+4y4Q6UCZ23eM2S1GFh7/blmSlDY8zWUzNE4fZhGtLuHLApkvoHR+gL?= =?utf-8?q?cs0Az3EEK5smbb9omAzV9AUDOOTiwy7fEWAdl9NuQ86dcUBQrQwhjAX27RcOxWEb6?= =?utf-8?q?40OvXwy82tsw7B5IVDFC0FpisNtt5y+9Re0OPuGQ6AUQQtB8VeVYH9JJb+kkb4XjD?= =?utf-8?q?ubV5wBdCJz0/MCzuxKbTvIXmW80VVlStizkZJ9+/QaGI/1OD0T0pCHmB7QEiRsIry?= =?utf-8?q?C2PzN2gedPSmKEMIi9/1fM1JKVrSkw1VX/de0j9wH5Q/KM/W+nrLjC8xQvQulFYeF?= =?utf-8?q?wQ4SyXjc9ke0z+t38HPcBqP3fOyQSrCb+teAh4pKUN1uhYpQXxkeSEsbGcUBLt/0N?= =?utf-8?q?sgKEnopKzK78Tp3U44/B/jjDVlTFeuKvh9Kg/38nXnqs8G8zUurxaXnzgLjradsh5?= =?utf-8?q?6D/jBtHrPBg8YUtpGW49z8+EmBJyTdRoJK1G6RM3dV1HanFyUUtC8ApACjAo+S7E+?= =?utf-8?q?0HTNaxfMno/B/dgT2EgRmUd8Q4snvmklZowlnX1xPL5LaGg9p8ZjU5CIbKwnqopp0?= =?utf-8?q?4ggnG/qCYbgADu679m87mcj2BDPuRgLmsZk1nQ81lm+keJha5PIH3iBdEhXuGRNhB?= =?utf-8?q?ToNAPUuXKw4vJzMjTJpriCk4lufxnRNYgQgBeY286Li9PUxPf8+8urY5DNmG0EUE1?= =?utf-8?q?oLGmc1/QVl+8UgZjH3n9Db9wkKwxcmgA60/LJnftBDHKfoTH41sk/yQ6z4p7v1+MX?= =?utf-8?q?FWm/L8RUNLJToAc/CAWanmKuaDM/ug2Qbtnm3dvVwFt3xNyssYrTdL5FuNgMRIyhr?= =?utf-8?q?h5hNbamJFbBSIA8SF0RKd7gzLVdnFJ22FoZBLqmrDUUnONh+gdo8YmUGLZwSG9Mcs?= =?utf-8?q?X5bu6faSvwnoAGldlgsV2ijkE6UaG5xX26pspHEbqS/RjvnbnrdH8cjequvS9gyE5?= =?utf-8?q?GzhR4WZGs8gT8tTsFWgemHH2gEgM2Z8SFA=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)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 06:03:38.1761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8809ab8-8428-4f4b-7896-08dcfef1ec3d 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: CH2PEPF00000147.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7653 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. Tested-by: Mark Pearson Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Mario Limonciello --- drivers/acpi/platform_profile.c | 114 ++++++++++++-------------------- 1 file changed, 44 insertions(+), 70 deletions(-) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index 548eb99253958..0450bdae7c88b 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -27,25 +27,21 @@ 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 +52,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 +79,20 @@ 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"); - - mutex_unlock(&profile_lock); - if (err) - return err; + sysfs_notify(acpi_kobj, NULL, "platform_profile"); return count; } @@ -140,36 +123,27 @@ 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"); - - return err; + sysfs_notify(acpi_kobj, NULL, "platform_profile"); + return 0; } EXPORT_SYMBOL_GPL(platform_profile_cycle);