Skip to contentSkip to conversation

tty/vt/keyboard: use memdup_user to simplify code

PATCH In review Saurabh Sengar 1 participant 2 messages Oct 28, 2015 – Nov 19, 2015 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty/vt/keyboard: use memdup_user to simplify code

use memdup_user rather than duplicating implementation. found by coccinelle

---
 drivers/tty/vt/keyboard.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/tty/vt/keyboard.c +5 -9
index 6f0336f..f973bfc 100644
@@ -1706,16 +1706,12 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
 			return -EINVAL;
 
 		if (ct) {
-			dia = kmalloc(sizeof(struct kbdiacr) * ct,
-								GFP_KERNEL);
-			if (!dia)
-				return -ENOMEM;
 
-			if (copy_from_user(dia, a->kbdiacr,
-					sizeof(struct kbdiacr) * ct)) {
-				kfree(dia);
-				return -EFAULT;
-			}
+			dia = memdup_user(a->kbdiacr,
+					sizeof(struct kbdiacr) * ct);
+			if (IS_ERR(dia))
+				return PTR_ERR(dia);
+
 		}
 
 		spin_lock_irqsave(&kbd_event_lock, flags);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 35 lines · Saurabh Sengar

use memdup_user rather than duplicating implementation. found by coccinelle

---
 drivers/tty/vt/keyboard.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/tty/vt/keyboard.c +5 -10
index 6f0336f..f973bfc 100644
@@ -1706,16 +1706,12 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm)
                        return -EINVAL;
 
                if (ct) {
-                       dia = kmalloc(sizeof(struct kbdiacr) * ct,
-                                                               GFP_KERNEL);
-                       if (!dia)
-                               return -ENOMEM;
 
-                       if (copy_from_user(dia, a->kbdiacr,
-                                       sizeof(struct kbdiacr) * ct)) {
-                               kfree(dia);
-                               return -EFAULT;
-                       }
+                       dia = memdup_user(a->kbdiacr,
+                                       sizeof(struct kbdiacr) * ct);
+                       if (IS_ERR(dia))
+                               return PTR_ERR(dia);
+
                }
 
                spin_lock_irqsave(&kbd_event_lock, flags);
--
Quoted 2 lines

1.9.1

Hi,

Is this patch rejected for some reason or is still in queue?