[PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()

Thorsten Blum posted 1 patch 1 month, 2 weeks ago
net/core/pktgen.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
[PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()
Posted by Thorsten Blum 1 month, 2 weeks ago
Use min() to simplify pktgen_finalize_skb() and improve its readability.

Signed-off-by: Thorsten Blum <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..29ff079c0c36 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(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
Re: [PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()
Posted by kernel test robot 1 month, 2 weeks ago
Hi Thorsten,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Thorsten-Blum/net-pktgen-Use-min-to-simplify-pktgen_finalize_skb/20250815-012951
base:   net-next/main
patch link:    https://lore.kernel.org/r/20250814172242.231633-2-thorsten.blum%40linux.dev
patch subject: [PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()
config: arc-randconfig-002-20250815 (https://download.01.org/0day-ci/archive/20250815/202508151939.AA9PxPv1-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 9.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250815/202508151939.AA9PxPv1-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508151939.AA9PxPv1-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from <command-line>:
   net/core/pktgen.c: In function 'pktgen_finalize_skb':
>> include/linux/compiler_types.h:572:38: error: call to '__compiletime_assert_853' declared with attribute error: min(datalen / frags, ((1UL) << 12)) signedness error
     572 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |                                      ^
   include/linux/compiler_types.h:553:4: note: in definition of macro '__compiletime_assert'
     553 |    prefix ## suffix();    \
         |    ^~~~~~
   include/linux/compiler_types.h:572:2: note: in expansion of macro '_compiletime_assert'
     572 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |  ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:93:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      93 |  BUILD_BUG_ON_MSG(!__types_ok(ux, uy),  \
         |  ^~~~~~~~~~~~~~~~
   include/linux/minmax.h:98:2: note: in expansion of macro '__careful_cmp_once'
      98 |  __careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_))
         |  ^~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:105:19: note: in expansion of macro '__careful_cmp'
     105 | #define min(x, y) __careful_cmp(min, x, y)
         |                   ^~~~~~~~~~~~~
   net/core/pktgen.c:2845:14: note: in expansion of macro 'min'
    2845 |   frag_len = min(datalen / frags, PAGE_SIZE);
         |              ^~~


vim +/__compiletime_assert_853 +572 include/linux/compiler_types.h

eb5c2d4b45e3d2 Will Deacon 2020-07-21  558  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  559  #define _compiletime_assert(condition, msg, prefix, suffix) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21  560  	__compiletime_assert(condition, msg, prefix, suffix)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  561  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  562  /**
eb5c2d4b45e3d2 Will Deacon 2020-07-21  563   * compiletime_assert - break build and emit msg if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  564   * @condition: a compile-time constant condition to check
eb5c2d4b45e3d2 Will Deacon 2020-07-21  565   * @msg:       a message to emit if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  566   *
eb5c2d4b45e3d2 Will Deacon 2020-07-21  567   * In tradition of POSIX assert, this macro will break the build if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  568   * supplied condition is *false*, emitting the supplied error message if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  569   * compiler has support to do so.
eb5c2d4b45e3d2 Will Deacon 2020-07-21  570   */
eb5c2d4b45e3d2 Will Deacon 2020-07-21  571  #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @572  	_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  573  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()
Posted by Thorsten Blum 1 month, 2 weeks ago
On 15. Aug 2025, at 13:31, kernel test robot wrote:
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on net-next/main]

I thought I compile-tested it, but I must have forgotten to enable
CONFIG_NET_PKTGEN. Sorry about that.

I'll submit a v2.
Re: [PATCH net-next] net: pktgen: Use min() to simplify pktgen_finalize_skb()
Posted by Jakub Kicinski 1 month, 2 weeks ago
On Fri, 15 Aug 2025 13:46:57 +0200 Thorsten Blum wrote:
> On 15. Aug 2025, at 13:31, kernel test robot wrote:
> > kernel test robot noticed the following build errors:
> > 
> > [auto build test ERROR on net-next/main]  
> 
> I thought I compile-tested it, but I must have forgotten to enable
> CONFIG_NET_PKTGEN. Sorry about that.

FTR I don't think the min()/clamp() conversions are particularly
useful. I'll TAL at v2, but I'd appreciate if you stop sending
such patches to code under net/ and drivers/net/