Advice Wanted on sonic.c Indentation Warning
Martin Galvan
martin.galvan at tallertechnologies.com
Tue Mar 22 15:25:33 UTC 2016
On Sat, Mar 19, 2016 at 15:59, Joel Sherrill <joel at rtems.org> wrote:
> Hi
>
> GCC 6.0 previews give the indentation warning below
>
> ../../../../../rtems/c/src/libchip/network/sonic.c:837:11: warning:
> statement is indented as if it were guarded by... [-Wmisleading-indentation]
>
> on this code from sonic.c.
>
> for (i = 0 ; i < 2 ; i++) {
> if ((*sc->read_register)( rp, SONIC_REG_RRP ) ==
> (*sc->read_register)( rp, SONIC_REG_RSA ))
> (*sc->write_register)(
> rp,
> SONIC_REG_RRP,
> (*sc->read_register)( rp, SONIC_REG_REA )
> );
> (*sc->write_register)(
> rp,
> SONIC_REG_RRP,
> (*sc->read_register)(rp, SONIC_REG_RRP) -
> sizeof(ReceiveResource_t)
> );
> }
>
> >From the comments, this code was written for RTEMS. Assuming it
> works (and it did on both a DMV177 and erc32 Tharsys board), then
> I am prone to add braces to the if and move the second write register
> to the left.
I'd honestly rewrite that entire snippet :)
for (i = 0; i < 2; ++i) {
uint32_t rrp = (*sc->read_register)( rp, SONIC_REG_RRP );
const uint32_t rsa = (*sc->read_register)( rp, SONIC_REG_RSA );
if (rrp == rsa) {
const uint32_t rea = (*sc->read_register)( rp, SONIC_REG_REA );
(*sc->write_register)( rp, SONIC_REG_RRP, rea );
}
rrp = (*sc->read_register)(rp, SONIC_REG_RRP);
(*sc->write_register)( rp, SONIC_REG_RRP, rrp - sizeof(ReceiveResource_t) );
}
I re-read RRP because I don't know if it can change between both calls.
More information about the devel
mailing list