[Cocci] Remove unnecessary null pointer checks?

SF Markus Elfring elfring at users.sourceforge.net
Tue Feb 25 10:10:48 CET 2014


>> This example does not fit to my expectation because it seems that the function
>> implementation does not refer to the passed values.

I'm sorry that I overlooked information somehow there.

The implementations of the function "show_stack" can be nice source code
examples for further fine-tuning of proposed filter patterns.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/arch/um/kernel/sysrq.c?id=8ed12fcc194d93c6a17714120a7027ee4d76a881#n67

Its interface contains two pointer parameters.


> I'm not sure what is the point of the if (input) is else es pattern.

I can also adjust the search approach like the following.

@safety_check@
identifier work, input;
type data_type;
position pos;
statement is, es;
@@
 void work at pos(...,data_type input,...)
 {
  ...
( if (input) is
| if (likely(input)) is
)
  else es
  ...
 }


> I would think you only want to find cases where the function does nothing
> until it tests input and aborts the function is the value is 0.

I guess that the interpretation of "nothing relevant" will need further
considerations, won't it?


> So you only want the return case.

Not "only" this one ...

I have got a feeling for a need to introspect the else branch for useful
properties. I am unsure about better analysis of the metavariable "es" with the
semantic patch language.

Regards,
Markus


More information about the Cocci mailing list