Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20250917150941.168887-1-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Thorsten Blum and committed by
Jason Gunthorpe
479bec4c e7085be8

+4 -12
+4 -12
drivers/fwctl/pds/main.c
··· 6 6 #include <linux/pci.h> 7 7 #include <linux/vmalloc.h> 8 8 #include <linux/bitfield.h> 9 + #include <linux/string.h> 9 10 10 11 #include <uapi/fwctl/fwctl.h> 11 12 #include <uapi/fwctl/pds.h> ··· 367 366 return ERR_PTR(err); 368 367 369 368 if (rpc->in.len > 0) { 370 - in_payload = kzalloc(rpc->in.len, GFP_KERNEL); 371 - if (!in_payload) { 372 - dev_err(dev, "Failed to allocate in_payload\n"); 373 - err = -ENOMEM; 374 - goto err_out; 375 - } 376 - 377 - if (copy_from_user(in_payload, u64_to_user_ptr(rpc->in.payload), 378 - rpc->in.len)) { 369 + in_payload = memdup_user(u64_to_user_ptr(rpc->in.payload), rpc->in.len); 370 + if (IS_ERR(in_payload)) { 379 371 dev_dbg(dev, "Failed to copy in_payload from user\n"); 380 - err = -EFAULT; 381 - goto err_in_payload; 372 + return in_payload; 382 373 } 383 374 384 375 in_payload_dma_addr = dma_map_single(dev->parent, in_payload, ··· 446 453 rpc->in.len, DMA_TO_DEVICE); 447 454 err_in_payload: 448 455 kfree(in_payload); 449 - err_out: 450 456 if (err) 451 457 return ERR_PTR(err); 452 458