* [PATCH net-next v2] net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb()
@ 2025-08-15 15:33 Thorsten Blum
2025-08-21 8:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-08-15 15:33 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Peter Seiderer, Toke Høiland-Jørgensen
Cc: Thorsten Blum, netdev, linux-kernel
Use min() and min_t() to improve pktgen_finalize_skb() and avoid
calculating 'datalen / frags' twice.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Use min_t(int,,) to prevent a signedness error
- Link to v1: https://lore.kernel.org/lkml/20250814172242.231633-2-thorsten.blum@linux.dev/
---
net/core/pktgen.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 0ebe5461d4d9..d41b03fd1f63 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -114,6 +114,7 @@
#include <linux/sys.h>
#include <linux/types.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
@@ -2841,8 +2842,7 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
}
i = 0;
- frag_len = (datalen/frags) < PAGE_SIZE ?
- (datalen/frags) : PAGE_SIZE;
+ frag_len = min_t(int, datalen / frags, PAGE_SIZE);
while (datalen > 0) {
if (unlikely(!pkt_dev->page)) {
int node = numa_node_id();
@@ -2859,8 +2859,7 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
if (i == (frags - 1))
skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i],
pkt_dev->page, 0,
- (datalen < PAGE_SIZE ?
- datalen : PAGE_SIZE));
+ min(datalen, PAGE_SIZE));
else
skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i],
pkt_dev->page, 0, frag_len);
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v2] net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb()
2025-08-15 15:33 [PATCH net-next v2] net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb() Thorsten Blum
@ 2025-08-21 8:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-21 8:20 UTC (permalink / raw)
To: Thorsten Blum
Cc: davem, edumazet, kuba, pabeni, horms, ps.report, toke, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 15 Aug 2025 17:33:33 +0200 you wrote:
> Use min() and min_t() to improve pktgen_finalize_skb() and avoid
> calculating 'datalen / frags' twice.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> Changes in v2:
> - Use min_t(int,,) to prevent a signedness error
> - Link to v1: https://lore.kernel.org/lkml/20250814172242.231633-2-thorsten.blum@linux.dev/
>
> [...]
Here is the summary with links:
- [net-next,v2] net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb()
https://git.kernel.org/netdev/net-next/c/833e43171b00
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:[~2025-08-21 8:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 15:33 [PATCH net-next v2] net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb() Thorsten Blum
2025-08-21 8:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).