Skip to contentSkip to conversation

net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb()

PATCH Applied Thorsten Blum 2 participants 2 messages Aug 15, 2025 – Aug 21, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: pktgen: Use min()/min_t() to improve pktgen_finalize_skb()

Use min() and min_t() to improve pktgen_finalize_skb() and avoid calculating 'datalen / frags' twice.

---
Changes in v2:
- Use min_t(int,,) to prevent a signedness error
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

---
 net/core/pktgen.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/core/pktgen.c +3 -4
index 0ebe5461d4d9..d41b03fd1f63 100644
@@ -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);
Signature · 1 line
2.50.1
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 10 lines · 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.

---
Changes in v2:
- Use min_t(int,,) to prevent a signedness error
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

[...]

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html