[PATCH] Prevent crash when adding interface under a lag

Jerry Wu posted 1 patch 1 month, 2 weeks ago
drivers/net/ethernet/mscc/ocelot.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[PATCH] Prevent crash when adding interface under a lag
Posted by Jerry Wu 1 month, 2 weeks ago
Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag")
had fixed CVE-2024-26723 which is caused by NULL pointer dereference.
ocelot_set_aggr_pgids in drivers/net/ethernet/mscc/ocelot.c contains a similar logic.
This patch fix it in the same way as the aforementioned patch did.

Signed-off-by: Jerry Wu <w.7erry@foxmail.com>
---
 drivers/net/ethernet/mscc/ocelot.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 08bee56aea35..cb1c19c38c2c 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2307,19 +2307,24 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
 
 	/* Now, set PGIDs for each active LAG */
 	for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
-		struct net_device *bond = ocelot->ports[lag]->bond;
+		struct ocelot_port *port = ocelot->ports[lag];
 		int num_active_ports = 0;
+		struct net_device *bond;
 		unsigned long bond_mask;
 		u8 aggr_idx[16];
 
-		if (!bond || (visited & BIT(lag)))
+		if (!port || !port->bond || (visited & BIT(lag)))
 			continue;
 
+		bond = port->bond;
 		bond_mask = ocelot_get_bond_mask(ocelot, bond);
 
 		for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
 			struct ocelot_port *ocelot_port = ocelot->ports[port];
 
+			if (!port)
+				continue;
+
 			// Destination mask
 			ocelot_write_rix(ocelot, bond_mask,
 					 ANA_PGID_PGID, port);
-- 
2.51.0
Re: [PATCH] Prevent crash when adding interface under a lag
Posted by Vladimir Oltean 1 month, 2 weeks ago
Hello,

On Sat, Dec 20, 2025 at 05:32:15PM +0000, Jerry Wu wrote:
> Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag")
> had fixed CVE-2024-26723 which is caused by NULL pointer dereference.
> ocelot_set_aggr_pgids in drivers/net/ethernet/mscc/ocelot.c contains a similar logic.
> This patch fix it in the same way as the aforementioned patch did.
> 
> Signed-off-by: Jerry Wu <w.7erry@foxmail.com>
> ---

Please follow the Documentation/process/maintainer-netdev.rst process
and send the patch to the net tree and use ./scripts/get_maintainer.pl
to form a more comprehensive CC list, which at the very least contains
netdev@vger.kernel.org.

We need a Fixes: tag; I believe the correct one should be:
Fixes: 528d3f190c98 ("net: mscc: ocelot: drop the use of the "lags" array")
Looking at that commit, we can clearly see that when iterating the first
time to form the "visited" mask, we do skip the unprobed ports properly:

		if (!ocelot_port || !ocelot_port->bond)
			continue;

but then there is another iteration over the ports right next to it, and
we failed to check this condition again.

I would add a small mention that the Ocelot library has two front-ends,
which treat unused ports differently.

The drivers/net/dsa/ocelot/felix_vsc9959.c frontend uses the DSA
framework, which registers ports for all switch ports, with the special
DSA_PORT_TYPE_UNUSED value. I tested the patch on this frontend, so the
bug doesn't exist there.

Then there is the drivers/net/ethernet/mscc/ocelot_vsc7514.c frontend,
which indeed leaves unused ports as NULL pointers. The problem only
exists there.

>  drivers/net/ethernet/mscc/ocelot.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
> index 08bee56aea35..cb1c19c38c2c 100644
> --- a/drivers/net/ethernet/mscc/ocelot.c
> +++ b/drivers/net/ethernet/mscc/ocelot.c
> @@ -2307,19 +2307,24 @@ static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
> 
>         /* Now, set PGIDs for each active LAG */
>         for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
> -               struct net_device *bond = ocelot->ports[lag]->bond;
> +               struct ocelot_port *port = ocelot->ports[lag];

Please name the variable ocelot_port, that is the convention in this driver.
If you name it "port", you are shadowing the "int port" definition from
the beginning of the function.

>                 int num_active_ports = 0;
> +               struct net_device *bond;
>                 unsigned long bond_mask;
>                 u8 aggr_idx[16];
> 
> -               if (!bond || (visited & BIT(lag)))
> +               if (!port || !port->bond || (visited & BIT(lag)))
>                         continue;
> 
> +               bond = port->bond;
>                 bond_mask = ocelot_get_bond_mask(ocelot, bond);

