On Thu, Sep 22, 2011 at 08:20:54PM +0000, Hefty, Sean wrote:
 
> The entire windows tree is built using the WinDDK compiler.  I
> haven't found a way to disable that warning that works.  Since the
> warning is real, an explicit cast at least lets someone reading the
> code know that the author took truncation into account.

It would be much better to fix this at the source.

 mad_get_field16(..,IB_NODE_DEVID_F)

Then at least there is the option of doing a static or runtime check
that IB_NODE_DEVID_F is actually referring to a 16 bit field.

For instance, a static check might be possible with some compilers by
doing:

enum MAD_FIELDS8
{
IB_PORT_LOCAL_PORT_F
};

enum MAD_FIELDS16
{
IB_NODE_DEVID_F
};

uint8_t mad_get_field8(void *buf, int base_offs,
                       enum MAD_FIELDS8 field);
uint16_t mad_get_field16(void *buf, int base_offs,
                         enum MAD_FIELDS16 field);

A compiler can produce a warning about mismatching enums.

Someone can fixup the enums later, but I'd much rather see you add a
patch with this hunk:

static inline uint16_t mad_get_field16(void *buf, int base_offs,
                                       enum MAD_FIELDS field)
{
   return (uint16_t)mad_get_field(buf,base_offs,field);
}

And another patch replacing every (uint16_t)mad_get_field with
mad_get_field16

Adding a cast is just pointless noise, doesn't fix or prove anything.

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

Reply via email to