Skip to contentSkip to conversation

coda: switch to vmemdup_user()

PATCH New Yang Li 1 participant 1 message Mar 2, 2021 Coda file system

lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 coda: switch to vmemdup_user()

Replace opencoded alloc and copy with vmemdup_user()

fixed the following coccicheck:
./fs/coda/psdev.c:125:10-18: WARNING opportunity for vmemdup_user

---
 fs/coda/psdev.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
fs/coda/psdev.c +3 -8
index 240669f..8d38e92 100644
@@ -122,14 +122,9 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
 				hdr.opcode, hdr.unique);
 		        nbytes = size;
 		}
-		dcbuf = kvmalloc(nbytes, GFP_KERNEL);
-		if (!dcbuf) {
-			retval = -ENOMEM;
-			goto out;
-		}
-		if (copy_from_user(dcbuf, buf, nbytes)) {
-			kvfree(dcbuf);
-			retval = -EFAULT;
+		dcbuf = vmemdup_user(buf, nbytes)
+		if (IS_ERR(dcbuf)) {
+			r = PTR_ERR(dcbuf);
 			goto out;
 		}
 
Signature · 1 line
1.8.3.1