Re: [PATCH] driver core: faux: fix Undefined Behavior in faux_device_destroy()
From: Dan Carpenter
Date: Thu Jun 19 2025 - 00:02:41 EST
On Wed, Jun 18, 2025 at 08:33:27PM -0700, Marc Herbert wrote:
> > But, again, this is a totally different thing from what the patch does.
> > The faux_device_destroy() code is not doing a dereference, it's doing
> > pointer math.
>
> pointer math is what we _want_ the code to do. But if that relies on
> some undefined behavior(s) then the bets are off again. Check
> https://stackoverflow.com/questions/26906621/does-struct-name-null-b-cause-undefined-behaviour-in-c11
> where offsetof() is a suggested alternative.
The answers talk about "But the value of a null pointer constant is not
defined as 0." which is some trivia that had heard before. Probably
I heard it in the context of someone saying that we should check
"if (p == NULL)" instead of "if (!p)"...
regards,
dan carpenter