diff options
author | Markus Elfring <elfring@users.sourceforge.net> | 2016-08-19 02:50:23 -0400 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2016-08-23 12:38:24 -0400 |
commit | 48ef5865d08fa0a36d786f2f8e12c6194d27538b (patch) | |
tree | fcddba0d36ef7e6c8950a3e0f19052bb39a7fc29 | |
parent | 30b03b1528b60623986ee0b50ec0e5dab9094be8 (diff) |
IB/qib: Use memdup_user() rather than duplicating its implementation
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/infiniband/hw/qib/qib_fs.c | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c index fcdf37913a26..c3edc033f7c4 100644 --- a/drivers/infiniband/hw/qib/qib_fs.c +++ b/drivers/infiniband/hw/qib/qib_fs.c | |||
@@ -328,26 +328,12 @@ static ssize_t flash_write(struct file *file, const char __user *buf, | |||
328 | 328 | ||
329 | pos = *ppos; | 329 | pos = *ppos; |
330 | 330 | ||
331 | if (pos != 0) { | 331 | if (pos != 0 || count != sizeof(struct qib_flash)) |
332 | ret = -EINVAL; | 332 | return -EINVAL; |
333 | goto bail; | ||
334 | } | ||
335 | |||
336 | if (count != sizeof(struct qib_flash)) { | ||
337 | ret = -EINVAL; | ||
338 | goto bail; | ||
339 | } | ||
340 | |||
341 | tmp = kmalloc(count, GFP_KERNEL); | ||
342 | if (!tmp) { | ||
343 | ret = -ENOMEM; | ||
344 | goto bail; | ||
345 | } | ||
346 | 333 | ||
347 | if (copy_from_user(tmp, buf, count)) { | 334 | tmp = memdup_user(buf, count); |
348 | ret = -EFAULT; | 335 | if (IS_ERR(tmp)) |
349 | goto bail_tmp; | 336 | return PTR_ERR(tmp); |
350 | } | ||
351 | 337 | ||
352 | dd = private2dd(file); | 338 | dd = private2dd(file); |
353 | if (qib_eeprom_write(dd, pos, tmp, count)) { | 339 | if (qib_eeprom_write(dd, pos, tmp, count)) { |
@@ -361,8 +347,6 @@ static ssize_t flash_write(struct file *file, const char __user *buf, | |||
361 | 347 | ||
362 | bail_tmp: | 348 | bail_tmp: |
363 | kfree(tmp); | 349 | kfree(tmp); |
364 | |||
365 | bail: | ||
366 | return ret; | 350 | return ret; |
367 | } | 351 | } |
368 | 352 | ||