[2/2] drm/i915/params: support bool values for int and uint params
diff mbox series

Message ID c945ac7b08e0eb0827cf647609885f4abdb84f1d.1575560168.git.jani.nikula@intel.com
State New
Headers show
Series
  • drm/i915: debugfs device parameters
Related show

Commit Message

Jani Nikula Dec. 5, 2019, 3:43 p.m. UTC
It's not uncommon for us to switch param types between bools and ints,
often having otherwise bool semantics but -1 value for platform
default. Allow bool values (such as YyNn) for ints.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs_params.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Chris Wilson Jan. 15, 2020, 10:05 a.m. UTC | #1
Quoting Jani Nikula (2019-12-05 15:43:41)
> It's not uncommon for us to switch param types between bools and ints,
> often having otherwise bool semantics but -1 value for platform
> default. Allow bool values (such as YyNn) for ints.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

But play nice with checkpatch, no point fighting with it over a line of
whitespace.
-Chris

Patch
diff mbox series

diff --git a/drivers/gpu/drm/i915/i915_debugfs_params.c b/drivers/gpu/drm/i915/i915_debugfs_params.c
index 7f1af5a35ca1..9acb755714cf 100644
--- a/drivers/gpu/drm/i915/i915_debugfs_params.c
+++ b/drivers/gpu/drm/i915/i915_debugfs_params.c
@@ -32,6 +32,13 @@  static ssize_t i915_param_int_write(struct file *file,
 	int ret;
 
 	ret = kstrtoint_from_user(ubuf, len, 0, value);
+	if (ret) {
+		/* support boolean values too */
+		bool b;
+		ret = kstrtobool_from_user(ubuf, len, &b);
+		if (!ret)
+			*value = b;
+	}
 
 	return ret ?: len;
 }
@@ -77,6 +84,13 @@  static ssize_t i915_param_uint_write(struct file *file,
 	int ret;
 
 	ret = kstrtouint_from_user(ubuf, len, 0, value);
+	if (ret) {
+		/* support boolean values too */
+		bool b;
+		ret = kstrtobool_from_user(ubuf, len, &b);
+		if (!ret)
+			*value = b;
+	}
 
 	return ret ?: len;
 }