All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: virtualization@lists.linux.dev, kvm@vger.kernel.org,
	netdev@vger.kernel.org, "Eugenio Pérez" <eperezma@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Tiwei Bie" <tiwei.bie@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
Date: Wed, 25 Sep 2024 20:48:16 +0200	[thread overview]
Message-ID: <79b2f48a-f6a1-4bfc-9a8d-cb09777f2a07@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 25 Sep 2024 20:36:35 +0200

Assign the return value from a copy_to_user() call to an additional
local variable so that a kvfree() call and return statement can be
omitted accordingly.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/vhost/vdpa.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 5a49b5a6d496..ca69527a822c 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -370,13 +370,11 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v,

 	vdpa_get_config(vdpa, config.off, buf, config.len);

-	if (copy_to_user(c->buf, buf, config.len)) {
+	{
+		unsigned long ctu = copy_to_user(c->buf, buf, config.len);
 		kvfree(buf);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-
-	kvfree(buf);
-	return 0;
 }

 static long vhost_vdpa_set_config(struct vhost_vdpa *v,
--
2.46.1


             reply	other threads:[~2024-09-25 18:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 18:48 Markus Elfring [this message]
2024-09-25 20:50 ` [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config() Al Viro
2024-09-26  6:04   ` Markus Elfring

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=79b2f48a-f6a1-4bfc-9a8d-cb09777f2a07@web.de \
    --to=markus.elfring@web.de \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=tiwei.bie@intel.com \
    --cc=virtualization@lists.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.