Re: [PATCH 2.6.7-mm1] MBR centralization

From: Andries Brouwer
Date: Fri Jun 25 2004 - 04:42:21 EST


On Fri, Jun 25, 2004 at 09:30:24AM +0100, Anton Altaparmakov wrote:
> On Thu, 2004-06-24 at 14:06, Andries Brouwer wrote:
> > On Thu, Jun 24, 2004 at 08:38:52AM +0100, Anton Altaparmakov wrote:
> > > While I am at it, the above macro is even further optimized by moving the
> > > endianness conversion to the constant so it is applied at compile time
> > > rather than run time like so:
> > >
> > > #define MSDOS_MBR(p) ((*(u16*)(p)) == __constant_cpu_to_le16(0xaa55))
> >
> > I never understand why people want to do such things.
> > Cast a character pointer to u16*, possibly do a byteswap, etc.
> > What one wants is just
> >
> > p[0] == 0x55 && p[1] == 0xaa
>
> I would disagree. Seeing something like "is_msdos_mbr(p)" it is
> immediately obvious what it means while seeing the "p[0] = 0x55 && p[1]
> = 0xaa" it is not obvious at all what it means. IMO _any_ hardcoded
> value is a very bad thing

Ha Anton - you cannot read.
I complain about this strange casting, and you start talking about hardcoded
values (while you write 0xaa55 yourself). The current code is below - a good
name and no hardcoded constants and no strange casts.

Andries


#define MSDOS_LABEL_MAGIC1 0x55
#define MSDOS_LABEL_MAGIC2 0xAA

static inline int
msdos_magic_present(unsigned char *p)
{
return (p[0] == MSDOS_LABEL_MAGIC1 && p[1] == MSDOS_LABEL_MAGIC2);
}
-
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/