Re: [PATCH 1/5] nubus: Simplify check in remove callback

From: Finn Thain
Date: Tue Jul 27 2021 - 06:19:39 EST


On Tue, 27 Jul 2021, Geert Uytterhoeven wrote:

> On Tue, Jul 27, 2021 at 11:50 AM Finn Thain <fthain@xxxxxxxxxxxxxx> wrote:
> > On Tue, 27 Jul 2021, Uwe Kleine-König wrote:
> > > Apart from that, the compiler might already assume dev->driver being
> > > non-NULL after to_nubus_driver(dev->driver) was called.
> >
> > I don't understand how a compiler can make that assumption. But then,
> > I don't know why compilers do a lot of the things they do...
>
> It is one of those recent optimizations people have been complaining
> about. Once you have dereferenced a pointer, compilers may remove all
> further NULL-checks, assuming they can't happen, as the code would have
> crashed anyway before due to the dereference.

But that's the point -- there is no dereference, just pointer arithmetic.

> Good luck running on bare metal with RAM at zero ;-)

Quite.