Skip to content

Commit 479bec4

Browse files
tobluxjgunthorpe
authored andcommitted
pds_fwctl: Replace kzalloc + copy_from_user with memdup_user in pdsfc_fw_rpc
Replace kzalloc() followed by copy_from_user() with memdup_user() to improve and simplify pdsfc_fw_rpc(). Return early if an error occurs and remove the obsolete 'err_out' label. No functional changes intended. Link: https://patch.msgid.link/r/[email protected] Signed-off-by: Thorsten Blum <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Brett Creeley <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e7085be commit 479bec4

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

drivers/fwctl/pds/main.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/pci.h>
77
#include <linux/vmalloc.h>
88
#include <linux/bitfield.h>
9+
#include <linux/string.h>
910

1011
#include <uapi/fwctl/fwctl.h>
1112
#include <uapi/fwctl/pds.h>
@@ -366,18 +367,10 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
366367
return ERR_PTR(err);
367368

368369
if (rpc->in.len > 0) {
369-
in_payload = kzalloc(rpc->in.len, GFP_KERNEL);
370-
if (!in_payload) {
371-
dev_err(dev, "Failed to allocate in_payload\n");
372-
err = -ENOMEM;
373-
goto err_out;
374-
}
375-
376-
if (copy_from_user(in_payload, u64_to_user_ptr(rpc->in.payload),
377-
rpc->in.len)) {
370+
in_payload = memdup_user(u64_to_user_ptr(rpc->in.payload), rpc->in.len);
371+
if (IS_ERR(in_payload)) {
378372
dev_dbg(dev, "Failed to copy in_payload from user\n");
379-
err = -EFAULT;
380-
goto err_in_payload;
373+
return in_payload;
381374
}
382375

383376
in_payload_dma_addr = dma_map_single(dev->parent, in_payload,
@@ -453,7 +446,6 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
453446
rpc->in.len, DMA_TO_DEVICE);
454447
err_in_payload:
455448
kfree(in_payload);
456-
err_out:
457449
if (err)
458450
return ERR_PTR(err);
459451

0 commit comments

Comments
 (0)