* [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user
@ 2014-05-30 17:07 Fabian Frederick
2014-06-02 14:53 ` One Thousand Gnomes
0 siblings, 1 reply; 2+ messages in thread
From: Fabian Frederick @ 2014-05-30 17:07 UTC (permalink / raw)
To: linux-kernel
Cc: Fabian Frederick, linux-scsi, Anil Gurumurthy,
James E.J. Bottomley
(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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user
2014-05-30 17:07 [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user Fabian Frederick
@ 2014-06-02 14:53 ` One Thousand Gnomes
0 siblings, 0 replies; 2+ messages in thread
From: One Thousand Gnomes @ 2014-06-02 14:53 UTC (permalink / raw)
To: Fabian Frederick
Cc: linux-kernel, linux-scsi, Anil Gurumurthy, James E.J. Bottomley
On Fri, 30 May 2014 19:07:36 +0200
Fabian Frederick <fabf@skynet.be> wrote:
> (memdup_user can be used to replace kmalloc/copy_from_user. Not sure if it's ok with kzalloc ...)
> + kern_buf = memdup_user((void __user *)buf, nbytes);
> + if (IS_ERR(kern_buf)) {
> + printk(KERN_INFO "bfad[%d]: Failed to copy buffer\n",
> + bfad->inst_no);
While you are tidying up lose the printk KERN_INFO stuff here, it really
isn't needed.
Looks good to me and it also fixes the incorrect return of -ENOMEM the
old code had on a copy_from_user failing.
Alan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-02 14:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-30 17:07 [RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user Fabian Frederick
2014-06-02 14:53 ` One Thousand Gnomes
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).