From: Brett Creeley <bcreeley@amd.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
Brett Creeley <brett.creeley@amd.com>,
Dave Jiang <dave.jiang@intel.com>, Jason Gunthorpe <jgg@ziepe.ca>,
Saeed Mahameed <saeedm@nvidia.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pds_fwctl: Replace kzalloc + copy_from_user with memdup_user in pdsfc_fw_rpc
Date: Wed, 17 Sep 2025 08:46:14 -0700 [thread overview]
Message-ID: <fdf330e2-c47d-480f-8a8f-09e73d454d83@amd.com> (raw)
In-Reply-To: <20250917150941.168887-1-thorsten.blum@linux.dev>
On 9/17/2025 8:09 AM, Thorsten Blum wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
>
>
> 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.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> drivers/fwctl/pds/main.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
Thanks for the patch.
Tested-by: Brett Creeley <brett.creeley@amd.com>
>
> diff --git a/drivers/fwctl/pds/main.c b/drivers/fwctl/pds/main.c
> index 9b9d1f6b5556..04d84f892fb8 100644
> --- a/drivers/fwctl/pds/main.c
> +++ b/drivers/fwctl/pds/main.c
> @@ -6,6 +6,7 @@
> #include <linux/pci.h>
> #include <linux/vmalloc.h>
> #include <linux/bitfield.h>
> +#include <linux/string.h>
>
> #include <uapi/fwctl/fwctl.h>
> #include <uapi/fwctl/pds.h>
> @@ -366,18 +367,10 @@ static void *pdsfc_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
> return ERR_PTR(err);
>
> if (rpc->in.len > 0) {
> - in_payload = kzalloc(rpc->in.len, GFP_KERNEL);
> - if (!in_payload) {
> - dev_err(dev, "Failed to allocate in_payload\n");
> - err = -ENOMEM;
> - goto err_out;
> - }
> -
> - if (copy_from_user(in_payload, u64_to_user_ptr(rpc->in.payload),
> - rpc->in.len)) {
> + in_payload = memdup_user(u64_to_user_ptr(rpc->in.payload), rpc->in.len);
> + if (IS_ERR(in_payload)) {
> dev_dbg(dev, "Failed to copy in_payload from user\n");
> - err = -EFAULT;
> - goto err_in_payload;
> + return in_payload;
> }
>
> 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,
> rpc->in.len, DMA_TO_DEVICE);
> err_in_payload:
> kfree(in_payload);
> -err_out:
> if (err)
> return ERR_PTR(err);
>
> --
> 2.51.0
>
next prev parent reply other threads:[~2025-09-17 15:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 15:09 [PATCH] pds_fwctl: Replace kzalloc + copy_from_user with memdup_user in pdsfc_fw_rpc Thorsten Blum
2025-09-17 15:12 ` Jason Gunthorpe
2025-09-17 15:22 ` Dave Jiang
2025-09-17 15:46 ` Brett Creeley [this message]
2025-09-22 13:33 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fdf330e2-c47d-480f-8a8f-09e73d454d83@amd.com \
--to=bcreeley@amd.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=brett.creeley@amd.com \
--cc=dave.jiang@intel.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=saeedm@nvidia.com \
--cc=thorsten.blum@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.