From: Thorsten Blum <thorsten.blum@linux.dev>
To: Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: bfa: Replace kzalloc + copy_from_user with memdup_user
Date: Thu, 18 Sep 2025 16:40:32 +0200 [thread overview]
Message-ID: <20250918144031.175148-2-thorsten.blum@linux.dev> (raw)
Replace kzalloc() followed by copy_from_user() with memdup_user() to
improve and simplify bfad_im_bsg_els_ct_request(). memdup_user() returns
either -ENOMEM or -EFAULT (instead of -EIO) if an error occurs.
Use u64_to_user_ptr() instead of manually casting 'bsg_data->payload'.
No functional changes intended other than returning the more idiomatic
error code -EFAULT.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/scsi/bfa/bfad_bsg.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 54bd11e6d593..d90dfee95160 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3392,21 +3392,10 @@ bfad_im_bsg_els_ct_request(struct bsg_job *job)
if (bsg_data == NULL)
goto out;
- /*
- * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
- * buffer of size bsg_data->payload_len
- */
- bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL);
- if (!bsg_fcpt) {
- rc = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user((uint8_t *)bsg_fcpt,
- (void *)(unsigned long)bsg_data->payload,
- bsg_data->payload_len)) {
- kfree(bsg_fcpt);
- rc = -EIO;
+ bsg_fcpt = memdup_user(u64_to_user_ptr(bsg_data->payload),
+ bsg_data->payload_len);
+ if (IS_ERR(bsg_fcpt)) {
+ rc = PTR_ERR(bsg_fcpt);
goto out;
}
--
2.51.0
next reply other threads:[~2025-09-18 14:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 14:40 Thorsten Blum [this message]
2025-09-25 2:10 ` Martin K. Petersen
2025-09-25 18:13 ` Thorsten Blum
2025-09-29 20:49 ` Martin K. Petersen
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=20250918144031.175148-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=James.Bottomley@HansenPartnership.com \
--cc=anil.gurumurthy@qlogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sudarsana.kalluru@qlogic.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®