svn commit: r233700 - head/sys/kern

Dimitry Andric dim at FreeBSD.org
Fri Mar 30 19:49:47 UTC 2012


On 2012-03-30 15:30, Stefan Farfeleder wrote:
> here are a few similar cases.

Hm, what about this one that clang warns about:

   sys/dev/asr/asr.c:2420:57: warning: for loop has empty body [-Wempty-body]
	  for (ha = &Asr_softc_list; *ha; ha = &((*ha)->ha_next));
								 ^
   sys/dev/asr/asr.c:2420:57: note: put the semicolon on a separate line to silence this warning [-Wempty-body]

I'm not sure about it though, the code looks like this:

static int
asr_attach(device_t dev)
{
[...]
         Asr_softc_t              *sc, **ha;
[...]
         LIST_INIT(&(sc->ha_ccb));
         /* Link us into the HA list */
         for (ha = &Asr_softc_list; *ha; ha = &((*ha)->ha_next));
                 *(ha) = sc;

It seems the for loop walks the list until the end, then tacks 'sc' onto
it.

So to 'fix' the warning, and make the meaning more explicit, we should
probably rewrite that fragment as:

         LIST_INIT(&(sc->ha_ccb));
         /* Link us into the HA list */
         for (ha = &Asr_softc_list; *ha; ha = &((*ha)->ha_next))
		;
	*(ha) = sc;

Is this OK?


More information about the svn-src-head mailing list