Re: [Patch 14/16] Remove needless kmalloc casts in the zd1211rw drivers.

From: Daniel Drake
Date: Tue Jul 31 2007 - 22:10:56 EST


Stefan Richter wrote:
NAK: this patch adds a sparse warning
zd_chip.c:116:15: warning: implicit cast to nocast type

What does this warning mean? a16 is defined as zd_addr_t *.

zd_addr_t is defined as
typedef u16 __nocast zd_addr_t;

The __nocast annotation forces us to use explicit casts for values of this type. This is really useful as we have functions which take an address and a value (e.g. register writes). It's very easy to get them in the wrong order and have a non-obvious bug. With this mechanism, sparse helps us avoid this.

The case with pointers may be a little unintuitive, but it's a small price to pay for a bug that bit us hard once before...

The number of other places we have to cast is very small due to use of the preprocessor. For example we have:

#define ZD_ADDR(base, offset) \
((zd_addr_t)(((base) & ADDR_BASE_MASK) | ((offset) & ADDR_OFFSET_MASK)))

#define CTL_REG(offset) ZD_ADDR(CR_BASE, offset) /* byte addressing */

Then we have a few hundred registers defined in terms of CTL_REG.

Also, why is there this cast right before that?

zd_addr_t *a16 = (zd_addr_t *)NULL;

For similar reasons.

Daniel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/