I think you can remove the "bond" local variable and replace this with
ocelot_port->bond directly. This makes the check rather similar with the
one from the previous

> 
>                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
>                         struct ocelot_port *ocelot_port = ocelot->ports[port];
> 
> +                       if (!port)
> +                               continue;
> +

This hunk is
(a) unnecessary. The bond_mask is formed by ocelot_get_bond_mask(), and
    this doesn't set ports which don't exist in the mask. So there is no
    reason to add this check.
(b) incorrect. You are testing that the "int port" is zero, not that the
    "ocelot_port" pointer is NULL (the real intention, but unnecessary,
    see a).

>                         // Destination mask
>                         ocelot_write_rix(ocelot, bond_mask,
>                                          ANA_PGID_PGID, port);
> --
> 2.51.0
>
Re: [PATCH] Prevent crash when adding interface under a lag
Posted by Vladimir Oltean 1 month, 2 weeks ago
On Sat, Dec 20, 2025 at 05:32:15PM +0000, Jerry Wu wrote:
> Commit 15faa1f67ab4 ("lan966x: Fix crash when adding interface under a lag")
> had fixed CVE-2024-26723 which is caused by NULL pointer dereference.
> ocelot_set_aggr_pgids in drivers/net/ethernet/mscc/ocelot.c contains a similar logic.
> This patch fix it in the same way as the aforementioned patch did.
> 
> Signed-off-by: Jerry Wu <w.7erry@foxmail.com>
> ---

One thing I forgot to mention is that you need to add the
"net: mscc: ocelot: Prevent ..." prefix in your commit title.
Compare with other commits on this driver and try to adapt to the style
used there.
Re: [PATCH] Prevent crash when adding interface under a lag
Posted by kernel test robot 1 month, 2 weeks ago
Hi Jerry,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.19-rc2 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jerry-Wu/Prevent-crash-when-adding-interface-under-a-lag/20251221-013514
base:   linus/master
patch link:    https://lore.kernel.org/r/tencent_9E2B81D645D04DFE191C86F128212F842B05%40qq.com
patch subject: [PATCH] Prevent crash when adding interface under a lag
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20251223/202512231521.giSxyLFY-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251223/202512231521.giSxyLFY-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/202512231521.giSxyLFY-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/bitmap.h:11,
                    from include/linux/cpumask.h:11,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:63,
                    from include/linux/debugobjects.h:6,
                    from include/linux/timer.h:8,
                    from include/linux/netdevice.h:24,
                    from include/linux/if_bridge.h:12,
                    from include/linux/dsa/ocelot.h:8,
                    from drivers/net/ethernet/mscc/ocelot.c:7:
   drivers/net/ethernet/mscc/ocelot.c: In function 'ocelot_set_aggr_pgids':
   include/linux/find.h:586:63: error: passing argument 3 of 'find_next_bit' makes integer from pointer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                               ^~~~~
         |                                                               |
         |                                                               struct ocelot_port *
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   include/linux/find.h:61:43: note: expected 'long unsigned int' but argument is of type 'struct ocelot_port *'
      61 |                             unsigned long offset)
         |                             ~~~~~~~~~~~~~~^~~~~~
   include/linux/find.h:586:31: error: assignment to 'struct ocelot_port *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                               ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
