Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20250815153334.295431-3-thorsten.blum@linux.dev
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Thorsten Blum and committed by
Paolo Abeni
833e4317 62a2b350

+3 -4
+3 -4
net/core/pktgen.c
··· 114 114 115 115 #include <linux/sys.h> 116 116 #include <linux/types.h> 117 + #include <linux/minmax.h> 117 118 #include <linux/module.h> 118 119 #include <linux/moduleparam.h> 119 120 #include <linux/kernel.h> ··· 2842 2841 } 2843 2842 2844 2843 i = 0; 2845 - frag_len = (datalen/frags) < PAGE_SIZE ? 2846 - (datalen/frags) : PAGE_SIZE; 2844 + frag_len = min_t(int, datalen / frags, PAGE_SIZE); 2847 2845 while (datalen > 0) { 2848 2846 if (unlikely(!pkt_dev->page)) { 2849 2847 int node = numa_node_id(); ··· 2859 2859 if (i == (frags - 1)) 2860 2860 skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i], 2861 2861 pkt_dev->page, 0, 2862 - (datalen < PAGE_SIZE ? 2863 - datalen : PAGE_SIZE)); 2862 + min(datalen, PAGE_SIZE)); 2864 2863 else 2865 2864 skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i], 2866 2865 pkt_dev->page, 0, frag_len);