aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Limonciello <mario.limonciello@amd.com>2024-12-05 21:19:11 -0600
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>2024-12-10 19:18:10 +0200
commit06ec24388f1de63a5d9b0dc1994bc2180d7ff6b8 (patch)
tree445b46ef1ff0801a8f8944a80b62ef90af90a93c
parentACPI: platform_profile: Notify change events on register and unregister (diff)
downloadlinux-rng-06ec24388f1de63a5d9b0dc1994bc2180d7ff6b8.tar.xz
linux-rng-06ec24388f1de63a5d9b0dc1994bc2180d7ff6b8.zip
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. Reviewed-by: Armin Wolf <W_Armin@gmx.de> Tested-by: Mark Pearson <mpearson-lenovo@squebb.ca> Tested-by: Matthew Schwartz <matthew.schwartz@linux.dev> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Link: https://lore.kernel.org/r/20241206031918.1537-16-mario.limonciello@amd.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
-rw-r--r--drivers/acpi/platform_profile.c54
1 files changed, 44 insertions, 10 deletions
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index 2a4f067c3c5c..bdf69255ed9c 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -198,22 +198,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)
+{
+ struct platform_profile_handler *handler;
+ unsigned long *aggregate = data;
+
+ lockdep_assert_held(&profile_lock);
+ handler = dev_get_drvdata(dev);
+ if (test_bit(PLATFORM_PROFILE_LAST, aggregate))
+ bitmap_copy(aggregate, handler->choices, PLATFORM_PROFILE_LAST);
+ else
+ bitmap_and(aggregate, handler->choices, aggregate, PLATFORM_PROFILE_LAST);
+
+ 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[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
+ int err;
+ set_bit(PLATFORM_PROFILE_LAST, aggregate);
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)
- len += sysfs_emit_at(buf, len, len ? " %s": "%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 (bitmap_empty(aggregate, PLATFORM_PROFILE_LAST))
+ return -EINVAL;
+
+ return _commmon_choices_show(aggregate, buf);
}
static ssize_t platform_profile_show(struct device *dev,