Re: [v5] Coccinelle: semantic code search for missing put_device()

From: Markus Elfring
Date: Fri Feb 15 2019 - 08:15:52 EST


>>> +id = of_find_device_by_node@p1(x)
â
>>> +if (id == NULL || ...) { ... return ...; }
>>> +... when != put_device(&id->dev)
>> â
>>> + when != if (id) { ... put_device(&id->dev) ... }
>> â
>>
>> I would interpret this SmPL code in the way that the if statement
>> for the pointer check is âoptionalâ in this line.
>> Is it an extra and redundant SmPL specification when the reference
>> release function could eventually be found just anywhere within
>> an implementation?
>
> The proposed when code is correct.

I agree that this SmPL code can work in the way it was designed.


> It is not redundant, because it checks for a particular control-flow pattern.

It took another moment until I dared to express a different software
development opinion also on this implementation detail.

Does the first SmPL when specification include the case that a call
of the function âput_deviceâ can occur within a branch of an if statement?

Regards,
Markus