Re: net: rnpgbe: Pass an expression directly in rnpgbe_rm_adapter()
From: Markus Elfring
Date: Wed Jul 15 2026 - 14:46:56 EST
Am 15.07.26 um 15:12 schrieb Uwe Kleine-König:
> On Mon, Jul 13, 2026 at 10:22:06AM +0200, Markus Elfring wrote:
>>>> The address of a data structure member was determined before
>>>> a corresponding null pointer check in the implementation of
>>>> the function “rnpgbe_rm_adapter”.
>>>>
>>>> Thus avoid the risk for undefined behaviour by omitting the variable “hw”.
>>>> Pass the required address directly to a function call.
>>>>
>>>> This issue was detected by using the Coccinelle software.
>>>>
>>>> Fixes: 2ee95ec17e97c58b65e978a08b75fa8cb6424e4e ("net: rnpgbe: Add register_netdev")
>>>
>>> There is no NULL dereference here. It's just pointer math.
>>> No need for a Fixes tag.
>>
>> How does your view fit to information in an article like “Fun with
>> NULL pointers, part 1”(by Jonathan Corbet from 2009-07-20)?
>> https://lwn.net/Articles/342330/
>
> It does fit, because the problematic code discussed in Jonathan Corbet's
> article is of the type:
>
> int i = ptr->i;
>
> if (!ptr)
> do_something();
>
> while here we have:
>
> int *i = &ptr->i;
>
> if (!ptr)
> do_something();
>
> which at least in my test[1] is relevantly different.
Jonathan Corbet provided the following information.
“…
But Herbert's patch added a line which dereferences the pointer prior to the check. That, of course, is a bug.
…”
> Note, I didn't
> study the C standard
I hope that clarification approaches can evolve further according to this information source.
> if the compiler is free to optimize out
> do_something() also in the 2nd case, but at least today gcc doesn't.
Can development interests grow also according to another clarification approach?
Does &((struct name *)NULL -> b) cause undefined behaviour in C11?
https://stackoverflow.com/questions/26906621/does-struct-name-null-b-cause-undefined-behaviour-in-c11
Would you prefer to omit a “sanity check” in the discussed function implementation?
Regards,
Markus