>> include/linux/find.h:586:77: warning: comparison between pointer and integer
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                                             ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   drivers/net/ethernet/mscc/ocelot.c:2323:72: error: array subscript is not an integer
    2323 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/soc/mscc/ocelot_vcap.h:9,
                    from drivers/net/ethernet/mscc/ocelot.c:13:
   include/soc/mscc/ocelot.h:923:55: error: invalid operands to binary * (have 'int' and 'struct ocelot_port *')
     923 |         __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
         |                                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2329:25: note: in expansion of macro 'ocelot_write_rix'
    2329 |                         ocelot_write_rix(ocelot, bond_mask,
         |                         ^~~~~~~~~~~~~~~~
   drivers/net/ethernet/mscc/ocelot.c:2333:62: error: assignment to 'u8' {aka 'unsigned char'} from 'struct ocelot_port *' makes integer from pointer without a cast [-Wint-conversion]
    2333 |                                 aggr_idx[num_active_ports++] = port;
         |                                                              ^
   drivers/net/ethernet/mscc/ocelot.c:2352:27: error: assignment to 'struct ocelot_port *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                           ^
>> drivers/net/ethernet/mscc/ocelot.c:2352:39: warning: comparison between pointer and integer
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2353:72: error: array subscript is not an integer
    2353 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/linux/bits.h:5,
                    from include/linux/ratelimit_types.h:5,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:31,
                    from arch/parisc/include/asm/bug.h:97,
                    from include/linux/ktime.h:24,
                    from include/linux/timer.h:6:
   include/vdso/bits.h:7:40: error: invalid operands to binary << (have 'long unsigned int' and 'struct ocelot_port *')
       7 | #define BIT(nr)                 (UL(1) << (nr))
         |                                        ^~
   drivers/net/ethernet/mscc/ocelot.c:2359:44: note: in expansion of macro 'BIT'
    2359 |                                 visited |= BIT(port);
         |                                            ^~~


vim +2352 drivers/net/ethernet/mscc/ocelot.c

a556c76adc052c Alexandre Belloni 2018-05-14  2277  
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2278  static void ocelot_set_aggr_pgids(struct ocelot *ocelot)
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2279  {
528d3f190c98c8 Vladimir Oltean   2021-02-06  2280  	unsigned long visited = GENMASK(ocelot->num_phys_ports - 1, 0);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2281  	int i, port, lag;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2282  
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2283  	/* Reset destination and aggregation PGIDS */
96b029b004942e Vladimir Oltean   2020-06-21  2284  	for_each_unicast_dest_pgid(ocelot, port)
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2285  		ocelot_write_rix(ocelot, BIT(port), ANA_PGID_PGID, port);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2286  
96b029b004942e Vladimir Oltean   2020-06-21  2287  	for_each_aggr_pgid(ocelot, i)
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2288  		ocelot_write_rix(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0),
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2289  				 ANA_PGID_PGID, i);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2290  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2291  	/* The visited ports bitmask holds the list of ports offloading any
528d3f190c98c8 Vladimir Oltean   2021-02-06  2292  	 * bonding interface. Initially we mark all these ports as unvisited,
528d3f190c98c8 Vladimir Oltean   2021-02-06  2293  	 * then every time we visit a port in this bitmask, we know that it is
528d3f190c98c8 Vladimir Oltean   2021-02-06  2294  	 * the lowest numbered port, i.e. the one whose logical ID == physical
528d3f190c98c8 Vladimir Oltean   2021-02-06  2295  	 * port ID == LAG ID. So we mark as visited all further ports in the
528d3f190c98c8 Vladimir Oltean   2021-02-06  2296  	 * bitmask that are offloading the same bonding interface. This way,
528d3f190c98c8 Vladimir Oltean   2021-02-06  2297  	 * we set up the aggregation PGIDs only once per bonding interface.
528d3f190c98c8 Vladimir Oltean   2021-02-06  2298  	 */
528d3f190c98c8 Vladimir Oltean   2021-02-06  2299  	for (port = 0; port < ocelot->num_phys_ports; port++) {
528d3f190c98c8 Vladimir Oltean   2021-02-06  2300  		struct ocelot_port *ocelot_port = ocelot->ports[port];
528d3f190c98c8 Vladimir Oltean   2021-02-06  2301  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2302  		if (!ocelot_port || !ocelot_port->bond)
528d3f190c98c8 Vladimir Oltean   2021-02-06  2303  			continue;
528d3f190c98c8 Vladimir Oltean   2021-02-06  2304  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2305  		visited &= ~BIT(port);
528d3f190c98c8 Vladimir Oltean   2021-02-06  2306  	}
528d3f190c98c8 Vladimir Oltean   2021-02-06  2307  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2308  	/* Now, set PGIDs for each active LAG */
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2309  	for (lag = 0; lag < ocelot->num_phys_ports; lag++) {
16bd8173225f07 Jerry Wu          2025-12-20  2310  		struct ocelot_port *port = ocelot->ports[lag];
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2311  		int num_active_ports = 0;
16bd8173225f07 Jerry Wu          2025-12-20  2312  		struct net_device *bond;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2313  		unsigned long bond_mask;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2314  		u8 aggr_idx[16];
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2315  
16bd8173225f07 Jerry Wu          2025-12-20  2316  		if (!port || !port->bond || (visited & BIT(lag)))
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2317  			continue;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2318  
16bd8173225f07 Jerry Wu          2025-12-20  2319  		bond = port->bond;
a14e6b69f393d6 Vladimir Oltean   2022-01-07  2320  		bond_mask = ocelot_get_bond_mask(ocelot, bond);
528d3f190c98c8 Vladimir Oltean   2021-02-06  2321  
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2322  		for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
a14e6b69f393d6 Vladimir Oltean   2022-01-07  2323  			struct ocelot_port *ocelot_port = ocelot->ports[port];
a14e6b69f393d6 Vladimir Oltean   2022-01-07  2324  
16bd8173225f07 Jerry Wu          2025-12-20  2325  			if (!port)
16bd8173225f07 Jerry Wu          2025-12-20  2326  				continue;
16bd8173225f07 Jerry Wu          2025-12-20  2327  
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2328  			// Destination mask
dc96ee3730fc41 Alexandre Belloni 2018-06-26 @2329  			ocelot_write_rix(ocelot, bond_mask,
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2330  					 ANA_PGID_PGID, port);
a14e6b69f393d6 Vladimir Oltean   2022-01-07  2331  
a14e6b69f393d6 Vladimir Oltean   2022-01-07  2332  			if (ocelot_port->lag_tx_active)
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2333  				aggr_idx[num_active_ports++] = port;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2334  		}
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2335  
96b029b004942e Vladimir Oltean   2020-06-21  2336  		for_each_aggr_pgid(ocelot, i) {
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2337  			u32 ac;
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2338  
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2339  			ac = ocelot_read_rix(ocelot, ANA_PGID_PGID, i);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2340  			ac &= ~bond_mask;
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2341  			/* Don't do division by zero if there was no active
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2342  			 * port. Just make all aggregation codes zero.
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2343  			 */
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2344  			if (num_active_ports)
23ca3b727ee6b4 Vladimir Oltean   2021-02-06  2345  				ac |= BIT(aggr_idx[i % num_active_ports]);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2346  			ocelot_write_rix(ocelot, ac, ANA_PGID_PGID, i);
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2347  		}
528d3f190c98c8 Vladimir Oltean   2021-02-06  2348  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2349  		/* Mark all ports in the same LAG as visited to avoid applying
528d3f190c98c8 Vladimir Oltean   2021-02-06  2350  		 * the same config again.
528d3f190c98c8 Vladimir Oltean   2021-02-06  2351  		 */
528d3f190c98c8 Vladimir Oltean   2021-02-06 @2352  		for (port = lag; port < ocelot->num_phys_ports; port++) {
528d3f190c98c8 Vladimir Oltean   2021-02-06  2353  			struct ocelot_port *ocelot_port = ocelot->ports[port];
528d3f190c98c8 Vladimir Oltean   2021-02-06  2354  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2355  			if (!ocelot_port)
528d3f190c98c8 Vladimir Oltean   2021-02-06  2356  				continue;
528d3f190c98c8 Vladimir Oltean   2021-02-06  2357  
528d3f190c98c8 Vladimir Oltean   2021-02-06  2358  			if (ocelot_port->bond == bond)
528d3f190c98c8 Vladimir Oltean   2021-02-06  2359  				visited |= BIT(port);
528d3f190c98c8 Vladimir Oltean   2021-02-06  2360  		}
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2361  	}
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2362  }
dc96ee3730fc41 Alexandre Belloni 2018-06-26  2363  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] Prevent crash when adding interface under a lag
Posted by kernel test robot 1 month, 2 weeks ago
Hi Jerry,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.19-rc2 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jerry-Wu/Prevent-crash-when-adding-interface-under-a-lag/20251221-013514
base:   linus/master
patch link:    https://lore.kernel.org/r/tencent_9E2B81D645D04DFE191C86F128212F842B05%40qq.com
patch subject: [PATCH] Prevent crash when adding interface under a lag
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20251223/202512232301.jt5UlaM8-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251223/202512232301.jt5UlaM8-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/202512232301.jt5UlaM8-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/bitops.h:67,
                    from include/linux/log2.h:12,
                    from include/asm-generic/div64.h:55,
                    from arch/arm/include/asm/div64.h:114,
                    from include/linux/math.h:6,
                    from include/linux/math64.h:6,
                    from include/linux/jiffies.h:7,
                    from include/linux/ktime.h:25,
                    from include/linux/timer.h:6,
                    from include/linux/netdevice.h:24,
                    from include/linux/if_bridge.h:12,
                    from include/linux/dsa/ocelot.h:8,
                    from drivers/net/ethernet/mscc/ocelot.c:7:
   drivers/net/ethernet/mscc/ocelot.c: In function 'ocelot_set_aggr_pgids':
