From nobody Sun Nov 24 06:34:30 2024 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=20J=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=20Kleine-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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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?B?UEtXQ0IraEFGZWpHK3ZYT2s0bmRqREY4M1d5UE5pS1FNcW5BamdMSjd5VXE4?= =?utf-8?B?OXJnVkkvMHNxblB0UThrOXUxYW0rUlNSMkNPMitZZkRZaldPbmZWek5jUGZK?= =?utf-8?B?bjNFOVpuNWdiK3IwMVBsR2x3WGlvV0QzTzJac3lkYURFN2V2elpIVE1HMmps?= =?utf-8?B?Y0YrcERoOXQzZHJDN0srVDlhRjI1Yy9DOU5xekFJenBhd1IvZ3FsVzdJaXMw?= =?utf-8?B?TVNVMWFYa0VRa0dGYTZxK0JhdTRQV2dhaUdvUkNHaGZRSjZHdTFwK1YySWlP?= =?utf-8?B?bzk2dGM3LzNOYkRtcVloUGtEVFNFVVNCdUs4aC94dlNCbFV6VnloZnJBRGZX?= =?utf-8?B?anlJTVpkTlVVVkFkQm4wQ3c1RVZlNWpzZUJsR1F2NDArN3hzQTM4RE5pcHAx?= =?utf-8?B?WDE4cGZEcTd5RkpocmVQdXhEbkJsSC9PUUZYRWdFYWVJdmpXcDYxcDc2UnhB?= =?utf-8?B?TjljQTZrRG5ZZExqWmNxdEswWTFaNFZReGtoSWdpZFlQVWtCcmtVTzVpZWxS?= =?utf-8?B?QTkrZG5NQVUvYVBQeHMyRHBYaE02ejVmTlArNHk0UTZVQ1oyM2VNMlMxR0Zo?= =?utf-8?B?Ny9ibG1TbERZOHpXVXpORTRmWmhHdEx1SExBcGt2b0hSK2dMY3MwQXozRUVL?= =?utf-8?B?NXNtYmI5b21BelY5QVVET09UaXd5N2ZFV0FkbDlOdVE4NmRjVUJRclF3aGpB?= =?utf-8?B?WDI3UmNPeFdFYjY0ME92WHd5ODJ0c3c3QjVJVkRGQzBGcGlzTnR0NXkrOVJl?= =?utf-8?B?ME9QdUdRNkFVUVF0QjhWZVZZSDlKSm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yaDVoTmJhbUpGYkJTSUE4U0YwUktkN2d6TFZkbkZKMjJGb1pCTHFt?= =?utf-8?B?ckRVVW5PTmgrZ2RvOFltVUdMWndTRzlNY3NYNWJ1NmZhU3Z3bm9BR2xkbGdz?= =?utf-8?B?VjJpamtFNlVhRzV4WDI2cHNwSEVicVMvUmp2bmJucmRIOGNqZXF1dlM5Z3lF?= =?utf-8?B?NUd6aFI0V1pHczhnVDh0VHNGV2dlbUhIMmdFZ00yWjhTRkE9PQ==?= 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=C3=A4rvinen 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_profil= e.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 dev= ice *dev, char *buf) { int len =3D 0; - int err, i; - - err =3D 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 =3D=3D 0) - len +=3D sysfs_emit_at(buf, len, "%s", profile_names[i]); - else - len +=3D 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 =3D=3D 0) + len +=3D sysfs_emit_at(buf, len, "%s", profile_names[i]); + else + len +=3D sysfs_emit_at(buf, len, " %s", profile_names[i]); + } } len +=3D sysfs_emit_at(buf, len, "\n"); - mutex_unlock(&profile_lock); + return len; } =20 @@ -56,20 +52,15 @@ static ssize_t platform_profile_show(struct device *dev, enum platform_profile_option profile =3D PLATFORM_PROFILE_BALANCED; int err; =20 - err =3D mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; =20 - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; + err =3D cur_profile->profile_get(cur_profile, &profile); + if (err) + return err; } =20 - err =3D 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 >=3D ARRAY_SIZE(profile_names)))) return -EIO; @@ -88,28 +79,20 @@ static ssize_t platform_profile_store(struct device *de= v, if (i < 0) return -EINVAL; =20 - err =3D mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; =20 - 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; =20 - /* Check that platform supports this profile choice */ - if (!test_bit(i, cur_profile->choices)) { - mutex_unlock(&profile_lock); - return -EOPNOTSUPP; + err =3D cur_profile->profile_set(cur_profile, i); + if (err) + return err; } =20 - err =3D 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; } =20 @@ -140,36 +123,27 @@ int platform_profile_cycle(void) enum platform_profile_option next; int err; =20 - err =3D mutex_lock_interruptible(&profile_lock); - if (err) - return err; + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + if (!cur_profile) + return -ENODEV; =20 - if (!cur_profile) { - mutex_unlock(&profile_lock); - return -ENODEV; - } + err =3D cur_profile->profile_get(cur_profile, &profile); + if (err) + return err; =20 - err =3D cur_profile->profile_get(cur_profile, &profile); - if (err) { - mutex_unlock(&profile_lock); - return err; - } + next =3D find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST, + profile + 1); =20 - next =3D find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST, - profile + 1); + if (WARN_ON(next =3D=3D PLATFORM_PROFILE_LAST)) + return -EINVAL; =20 - if (WARN_ON(next =3D=3D PLATFORM_PROFILE_LAST)) { - mutex_unlock(&profile_lock); - return -EINVAL; + err =3D cur_profile->profile_set(cur_profile, next); + if (err) + return err; } =20 - err =3D 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); =20 --=20 2.43.0