Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1467778

[PATCH v2] IB/core: Use memdup_user() rather than duplicating its implementation

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH v2] IB/core: Use memdup_user() rather than duplicating its implementation
Date 2016-08-22 18:40 +0200
Message-ID <s90qt-ft-7@gated-at.bofh.it> (permalink)
References (2 earlier) <s8Fm1-3If-1@gated-at.bofh.it> <s8H4u-4F3-9@gated-at.bofh.it> <s8H4u-4F3-7@gated-at.bofh.it> <s8HnQ-510-3@gated-at.bofh.it> <s8U1I-4zE-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 22 Aug 2016 18:23:24 +0200

* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

  This issue was detected by using the Coccinelle software.

* The local variable "ret" will be set to an appropriate value a bit later.
  Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

v2: The desired changes were put into a single patch instead of
    distributing them over two update steps.

 include/rdma/ib_verbs.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 6f667dd..0d8100f 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -2199,22 +2199,17 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata,
 				       size_t len)
 {
 	const void __user *p = udata->inbuf + offset;
-	bool ret = false;
+	bool ret;
 	u8 *buf;
 
 	if (len > USHRT_MAX)
 		return false;
 
-	buf = kmalloc(len, GFP_KERNEL);
-	if (!buf)
+	buf = memdup_user(p, len);
+	if (IS_ERR(buf))
 		return false;
 
-	if (copy_from_user(buf, p, len))
-		goto free;
-
 	ret = !memchr_inv(buf, 0, len);
-
-free:
 	kfree(buf);
 	return ret;
 }
-- 
2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] IB/core: Fine-tuning for ib_is_udata_cleared() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-21 19:40 +0200
  [PATCH 2/2] IB/core: Delete an unnecessary initialisation in  ib_is_udata_cleared() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-21 19:50 +0200
  [PATCH 1/2] IB/core: Use memdup_user() rather than duplicating its  implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-21 19:50 +0200
  Re: [PATCH 0/2] IB/core: Fine-tuning for ib_is_udata_cleared() Joe Perches <joe@perches.com> - 2016-08-21 20:10 +0200
    Re: IB/core: Fine-tuning for ib_is_udata_cleared() Joe Perches <joe@perches.com> - 2016-08-21 22:00 +0200
      Re: IB/core: Fine-tuning for ib_is_udata_cleared() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-21 22:20 +0200
        Re: IB/core: Fine-tuning for ib_is_udata_cleared() Yann Droneaud <ydroneaud@opteya.com> - 2016-08-22 11:50 +0200
          [PATCH v2] IB/core: Use memdup_user() rather than duplicating its  implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-22 18:40 +0200
            Re: [PATCH v2] IB/core: Use memdup_user() rather than duplicating its  implementation Doug Ledford <dledford@redhat.com> - 2016-08-23 18:50 +0200
    Re: IB/core: Fine-tuning for ib_is_udata_cleared() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-21 22:00 +0200

csiph-web