From patchwork Sat Nov 9 04:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 842753 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_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 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-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: 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?q?O21KDmQr4cvvLa7EZydhILFfpaOBJ3H?= =?utf-8?q?aMvZHYgELNoFgiErOzl+GQUQ6IkKru5m8Qz8L0bNGDuHx1QeTudhUUk0tdAlkPYxf?= =?utf-8?q?RvGH+7m2E0NXFHFLxKyzcaDtus6oR7uoewMKxaOJGoiwhqKwQRg6aTBmaHtgJLLwH?= =?utf-8?q?pLkxSmLqLDy8BNPrbMwBUzbq6bkW8Vze0/6/y0sHUSmSMWNvDfBM6LNKwuoKSXADR?= =?utf-8?q?4wZKVzIUpzxBnj/xU+X6whZ7yFaQelzeV79RxEEj9pgg5crlMBMbKSK0cISfVcQsm?= =?utf-8?q?9rMhq1BMpZNgpGq71ZcPNMnWCl6Afavht91y1F+BicSeacfzO+Q+iZ5qJrCOLZzQa?= =?utf-8?q?2JWk0qS661+k25kQ/QRtZmfZJGy6ah5D1muqA1VGLkwhkfONPyd7b5iFTgMgx7B0z?= =?utf-8?q?VDPNlvSeaDsFtbmROfJvwKT4NgveV9e4qSWxq93y9zmWjmMuSks/VGEfKumU7AJKv?= =?utf-8?q?5SAVjTyLnBcAfoWWdXkTBCfRdEqmoqbwo47/GFS3GfWI/85g48wxDmGgGRj5cjSkS?= =?utf-8?q?9J2xoTAptb9AR2aA/ukDTjF2/4h/ZKpyM6LEdj9KZ4g79uS55twtLI1yys+sUdUZ/?= =?utf-8?q?9CDbWao4JmZ473dhPzVjO8LWMNR0J7lTpFXjmoeQsjVCONLK4z0UnBtgKIMTsqZH0?= =?utf-8?q?jm0gUuI0zXtu2e6FRy1p//LGVMxs2U9noYLiBUxvySZEPpe/LhLNQJgsyNwVeHUD6?= =?utf-8?q?7TukhAt+dEaKkthewXYfIBU5Bq4bAGygD1YEW/RLehbkR8z1ba/YUGuQOerwl3EyR?= =?utf-8?q?s5rvwi8Q8RVyKXVx72mr5R57wWo335QnwhApCxLDcG7kTeqL26LsBz58vV1l0k1+r?= =?utf-8?q?9KPAiUmFq9BapS6PpyGad0W3myY/50kUHBegopzT32oPeTfaQFDISHOH7oCLx2hER?= =?utf-8?q?lySKybrB0SutpIdYR6WexgPOigtTDoDzPSnN6pd+cAqk6x11noAd4u3oRNb4iB8wn?= =?utf-8?q?zNr0O7FXZwNwq5w5FRKlLmmdO1xnDlHRg/NscoOZ7Y8r+sU69z6Ir2FpenLfA0h0n?= =?utf-8?q?0KelzykmIoGNMnjNmhK9AR4y/yBLUjZbalOWRVi+2qyE6mMmc1rc0NSGoaQAtpL5a?= =?utf-8?q?9t9+isVWBLLD6JxeAC0Amu2uq7mvLTHph+Qdt6c83bZQJvfWAaXs5GZi4Kay0++I2?= =?utf-8?q?hjsC8ub42VQO7/qgTy9xKV/JuWT/LcErPyHbL3pj3xRVmbSnoyNKOtWrO4jKTk7wq?= =?utf-8?q?C4bnJwoy9bOekpcEMMmdm47PQBc4pgYX3ufnUkh7ImFA15/KAsFpV6hZoHiYTErRS?= =?utf-8?q?meaf+FhyLLUEujSvCR4FRwFIxtZPvAXxvumRTZmkkZkNh6LV4ajQMyHPfNaiBOUgi?= =?utf-8?q?jEsZWa+t0bFZ3OqYEP+n5TCSV+Fp90JQew=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)(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ä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);