+ compilerh-add-support-for-malloc-attribute.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: compiler.h: add support for malloc attribute
has been added to the -mm tree.  Its filename is
     compilerh-add-support-for-malloc-attribute.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/compilerh-add-support-for-malloc-attribute.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/compilerh-add-support-for-malloc-attribute.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Subject: compiler.h: add support for malloc attribute

gcc as far back as at least 3.04 documents the function attribute
__malloc__.  Add a shorthand for attaching that to a function declaration.
This was also suggested by Andi Kleen way back in 2002 [1], but didn't
get applied, perhaps because gcc at that time generated the exact same
code with and without this attribute.

This attribute tells the compiler that the return value (if non-NULL) can
be assumed not to alias any other valid pointers at the time of the call.

Please note that the documentation for a range of gcc versions (starting
from around 4.7) contained a somewhat confusing and self-contradicting
text:

  The malloc attribute is used to tell the compiler that a function may
  be treated as if any non-NULL pointer it returns cannot alias any other
  pointer valid when the function returns and *that the memory has
  undefined content*.  [...] Standard functions with this property include
  malloc and *calloc*.

(emphasis mine). The intended meaning has later been clarified [2]:

  This tells the compiler that a function is malloc-like, i.e., that the
  pointer P returned by the function cannot alias any other pointer valid
  when the function returns, and moreover no pointers to valid objects
  occur in any storage addressed by P.

What this means is that we can apply the attribute to kmalloc and friends,
and it is ok for the returned memory to have well-defined contents
(__GFP_ZERO).  But it is not ok to apply it to kmemdup(), nor to other
functions which both allocate and possibly initialize the memory with
existing pointers.  So unless someone is doing something pretty perverted
kstrdup() should also be a fine candidate.

[1] http://thread.gmane.org/gmane.linux.kernel/57172
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56955

Signed-off-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxx>
Cc: Pekka Enberg <penberg@xxxxxxxxxx>
Cc: David Rientjes <rientjes@xxxxxxxxxx>
Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 include/linux/compiler-gcc.h |    1 +
 include/linux/compiler.h     |    4 ++++
 2 files changed, 5 insertions(+)

diff -puN include/linux/compiler-gcc.h~compilerh-add-support-for-malloc-attribute include/linux/compiler-gcc.h
--- a/include/linux/compiler-gcc.h~compilerh-add-support-for-malloc-attribute
+++ a/include/linux/compiler-gcc.h
@@ -142,6 +142,7 @@
 
 #if GCC_VERSION >= 30400
 #define __must_check		__attribute__((warn_unused_result))
+#define __malloc		__attribute__((__malloc__))
 #endif
 
 #if GCC_VERSION >= 40000
diff -puN include/linux/compiler.h~compilerh-add-support-for-malloc-attribute include/linux/compiler.h
--- a/include/linux/compiler.h~compilerh-add-support-for-malloc-attribute
+++ a/include/linux/compiler.h
@@ -357,6 +357,10 @@ static __always_inline void __write_once
 #define __deprecated_for_modules
 #endif
 
+#ifndef __malloc
+#define __malloc
+#endif
+
 /*
  * Allow us to avoid 'defined but not used' warnings on functions and data,
  * as well as force them to be emitted to the assembly file.
_

Patches currently in -mm which might be from linux@xxxxxxxxxxxxxxxxxx are

compilerh-add-support-for-malloc-attribute.patch
include-linux-apply-__malloc-attribute.patch

--
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux