[arch/arm/mach-mvebu] Question about kzalloc NULL check in i2c_quirk

Andrew Lunn andrew at lunn.ch
Wed Mar 20 12:03:36 PDT 2024


> > What context is this code run in? What would need to happen for the
> > allocation to fail? And what happens next if it does fail, both in
> > this function and the system in general?
> > 
> > 	   Andrew
> > 
> 
> Hi Andrew,
> 
> Thanks for checking!
> 
> We encountered this kzalloc while doing a static analysis for the kernel code.
> 
> kzalloc would return NULL in case of out-of-memory and would make the next field access new_compat->name segfault.
> 
> However, we are not sure if i2c_quirk, used in an init_machine hook, has any special assumption, so would appreciate your knowledge to decide whether an NULL check is needed.

Please configure your email client to wrap lines at around 70
characters.

O.K, let me help you answer your questions.

When is init_machine called?

What would need to happen for the allocation to fail?

Say it does fall, and you avoid a NULL pointer dereference here. What
happens next to the system in general.

These are not hard questions to answer, you just need to think about
them a little.

     Andrew



More information about the linux-arm-kernel mailing list