>> include/linux/find.h:586:63: error: passing argument 3 of '_find_next_bit_le' makes integer from pointer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                               ^~~~~
         |                                                               |
         |                                                               struct ocelot_port *
   arch/arm/include/asm/bitops.h:205:64: note: in definition of macro 'find_next_bit'
     205 | #define find_next_bit(p,sz,off)         _find_next_bit_le(p,sz,off)
         |                                                                ^~~
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   arch/arm/include/asm/bitops.h:167:91: note: expected 'long unsigned int' but argument is of type 'struct ocelot_port *'
     167 | unsigned long _find_next_bit_le(const unsigned long *p, unsigned long size, unsigned long offset);
         |                                                                             ~~~~~~~~~~~~~~^~~~~~
   In file included from include/linux/bitmap.h:11,
                    from include/linux/cpumask.h:11,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:63,
                    from include/linux/debugobjects.h:6,
                    from include/linux/timer.h:8:
   include/linux/find.h:586:31: error: assignment to 'struct ocelot_port *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                               ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   include/linux/find.h:586:77: warning: comparison between pointer and integer
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                                             ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   drivers/net/ethernet/mscc/ocelot.c:2323:72: error: array subscript is not an integer
    2323 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/soc/mscc/ocelot_vcap.h:9,
                    from drivers/net/ethernet/mscc/ocelot.c:13:
   include/soc/mscc/ocelot.h:923:55: error: invalid operands to binary * (have 'int' and 'struct ocelot_port *')
     923 |         __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
         |                                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2329:25: note: in expansion of macro 'ocelot_write_rix'
    2329 |                         ocelot_write_rix(ocelot, bond_mask,
         |                         ^~~~~~~~~~~~~~~~
   drivers/net/ethernet/mscc/ocelot.c:2333:62: error: assignment to 'u8' {aka 'unsigned char'} from 'struct ocelot_port *' makes integer from pointer without a cast [-Wint-conversion]
    2333 |                                 aggr_idx[num_active_ports++] = port;
         |                                                              ^
   drivers/net/ethernet/mscc/ocelot.c:2352:27: error: assignment to 'struct ocelot_port *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                           ^
   drivers/net/ethernet/mscc/ocelot.c:2352:39: warning: comparison between pointer and integer
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2353:72: error: array subscript is not an integer
    2353 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/linux/bits.h:5,
                    from include/linux/ratelimit_types.h:5,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:31,
                    from arch/arm/include/asm/bug.h:60,
                    from include/linux/ktime.h:24:
   include/vdso/bits.h:7:40: error: invalid operands to binary << (have 'long unsigned int' and 'struct ocelot_port *')
       7 | #define BIT(nr)                 (UL(1) << (nr))
         |                                        ^~
   drivers/net/ethernet/mscc/ocelot.c:2359:44: note: in expansion of macro 'BIT'
    2359 |                                 visited |= BIT(port);
         |                                            ^~~


vim +/_find_next_bit_le +586 include/linux/find.h

6b8ecb84f8f640 include/asm-generic/bitops/find.h Yury Norov 2021-08-14  584  
bc9d6635c293a2 include/linux/find.h              Yury Norov 2021-08-14  585  #define for_each_set_bit(bit, addr, size) \
fdae96a3fc7f70 include/linux/find.h              Yury Norov 2022-09-19 @586  	for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
bc9d6635c293a2 include/linux/find.h              Yury Norov 2021-08-14  587  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] Prevent crash when adding interface under a lag
Posted by kernel test robot 1 month, 2 weeks ago
Hi Jerry,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.19-rc2 next-20251219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jerry-Wu/Prevent-crash-when-adding-interface-under-a-lag/20251221-013514
base:   linus/master
patch link:    https://lore.kernel.org/r/tencent_9E2B81D645D04DFE191C86F128212F842B05%40qq.com
patch subject: [PATCH] Prevent crash when adding interface under a lag
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20251223/202512231955.Jle1VCFu-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251223/202512231955.Jle1VCFu-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/202512231955.Jle1VCFu-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/bitmap.h:11,
                    from include/linux/cpumask.h:11,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:63,
                    from include/linux/debugobjects.h:6,
                    from include/linux/timer.h:8,
                    from include/linux/netdevice.h:24,
                    from include/linux/if_bridge.h:12,
                    from include/linux/dsa/ocelot.h:8,
                    from drivers/net/ethernet/mscc/ocelot.c:7:
   drivers/net/ethernet/mscc/ocelot.c: In function 'ocelot_set_aggr_pgids':
