From nobody Sat Nov 23 23:30:00 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2083.outbound.protection.outlook.com [40.107.236.83]) (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 8270314A0B3; Sat, 9 Nov 2024 04:42:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731127359; cv=fail; b=OGpvk/Dkhxsp3wJuYt5zqJZ2j5ZyDx3JKNbxHwSSHFoEj/F33vbhHIDIbIfUZrCkIApxsCeKD+7N5gulSsPPqK8kYiKHNJVFrtY+en7JxH3i8/oipc6HFFHr8tDGRnQflIupXJIdnFWq9AFBKE5lJxMVhHBRb5cNl1F56hphVhc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731127359; c=relaxed/simple; bh=eR/kuOWvhZLZUdUk6IKGkBbP0bE5GeKHJI29oIiDKh4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ct5+rp4Jjk9Ao1RpYUxQeNvKE9xnMVIX4m2Novqe4p7j9qabWaE4IuOHUrSZQ7u/40mJkUBmIu0lRztY73ARmAWGzY8e2izg8ssEwB24Efwx0Z4rxp8RRsCe9/KVNhKdwLI1Fa6gHYlHsOYLHQDgZps0oHatHES+POTPse/AON4= 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=glxb5FWw; arc=fail smtp.client-ip=40.107.236.83 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="glxb5FWw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UJ+VEQEXf053cNlNoGJtAvGngmYgOusnrFuLfg+PdASwrH8gMtKUjTlvKIuqpWsEE2i6kf7V7ATFB8oO8BkpkDbQnlGUq8vh6Pw1/4hTkItNSzGauGLVHTbppmYGoAwLGKRghfRcED9f5fWun9Lu+cjQ5chcgcSyUh4tToIpbpIN6/vEa8bNViKdiU+hBDmz6aYGdzbFRZ35S5R/orHaBY+gY9j4BVEGQAIp7IcbUVHnh5RwvaHRYgvrFok/AuoKEfXNsd2zGh98BakqxsdL2KDgtNBjLx7luv++AVZaMFD+eaB1Q0OpDJfZFmSVLhpU/FWaTWLJ+mDNCQEgGbkYfg== 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=ZLQ/qcNQHbvVxO8H7Dy9mDWXqRfXGHQv2or+UNEXmN8=; b=K5mENcUVKgcfvXkr8sBIH2mZuFUs3dEamBfQmv4n4/3FQ5NxAprCKmO8hvxFpciMBX0xQlGwTNMCUx0A7/EsHGEIhIevM8z7PYQNip4Wlc7WDcK8NCficpQou6L9vtnqTS++NanBZy6iLMcVHtPQxKOeAKL+lzRaI6THNQuPL4u5P/ZxcN8eYfj4wUzFq6nYIPTUsMlQFtpVRyJ99awUv5P7q1EpPp2yWOom4ngUicuSBYaYQFh/Svtjc2AsYe/GlCLM26ReqZDnymxaetTpTWK1k/tjl+fJY1VdrT4VBIGi4HvCLqXLID6leMtSqJNRCNbzx91ukUdoeGwE1MLo9Q== 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=ZLQ/qcNQHbvVxO8H7Dy9mDWXqRfXGHQv2or+UNEXmN8=; b=glxb5FWwNDw9tUaEEe3P7h394JNT/F/LFCFKqXb6rC/Zb0m0kmq1fufy23sE4fauxaNeY3JfXln1EU8LV5lcO3NSrwT82hu3tO60adphaMihoyBznNYLFC3JrsP4Algw9hYoh0sIz+q2rYU2HbXhYStMd5RLuDc8aoa6Bt6XaVg= Received: from SN4PR0501CA0069.namprd05.prod.outlook.com (2603:10b6:803:41::46) by MN2PR12MB4335.namprd12.prod.outlook.com (2603:10b6:208:1d4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.22; Sat, 9 Nov 2024 04:42:32 +0000 Received: from SN1PEPF00026369.namprd02.prod.outlook.com (2603:10b6:803:41:cafe::63) by SN4PR0501CA0069.outlook.office365.com (2603:10b6:803:41::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.11 via Frontend Transport; Sat, 9 Nov 2024 04:42:32 +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 SN1PEPF00026369.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8137.17 via Frontend Transport; Sat, 9 Nov 2024 04:42:32 +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; Fri, 8 Nov 2024 22:42:30 -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 v6 09/22] ACPI: platform_profile: Use `scoped_cond_guard` Date: Fri, 8 Nov 2024 22:41:38 -0600 Message-ID: <20241109044151.29804-10-mario.limonciello@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241109044151.29804-1-mario.limonciello@amd.com> References: <20241109044151.29804-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: 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: SN1PEPF00026369:EE_|MN2PR12MB4335:EE_ X-MS-Office365-Filtering-Correlation-Id: d15dbcfc-e2c8-4129-30c8-08dd0078ecfb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?TzIxS0RtUXI0Y3Z2TGE3RVp5ZGhJTEZmcGFPQkozSGFNdlpIWWdFTE5vRmdp?= =?utf-8?B?RXJPemwrR1FVUTZJa0tydTVtOFF6OEwwYk5HRHVIeDFRZVR1ZGhVVWswdGRB?= =?utf-8?B?bGtQWXhmUnZHSCs3bTJFME5YRkhGTHhLeXpjYUR0dXM2b1I3dW9ld01LeGFP?= =?utf-8?B?SkdvaXdocUt3UVJnNmFUQm1hSHRnSkxMd0hwTGt4U21McUxEeThCTlByYk13?= =?utf-8?B?QlV6YnE2YmtXOFZ6ZTAvNi95MHNIVVNtU01XTnZEZkJNNkxOS3d1b0tTWEFE?= =?utf-8?B?UjR3WktWeklVcHp4Qm5qL3hVK1g2d2haN3lGYVFlbHplVjc5UnhFRWo5cGdn?= =?utf-8?B?NWNybE1CTWJLU0swY0lTZlZjUXNtOXJNaHExQk1wWk5ncEdxNzFaY1BOTW5X?= =?utf-8?B?Q2w2QWZhdmh0OTF5MUYrQmljU2VhY2Z6TytRK2laNXFKckNPTFp6UWEySldr?= =?utf-8?B?MHFTNjYxK2syNWtRL1FSdFptZlpKR3k2YWg1RDFtdXFBMVZHTGt3aGtmT05Q?= =?utf-8?B?eWQ3YjVpRlRnTWd4N0IwelZEUE5sdlNlYURzRnRibVJPZkp2d0tUNE5ndmVW?= =?utf-8?B?OWU0cVNXeHE5M3k5em1Xam1NdVNrcy9WR0VmS3VtVTdBSkt2NVNBVmpUeUxu?= =?utf-8?B?QmNBZm9XV2RYa1RCQ2ZSZEVxbW9xYndvNDcvR0ZTM0dmV0kvODVnNDh3eERt?= =?utf-8?B?R2dHUmo1Y2pTa1M5SjJ4b1RBcHRiOUFSMmFBL3VrRFRqRjIvNGgvWktweU02?= =?utf-8?B?TEVkajlLWjRnNzl1Uz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N3dxQzRibkp3b3k5Yk9la3BjRU1NbWRtNDdQUUJjNHBnWVgzdWZuVWto?= =?utf-8?B?N0ltRkExNS9LQXNGcFY2aFpvSGlZVEVyUlNtZWFmK0ZoeUxMVUV1alN2Q1I0?= =?utf-8?B?RlJ3Rkl4dFpQdkFYeHZ1bVJUWm1ra1prTmg2TFY0YWpRTXlIUGZOYWlCT1Vn?= =?utf-8?B?aWpFc1pXYSt0MGJGWjNPcVlFUCtuNVRDU1YrRnA5MEpRZXc9PQ==?= 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)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2024 04:42:32.7501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d15dbcfc-e2c8-4129-30c8-08dd0078ecfb 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: SN1PEPF00026369.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4335 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 Reviewed-by: Armin Wolf --- 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_profil= e.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 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 +51,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 +78,21 @@ 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"); + sysfs_notify(acpi_kobj, NULL, "platform_profile"); =20 - mutex_unlock(&profile_lock); - if (err) - return err; return count; } =20 @@ -140,36 +123,28 @@ 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"); + sysfs_notify(acpi_kobj, NULL, "platform_profile"); =20 - return err; + return 0; } EXPORT_SYMBOL_GPL(platform_profile_cycle); =20 --=20 2.43.0