Thread (42 messages) 42 messages, 13 authors, 2025-03-13

Re: [PATCH *-next 00/18] Remove weird and needless 'return' for void APIs

From: Zijun Hu <hidden>
Date: 2025-02-22 10:52:03
Also in: linux-arch, linux-crypto, linux-gpio, linux-iommu, linux-mm, linux-pm, linux-rdma, linux-wireless, lkml

On 2025/2/22 03:36, Johannes Berg wrote:
On Fri, 2025-02-21 at 11:00 -0800, Stephen Hemminger wrote:
quoted
Is this something that could be done with a coccinelle script?
Almost enough to do this:

@@
identifier fn;
expression E;
@@
void fn(...)
{
...
-return
E;
}


It takes a long time to run though, and does some wrong things as well:
if the return is in the middle of the function, it still matches and
removes it erroneously.
if return is in the middle, we may need to convert the return statement
in to two statement as [PATCH 18/18] does:
https://lore.kernel.org/all/20250221-rmv_return-v1-18-cc8dff275827@quicinc.com/ (local)

namely, Convert  "return func(...);" to "func(...); return;"

C spec such as C17 have this description about return
statement:
6.8.6.4:
A return statement with an expression shall not appear in a function
whose return type is void. A return statement without an expression
shall only appear in a function whose return type is void.


so, do we need to treat "return void function in void function" as
bad code style and make coccinelle script check this bad usage?




Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help