Use memdup_user_nul() helper instead of open-coding to simplify the code.
Showing the changes to kernel/fail_function.c (1 of 1 file). Show all
Unified · Split
| @@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer, · 246 unmodified lines | ||
| 247 | 247 | /* cut off if it is too long */ |
| 248 | 248 | if (count > KSYM_NAME_LEN) |
| 249 | 249 | count = KSYM_NAME_LEN; |
| 250 | − buf = kmalloc(count + 1, GFP_KERNEL); | |
| 251 | − if (!buf) | |
| 252 | − return -ENOMEM; | |
| 253 | 250 | |
| 254 | − if (copy_from_user(buf, buffer, count)) { | |
| 255 | − ret = -EFAULT; | |
| 256 | − goto out_free; | |
| 257 | − } | |
| 258 | − buf[count] = '\0'; | |
| 251 | + buf = memdup_user_nul(buffer, count); | |
| 252 | + if (IS_ERR(buf)) | |
| 253 | + return PTR_ERR(buf); | |
| 254 | + | |
| 259 | 255 | sym = strstrip(buf); |
| 260 | 256 | |
| 261 | 257 | mutex_lock(&fei_lock); |
| @@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer, · 46 unmodified lines | ||
| 308 | 304 | } |
| 309 | 305 | out: |
| 310 | 306 | mutex_unlock(&fei_lock); |
| 311 | −out_free: | |
| 312 | 307 | kfree(buf); |
| 313 | 308 | return ret; |
| 314 | 309 | } |