lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20061002133806.10bd652d.akpm@osdl.org>
Date:	Mon, 2 Oct 2006 13:38:06 -0700
From:	Andrew Morton <akpm@...l.org>
To:	David Brownell <david-b@...bell.net>
Cc:	"Thiago Galesi" <thiagogalesi@...il.com>,
	"Andrea Paterniani" <a.paterniani@...pp-eng.it>,
	"Linux Kernel list" <linux-kernel@...r.kernel.org>
Subject: Re: [patch 2.6.18-git] SPI -- Freescale iMX SPI controller driver

On Mon, 2 Oct 2006 13:10:14 -0700
David Brownell <david-b@...bell.net> wrote:

> > > +/* Message state */
> > > +#define START_STATE                    ((void*)0)
> > > +#define RUNNING_STATE                  ((void*)1)
> > > +#define DONE_STATE                     ((void*)2)
> > > +#define ERROR_STATE                    ((void*)-1)
> > 
> > !?!??!?!
> 
> Now that you mention it ... let me second that comment!

These are "better enums".  The problem with C's enums is that it's possible
to mix them with integers and the compiler just swallows it.  With the
above, you'll get a warning if you make that mistake.

But otoh, it's possible to accidentally mix the above with, say, char*. 
And it's not convenient to declare this type.  So something like this would
be better:

struct not_a_struct {};
typedef struct not_a_struct *better_enum;

#define RUNNING_STATE		((better_enum)1)

better_enum my_function(better_enum b)
{
	...
	return RUNNING_STATE;
}

would work.

Next would be

#define DECLARE_BETTER_ENUM(name)				\
	struct not_a_struct_##name {};				\
	typedef struct not_a_struct##name better_enum_##name;

so we can declare types like better_enum_spi_state,
better_enum_notifier_return_, etc.


Anyway, back to work...  any patch which actually attempts to implement
this sort of thing will be cheerily ignored ;)   Do the enum-mismatch checking
in sparse.

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