>> include/linux/find.h:586:63: error: passing argument 3 of 'find_next_bit' makes integer from pointer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                               ^~~~~
         |                                                               |
         |                                                               struct ocelot_port *
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   include/linux/find.h:61:43: note: expected 'long unsigned int' but argument is of type 'struct ocelot_port *'
      61 |                             unsigned long offset)
         |                             ~~~~~~~~~~~~~~^~~~~~
>> include/linux/find.h:586:31: error: assignment to 'struct ocelot_port *' from 'long unsigned int' makes pointer from integer without a cast [-Wint-conversion]
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                               ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
   include/linux/find.h:586:77: warning: comparison between pointer and integer
     586 |         for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
         |                                                                             ^
   drivers/net/ethernet/mscc/ocelot.c:2322:17: note: in expansion of macro 'for_each_set_bit'
    2322 |                 for_each_set_bit(port, &bond_mask, ocelot->num_phys_ports) {
         |                 ^~~~~~~~~~~~~~~~
>> drivers/net/ethernet/mscc/ocelot.c:2323:72: error: array subscript is not an integer
    2323 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/soc/mscc/ocelot_vcap.h:9,
                    from drivers/net/ethernet/mscc/ocelot.c:13:
>> include/soc/mscc/ocelot.h:923:55: error: invalid operands to binary * (have 'int' and 'struct ocelot_port *')
     923 |         __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
         |                                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2329:25: note: in expansion of macro 'ocelot_write_rix'
    2329 |                         ocelot_write_rix(ocelot, bond_mask,
         |                         ^~~~~~~~~~~~~~~~
>> drivers/net/ethernet/mscc/ocelot.c:2333:62: error: assignment to 'u8' {aka 'unsigned char'} from 'struct ocelot_port *' makes integer from pointer without a cast [-Wint-conversion]
    2333 |                                 aggr_idx[num_active_ports++] = port;
         |                                                              ^
>> drivers/net/ethernet/mscc/ocelot.c:2352:27: error: assignment to 'struct ocelot_port *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                           ^
   drivers/net/ethernet/mscc/ocelot.c:2352:39: warning: comparison between pointer and integer
    2352 |                 for (port = lag; port < ocelot->num_phys_ports; port++) {
         |                                       ^
   drivers/net/ethernet/mscc/ocelot.c:2353:72: error: array subscript is not an integer
    2353 |                         struct ocelot_port *ocelot_port = ocelot->ports[port];
         |                                                                        ^
   In file included from include/linux/bits.h:5,
                    from include/linux/ratelimit_types.h:5,
                    from include/linux/printk.h:9,
                    from include/asm-generic/bug.h:31,
                    from arch/parisc/include/asm/bug.h:97,
                    from include/linux/ktime.h:24,
                    from include/linux/timer.h:6:
>> include/vdso/bits.h:7:40: error: invalid operands to binary << (have 'long unsigned int' and 'struct ocelot_port *')
       7 | #define BIT(nr)                 (UL(1) << (nr))
         |                                        ^~
   drivers/net/ethernet/mscc/ocelot.c:2359:44: note: in expansion of macro 'BIT'
    2359 |                                 visited |= BIT(port);
         |                                            ^~~


vim +586 include/linux/find.h

6b8ecb84f8f6401 include/asm-generic/bitops/find.h Yury Norov 2021-08-14  584  
bc9d6635c293a2a include/linux/find.h              Yury Norov 2021-08-14  585  #define for_each_set_bit(bit, addr, size) \
fdae96a3fc7f70e include/linux/find.h              Yury Norov 2022-09-19 @586  	for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)
bc9d6635c293a2a include/linux/find.h              Yury Norov 2021-08-14  587  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki