diff mbox

drm/debugfs: accept trailing whitespace in "force" attribute

Message ID 20170816153930.15623-1-m.tretter@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Tretter Aug. 16, 2017, 3:39 p.m. UTC
Using plain echo to set the "force" connector attribute fails with
-EINVAL, because echo appends a newline to the output.

Strip trailing whitespace in the input before checking the value to
accept "off\n" or "off  ".

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/gpu/drm/drm_debugfs.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jani Nikula Aug. 17, 2017, 9:59 a.m. UTC | #1
On Wed, 16 Aug 2017, Michael Tretter <m.tretter@pengutronix.de> wrote:
> Using plain echo to set the "force" connector attribute fails with
> -EINVAL, because echo appends a newline to the output.
>
> Strip trailing whitespace in the input before checking the value to
> accept "off\n" or "off  ".

Please replace the strcmp() calls with sysfs_streq() instead.

BR,
Jani.

>
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
>  drivers/gpu/drm/drm_debugfs.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index c1807d5754b2..10dd89d3f28e 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -241,6 +241,7 @@ static ssize_t connector_write(struct file *file, const char __user *ubuf,
>  	struct seq_file *m = file->private_data;
>  	struct drm_connector *connector = m->private;
>  	char buf[12];
> +	int i;
>  
>  	if (len > sizeof(buf) - 1)
>  		return -EINVAL;
> @@ -250,6 +251,10 @@ static ssize_t connector_write(struct file *file, const char __user *ubuf,
>  
>  	buf[len] = '\0';
>  
> +	/* strip trailing whitespace */
> +	for (i = len - 1; i > 0 && isspace(buf[i]); i--)
> +		buf[i] = '\0';
> +
>  	if (!strcmp(buf, "on"))
>  		connector->force = DRM_FORCE_ON;
>  	else if (!strcmp(buf, "digital"))
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index c1807d5754b2..10dd89d3f28e 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -241,6 +241,7 @@  static ssize_t connector_write(struct file *file, const char __user *ubuf,
 	struct seq_file *m = file->private_data;
 	struct drm_connector *connector = m->private;
 	char buf[12];
+	int i;
 
 	if (len > sizeof(buf) - 1)
 		return -EINVAL;
@@ -250,6 +251,10 @@  static ssize_t connector_write(struct file *file, const char __user *ubuf,
 
 	buf[len] = '\0';
 
+	/* strip trailing whitespace */
+	for (i = len - 1; i > 0 && isspace(buf[i]); i--)
+		buf[i] = '\0';
+
 	if (!strcmp(buf, "on"))
 		connector->force = DRM_FORCE_ON;
 	else if (!strcmp(buf, "digital"))