Message ID | d9486296c3b6b12ab3a0515fcd47d56447a07bfc.1699897370.git.baruch@tkos.co.il (mailing list archive) |
---|---|
State | Accepted |
Commit | fa02de9e75889915b554eda1964a631fd019973b |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net,1/2] net: stmmac: fix rx budget limit check | expand |
On Mon, Nov 13, 2023 at 07:42:49PM +0200, Baruch Siach wrote: > The while loop condition verifies 'count < limit'. Neither value change > before the 'count >= limit' check. As is this check is dead code. But > code inspection reveals a code path that modifies 'count' and then goto > 'drain_data' and back to 'read_again'. So there is a need to verify > count value sanity after 'read_again'. > > Move 'read_again' up to fix the count limit check. Nice catch! My local fix was to just drop the statement, but obviously it was wrong. Indeed it's possible to have an implicit loop based on two goto'es. So for this change definitely: Reviewed-by: Serge Semin <fancer.lancer@gmail.com> From the patch perspective seeing how clumsy the stmmac_rx()/stmmac_xmit() methods look here and in several/multiple other net-drivers here is a question to the subsystem maintainers. Is it really a preferred practice to design them that way with gotos and embed all the various stuff directly to a single function? Wouldn't it be better at least from the readability point of view to split them up into a set of smaller coherent functions and get rid from the gotos? I am wondering because normally it would be indeed better, but network subsystem may have some special requirements for such methods (if so is it described anywhere in the kernel doc?), for instance, to reach a greater performance by not relying on the compiler to embed the sub-functions body into the denoted functions or by using the gotos so not to increment the loop-counter and preserve the indentation level. All of that may improve the code performance in some extent, but in its turn it significantly reduces the code readability and maintainability. -Serge(y) > > Fixes: ec222003bd94 ("net: stmmac: Prepare to add Split Header support") > Signed-off-by: Baruch Siach <baruch@tkos.co.il> > --- > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index 3e50fd53a617..f28838c8cdb3 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -5328,10 +5328,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) > len = 0; > } > > +read_again: > if (count >= limit) > break; > > -read_again: > buf1_len = 0; > buf2_len = 0; > entry = next_entry; > -- > 2.42.0 > >
Hello: This series was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Mon, 13 Nov 2023 19:42:49 +0200 you wrote: > The while loop condition verifies 'count < limit'. Neither value change > before the 'count >= limit' check. As is this check is dead code. But > code inspection reveals a code path that modifies 'count' and then goto > 'drain_data' and back to 'read_again'. So there is a need to verify > count value sanity after 'read_again'. > > Move 'read_again' up to fix the count limit check. > > [...] Here is the summary with links: - [net,1/2] net: stmmac: fix rx budget limit check https://git.kernel.org/netdev/net/c/fa02de9e7588 - [net,2/2] net: stmmac: avoid rx queue overrun https://git.kernel.org/netdev/net/c/b6cb4541853c You are awesome, thank you!
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 3e50fd53a617..f28838c8cdb3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5328,10 +5328,10 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) len = 0; } +read_again: if (count >= limit) break; -read_again: buf1_len = 0; buf2_len = 0; entry = next_entry;
The while loop condition verifies 'count < limit'. Neither value change before the 'count >= limit' check. As is this check is dead code. But code inspection reveals a code path that modifies 'count' and then goto 'drain_data' and back to 'read_again'. So there is a need to verify count value sanity after 'read_again'. Move 'read_again' up to fix the count limit check. Fixes: ec222003bd94 ("net: stmmac: Prepare to add Split Header support") Signed-off-by: Baruch Siach <baruch@tkos.co.il> --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)