Christoph Hellwig hch at infradead.org
Fri Mar 11 02:32:33 MST 2011

On Fri, Mar 11, 2011 at 10:56:42AM +1100, tridge at samba.org wrote:
> Hi Christoph,
>  > Did you guys ever look into the sparse address space annotations?
> can sparse be used to warn about mixing of different integer types? 


> I so, that could be _really_ useful! We could get rid of the NTSTATUS
> structure in that case as well.
> looking at the sparse manpage, I think we'd need to declare NTTIME and
> NTSTATUS as being __attribute__((bitwise)), then use -Wbitwise with
> sparse. Does that sound right?

Exactly.  E.g. from the Linux kernel code for the little/big-endian
types (it requires -D__CHECK_ENDIAN__ to actually check endianess even
with sparse for historic reasons):


#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#define __bitwise__
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#define __bitwise

typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
typedef __u32 __bitwise __be32;
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;

and then the (be|le)*_to_cpu/cpu_to_(be|le)* require casts in their
actual bit-swap operations.

Note that bitwise also disallows arithmetic operations on these types.
I'm not sure how much of an issue that is for your NTTIME use case -
arithmetics on time values makes sense in theory, but I'm not sure how
common it is.

More information about the samba-technical mailing list