diff mbox series

[ovs-dev] util: Better document ALIGNED_CAST.

Message ID 20180918050123.27641-1-blp@ovn.org
State Accepted
Headers show
Series [ovs-dev] util: Better document ALIGNED_CAST. | expand

Commit Message

Ben Pfaff Sept. 18, 2018, 5:01 a.m. UTC
CC: Han Zhou <zhouhan@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 include/openvswitch/util.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Han Zhou Sept. 18, 2018, 5:12 a.m. UTC | #1
On Mon, Sep 17, 2018 at 10:01 PM Ben Pfaff <blp@ovn.org> wrote:
>
> CC: Han Zhou <zhouhan@gmail.com>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---
>  include/openvswitch/util.h | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
> index b4d49ee21804..9189e6480b1c 100644
> --- a/include/openvswitch/util.h
> +++ b/include/openvswitch/util.h
> @@ -273,8 +273,14 @@ is_pow2(uintmax_t x)
>  #define BITMAP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)
>  #define BITMAP_N_LONGS(N_BITS) DIV_ROUND_UP(N_BITS, BITMAP_ULONG_BITS)
>
> -/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
> - * (void *). This is to suppress the alignment warning issued by clang.
*/
> +/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
(void
> + * *).  This suppresses the alignment warning issued by Clang and newer
> + * versions of GCC when a pointer is cast to a type with a stricter
alignment.
> + *
> + * Add ALIGNED_CAST only if you are sure that the cast is actually
correct,
> + * that is, that the pointer is actually properly aligned for the
stricter
> + * type.  On RISC architectures, dereferencing a misaligned pointer can
cause a
> + * segfault, so it is important to be aware of correct alignment. */
>  #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
>
>  #ifdef __cplusplus
> --
> 2.16.1
>

Thanks Ben.
Acked-by: Han Zhou <hzhou8@ebay.com>
Ben Pfaff Sept. 18, 2018, 5:21 a.m. UTC | #2
On Mon, Sep 17, 2018 at 10:12:09PM -0700, Han Zhou wrote:
> On Mon, Sep 17, 2018 at 10:01 PM Ben Pfaff <blp@ovn.org> wrote:
> >
> > CC: Han Zhou <zhouhan@gmail.com>
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> >  include/openvswitch/util.h | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
> > index b4d49ee21804..9189e6480b1c 100644
> > --- a/include/openvswitch/util.h
> > +++ b/include/openvswitch/util.h
> > @@ -273,8 +273,14 @@ is_pow2(uintmax_t x)
> >  #define BITMAP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)
> >  #define BITMAP_N_LONGS(N_BITS) DIV_ROUND_UP(N_BITS, BITMAP_ULONG_BITS)
> >
> > -/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
> > - * (void *). This is to suppress the alignment warning issued by clang.
> */
> > +/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
> (void
> > + * *).  This suppresses the alignment warning issued by Clang and newer
> > + * versions of GCC when a pointer is cast to a type with a stricter
> alignment.
> > + *
> > + * Add ALIGNED_CAST only if you are sure that the cast is actually
> correct,
> > + * that is, that the pointer is actually properly aligned for the
> stricter
> > + * type.  On RISC architectures, dereferencing a misaligned pointer can
> cause a
> > + * segfault, so it is important to be aware of correct alignment. */
> >  #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
> >
> >  #ifdef __cplusplus
> > --
> > 2.16.1
> >
> 
> Thanks Ben.
> Acked-by: Han Zhou <hzhou8@ebay.com>

Thanks, applied to master.
diff mbox series

Patch

diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index b4d49ee21804..9189e6480b1c 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -273,8 +273,14 @@  is_pow2(uintmax_t x)
 #define BITMAP_ULONG_BITS (sizeof(unsigned long) * CHAR_BIT)
 #define BITMAP_N_LONGS(N_BITS) DIV_ROUND_UP(N_BITS, BITMAP_ULONG_BITS)
 
-/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
- * (void *). This is to suppress the alignment warning issued by clang. */
+/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to (void
+ * *).  This suppresses the alignment warning issued by Clang and newer
+ * versions of GCC when a pointer is cast to a type with a stricter alignment.
+ *
+ * Add ALIGNED_CAST only if you are sure that the cast is actually correct,
+ * that is, that the pointer is actually properly aligned for the stricter
+ * type.  On RISC architectures, dereferencing a misaligned pointer can cause a
+ * segfault, so it is important to be aware of correct alignment. */
 #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
 
 #ifdef __cplusplus