Skip to contentSkip to conversation

gpio: mockup: return -EFAULT if copy_from_user() fails

PATCH In review Dan Carpenter 3 participants 3 messages Feb 14, 2017 – Feb 23, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: mockup: return -EFAULT if copy_from_user() fails

copy_from_user() returns the number of bytes remaining to be copied but we want to return negative error codes on failue.

Fixes 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
drivers/gpio/gpio-mockup.c +3 -4
index 06dac72cb69c..d99338689213 100644
@@ -197,7 +197,7 @@ static ssize_t gpio_mockup_event_write(struct file *file,
 	struct seq_file *sfile;
 	struct gpio_desc *desc;
 	struct gpio_chip *gc;
-	int status, val;
+	int val;
 	char buf;
 
 	sfile = file->private_data;
@@ -206,9 +206,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
 	chip = priv->chip;
 	gc = &chip->gc;
 
-	status = copy_from_user(&buf, usr_buf, 1);
-	if (status)
-		return status;
+	if (copy_from_user(&buf, usr_buf, 1))
+		return -EFAULT;
 
 	if (buf = '0')
 		val = 0;
Acked-by on v1 1/1
#1 lore raw

2017-02-15 0:02 GMT+01:00 Dan Carpenter <[email protected]>:

Quoted 21 lines

copy_from_user() returns the number of bytes remaining to be copied but we want to return negative error codes on failue.

Fixes 9202ba2397d1 ("gpio: mockup: implement event injecting over debugfs")
drivers/gpio/gpio-mockup.c +1 -1
index 06dac72cb69c..d99338689213 100644
@@ -197,7 +197,7 @@ static ssize_t gpio_mockup_event_write(struct file *file,
        struct seq_file *sfile;
        struct gpio_desc *desc;
        struct gpio_chip *gc;
-       int status, val;
+       int val;
        char buf;
 
        sfile = file->private_data;
@@ -206,9 +206,8 @@ static ssize_t gpio_mockup_event_write(struct file *file,
        chip = priv->chip;

drivers/gpio/gpio-mockup.c static ssize_t gpio_mockup_event_write(struct file *file, · line 213

Quoted 10 lines
drivers/gpio/gpio-mockup.c +2 -3
        gc = &chip->gc;
 
-       status = copy_from_user(&buf, usr_buf, 1);
-       if (status)
-               return status;
+       if (copy_from_user(&buf, usr_buf, 1))
+               return -EFAULT;
 
        if (buf = '0')
                val = 0;

Oops my bad.