lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241107060254.17615-15-mario.limonciello@amd.com>
Date: Thu, 7 Nov 2024 00:02:48 -0600
From: Mario Limonciello <mario.limonciello@....com>
To: Hans de Goede <hdegoede@...hat.com>, Ilpo Järvinen
	<ilpo.jarvinen@...ux.intel.com>
CC: "Rafael J . Wysocki" <rafael@...nel.org>, Len Brown <lenb@...nel.org>,
	Maximilian Luz <luzmaximilian@...il.com>, Lee Chun-Yi <jlee@...e.com>, "Shyam
 Sundar S K" <Shyam-sundar.S-k@....com>, Corentin Chary
	<corentin.chary@...il.com>, "Luke D . Jones" <luke@...nes.dev>, Ike Panhc
	<ike.pan@...onical.com>, Henrique de Moraes Holschuh <hmh@....eng.br>,
	"Alexis Belmonte" <alexbelm48@...il.com>, Uwe Kleine-König
	<u.kleine-koenig@...gutronix.de>, Ai Chao <aichao@...inos.cn>, Gergo Koteles
	<soyer@....hu>, open list <linux-kernel@...r.kernel.org>, "open list:ACPI"
	<linux-acpi@...r.kernel.org>, "open list:MICROSOFT SURFACE PLATFORM PROFILE
 DRIVER" <platform-driver-x86@...r.kernel.org>, "open list:THINKPAD ACPI
 EXTRAS DRIVER" <ibm-acpi-devel@...ts.sourceforge.net>, Mark Pearson
	<mpearson-lenovo@...ebb.ca>, Matthew Schwartz <matthew.schwartz@...ux.dev>,
	Mario Limonciello <mario.limonciello@....com>
Subject: [PATCH v5 14/20] ACPI: platform_profile: Only show profiles common for all handlers

If multiple platform profile handlers have been registered, don't allow
switching to profiles unique to only one handler.

Tested-by: Mark Pearson <mpearson-lenovo@...ebb.ca>
Tested-by: Matthew Schwartz <matthew.schwartz@...ux.dev>
Signed-off-by: Mario Limonciello <mario.limonciello@....com>
---
v5:
 * adjust mutex use
---
 drivers/acpi/platform_profile.c | 59 ++++++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index 510e1435d3980..2ae0437623abb 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -231,27 +231,56 @@ static const struct class platform_profile_class = {
 	.dev_groups = profile_groups,
 };
 
+/**
+ * _aggregate_choices - Aggregate the available profile choices
+ * @dev: The device
+ * @data: The available profile choices
+ * Return: 0 on success, -errno on failure
+ */
+static int _aggregate_choices(struct device *dev, void *data)
+{
+	unsigned long *aggregate = data;
+	unsigned long choices = 0;
+	int err;
+
+	err = _get_class_choices(dev, &choices);
+	if (err)
+		return err;
+
+	if (!*aggregate)
+		*aggregate = choices;
+	else
+		*aggregate &= choices;
+
+	return 0;
+}
+
+/**
+ * platform_profile_choices_show - Show the available profile choices for legacy sysfs interface
+ * @dev: The device
+ * @attr: The attribute
+ * @buf: The buffer to write to
+ * Return: The number of bytes written
+ */
 static ssize_t platform_profile_choices_show(struct device *dev,
-					struct device_attribute *attr,
-					char *buf)
+					     struct device_attribute *attr,
+					     char *buf)
 {
-	int len = 0;
-	int i;
+	unsigned long aggregate = 0;
+	int err;
 
 	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]);
-		}
+		err = class_for_each_device(&platform_profile_class, NULL,
+					    &aggregate, _aggregate_choices);
+		if (err)
+			return err;
 	}
-	len += sysfs_emit_at(buf, len, "\n");
 
-	return len;
+	/* no profile handler registered any more */
+	if (!aggregate)
+		return -EINVAL;
+
+	return _commmon_choices_show(aggregate, buf);
 }
 
 static ssize_t platform_profile_show(struct device *dev,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