From: Fabian Frederick <fabf@skynet.be>
To: linux-kernel@vger.kernel.org
Cc: Fabian Frederick <fabf@skynet.be>,
linux-scsi@vger.kernel.org,
Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
"James E.J. Bottomley" <JBottomley@parallels.com>
Subject: [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user
Date: Fri, 30 May 2014 19:07:36 +0200 [thread overview]
Message-ID: <1401469656-10332-1-git-send-email-fabf@skynet.be> (raw)
(memdup_user can be used to replace kmalloc/copy_from_user. Not sure if it's ok with kzalloc ...)
Cc: linux-scsi@vger.kernel.org
Cc: Anil Gurumurthy <anil.gurumurthy@qlogic.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
drivers/scsi/bfa/bfad_debugfs.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index 8e83d04..07b9e36 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -260,17 +260,12 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
unsigned long flags;
void *kern_buf;
- kern_buf = kzalloc(nbytes, GFP_KERNEL);
+ kern_buf = memdup_user((void __user *)buf, nbytes);
- if (!kern_buf) {
- printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
- bfad->inst_no);
- return -ENOMEM;
- }
-
- if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
- kfree(kern_buf);
- return -ENOMEM;
+ if (IS_ERR(kern_buf)) {
+ printk(KERN_INFO "bfad[%d]: Failed to copy buffer\n",
+ bfad->inst_no);
+ return PTR_ERR(kern_buf);
}
rc = sscanf(kern_buf, "%x:%x", &addr, &len);
@@ -336,17 +331,12 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
unsigned long flags;
void *kern_buf;
- kern_buf = kzalloc(nbytes, GFP_KERNEL);
+ kern_buf = memdup_user((void __user *)buf, nbytes);
- if (!kern_buf) {
- printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
- bfad->inst_no);
- return -ENOMEM;
- }
-
- if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
- kfree(kern_buf);
- return -ENOMEM;
+ if (IS_ERR(kern_buf)) {
+ printk(KERN_INFO "bfad[%d]: Failed to copy buffer\n",
+ bfad->inst_no);
+ return PTR_ERR(kern_buf);
}
rc = sscanf(kern_buf, "%x:%x", &addr, &val);
--
1.8.4.5
next reply other threads:[~2014-05-30 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-30 17:07 Fabian Frederick [this message]
2014-06-02 14:53 ` [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user One Thousand Gnomes
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=1401469656-10332-1-git-send-email-fabf@skynet.be \
--to=fabf@skynet.be \
--cc=JBottomley@parallels.com \
--cc=anil.gurumurthy@qlogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).