Advice Wanted on sonic.c Indentation Warning

Joel Sherrill joel at rtems.org
Tue Mar 22 15:30:32 UTC 2016


On Tue, Mar 22, 2016 at 10:25 AM, Martin Galvan <
martin.galvan at tallertechnologies.com> wrote:

> 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.
>

If you want to submit a patch and reference this email thread URL so
future generations know what was discussed, feel free. :)

--joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20160322/bbea4d66/attachment-0001.html>


More information about the devel mailing list