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 | /* cut off if it is too long */ | 247 | /* cut off if it is too long */ |
| 248 | if (count > KSYM_NAME_LEN) | 248 | if (count > KSYM_NAME_LEN) |
| 249 | count = KSYM_NAME_LEN; | 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)) { | 251 | buf = memdup_user_nul(buffer, count); |
| 255 | ret = -EFAULT; | 252 | if (IS_ERR(buf)) |
| 256 | goto out_free; | 253 | return PTR_ERR(buf); |
| 257 | } | 254 | |
| 258 | buf[count] = '\0'; | ||
| 259 | sym = strstrip(buf); | 255 | sym = strstrip(buf); |
| 260 | 256 | ||
| 261 | mutex_lock(&fei_lock); | 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 | out: | 305 | out: |
| 310 | mutex_unlock(&fei_lock); | 306 | mutex_unlock(&fei_lock); |
| 311 | out_free: | ||
| 312 | kfree(buf); | 307 | kfree(buf); |
| 313 | return ret; | 308 | return ret; |
| 314 | } | 309 | } |