* [PATCH net-next v3] r8152: simplify loops in generic_ocp_{read,write}()
@ 2026-09-07 19:46 Sergey Shtylyov
2026-09-10 2:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Sergey Shtylyov @ 2026-09-07 19:46 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-usb, netdev
Cc: Sergey Shtylyov, Michal Pecio
In generic_ocp_{read,write}(), the *while* loops look very strange:
the last iteration is implemented differently to the previous ones
(doing some useless assignments before *break*) for no good reason.
Merge the different iterations into one, using the local variables
in the loop bodies...
Found by Linux Verification Center (linuxtesting.org) with the Svace
static analysis tool.
Suggested-by: Michal Pecio <michal.pecio@gmail.com>
Signed-off-by: Sergey Shtylyov <s.shtylyov@auroraos.dev>
---
Changes in version 3:
- removed [RFC] from the subject;
- added the version log.
Changes in version 2:
- instead of moving the code for the last iteration out of the loop bodies,
merged the separate iterations into a single one as suggested by Michal
Pecio (adding the Suggested-by tag), rewrote the description accordingly.
drivers/net/usb/r8152.c | 55 +++++++++++++----------------------------
1 file changed, 17 insertions(+), 38 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f61686433031..af3d7dcb2f14 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1432,24 +1432,15 @@ static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
return -EPERM;
while (size) {
- if (size > limit) {
- ret = get_registers(tp, index, type, limit, data);
- if (ret < 0)
- break;
-
- index += limit;
- data += limit;
- size -= limit;
- } else {
- ret = get_registers(tp, index, type, size, data);
- if (ret < 0)
- break;
+ u16 n = min(size, limit);
- index += size;
- data += size;
- size = 0;
+ ret = get_registers(tp, index, type, n, data);
+ if (ret < 0)
break;
- }
+
+ index += n;
+ data += n;
+ size -= n;
}
if (ret == -ENODEV)
@@ -1499,28 +1490,16 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
size -= 4;
while (size) {
- if (size > limit) {
- ret = set_registers(tp, index,
- type | BYTE_EN_DWORD,
- limit, data);
- if (ret < 0)
- goto error1;
-
- index += limit;
- data += limit;
- size -= limit;
- } else {
- ret = set_registers(tp, index,
- type | BYTE_EN_DWORD,
- size, data);
- if (ret < 0)
- goto error1;
-
- index += size;
- data += size;
- size = 0;
- break;
- }
+ u16 n = min(size, limit);
+
+ ret = set_registers(tp, index, type | BYTE_EN_DWORD,
+ n, data);
+ if (ret < 0)
+ goto error1;
+
+ index += n;
+ data += n;
+ size -= n;
}
/* Set the last DWORD */
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v3] r8152: simplify loops in generic_ocp_{read,write}()
2026-09-07 19:46 [PATCH net-next v3] r8152: simplify loops in generic_ocp_{read,write}() Sergey Shtylyov
@ 2026-09-10 2:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-10 2:30 UTC (permalink / raw)
To: Sergey Shtylyov
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb, netdev,
michal.pecio
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 7 Sep 2026 22:46:32 +0300 you wrote:
> In generic_ocp_{read,write}(), the *while* loops look very strange:
> the last iteration is implemented differently to the previous ones
> (doing some useless assignments before *break*) for no good reason.
> Merge the different iterations into one, using the local variables
> in the loop bodies...
>
> Found by Linux Verification Center (linuxtesting.org) with the Svace
> static analysis tool.
>
> [...]
Here is the summary with links:
- [net-next,v3] r8152: simplify loops in generic_ocp_{read,write}()
https://git.kernel.org/netdev/net-next/c/f217004a40c4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-10 2:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 19:46 [PATCH net-next v3] r8152: simplify loops in generic_ocp_{read,write}() Sergey Shtylyov
2026-09-10 2:30 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.