linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zou Wei <zou_wei@huawei.com>
To: <davem@davemloft.net>
Cc: <linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Zou Wei <zou_wei@huawei.com>
Subject: [PATCH -next] ide: Use memdup_user() as a cleanup
Date: Wed, 22 Apr 2020 10:59:41 +0800	[thread overview]
Message-ID: <1587524381-120136-1-git-send-email-zou_wei@huawei.com> (raw)

Fix coccicheck warning which recommends to use memdup_user().

This patch fixes the following coccicheck warnings:

drivers/ide/ide-taskfile.c:492:11-18: WARNING opportunity for memdup_user
drivers/ide/ide-taskfile.c:505:10-17: WARNING opportunity for memdup_user

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/ide/ide-taskfile.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index aab6a10..336b575 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -489,28 +489,16 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
 
 	if (taskout) {
 		int outtotal = tasksize;
-		outbuf = kzalloc(taskout, GFP_KERNEL);
-		if (outbuf == NULL) {
-			err = -ENOMEM;
-			goto abort;
-		}
-		if (copy_from_user(outbuf, buf + outtotal, taskout)) {
-			err = -EFAULT;
-			goto abort;
-		}
+		outbuf = memdup_user(buf + outtotal, taskout);
+		if (IS_ERR(outbuf))
+			return PTR_ERR(outbuf);
 	}
 
 	if (taskin) {
 		int intotal = tasksize + taskout;
-		inbuf = kzalloc(taskin, GFP_KERNEL);
-		if (inbuf == NULL) {
-			err = -ENOMEM;
-			goto abort;
-		}
-		if (copy_from_user(inbuf, buf + intotal, taskin)) {
-			err = -EFAULT;
-			goto abort;
-		}
+		inbuf = memdup_user(buf + intotal, taskin);
+		if (IS_ERR(inbuf))
+			return PTR_ERR(inbuf);
 	}
 
 	memset(&cmd, 0, sizeof(cmd));
-- 
2.6.2


             reply	other threads:[~2020-04-22  2:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22  2:59 Zou Wei [this message]
2020-04-22  2:58 ` [PATCH -next] ide: Use memdup_user() as a cleanup Al Viro

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=1587524381-120136-1-git-send-email-zou_wei@huawei.com \
    --to=zou_wei@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@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).