[linux-next:master 15622/16703] net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar

kernel test robot <[email protected]>
Newsgroups dev.linux.lists.oe-kbuild-all
Message-ID <[email protected]>
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   903c1cf6dff9964e71eda98a39e2e5d442050472
commit: e80456d79ec83b00a6bd44c377684b1632ccc3c7 [15622/16703] netfilter: ipset: remove need to allocate memory on delete operations
config: alpha-randconfig-r134-20260825 (https://download.01.org/0day-ci/archive/20260825/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 9.5.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260825/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)
   net/netfilter/ipset/ip_set_hash_netport.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
>> net/netfilter/ipset/ip_set_hash_netport.c:136:25: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_netport.c:136:25: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_netport.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_netport.c:356:25: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_netport.c:356:25: sparse: sparse: cast from non-scalar
--
   net/netfilter/ipset/ip_set_hash_net.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
>> net/netfilter/ipset/ip_set_hash_net.c:120:25: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_net.c:120:25: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_net.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_net.c:294:25: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_net.c:294:25: sparse: sparse: cast from non-scalar
--
   net/netfilter/ipset/ip_set_hash_ipportnet.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
>> net/netfilter/ipset/ip_set_hash_ipportnet.c:141:25: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_ipportnet.c:141:25: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_ipportnet.c: note: in included file:
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast to non-scalar
>> net/netfilter/ipset/ip_set_hash_gen.h:368:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:440:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:460:22: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_gen.h:1333:40: sparse: sparse: cast from non-scalar
   net/netfilter/ipset/ip_set_hash_ipportnet.c:401:25: sparse: sparse: cast to non-scalar
   net/netfilter/ipset/ip_set_hash_ipportnet.c:401:25: sparse: sparse: cast from non-scalar

vim +368 net/netfilter/ipset/ip_set_hash_gen.h

   343	
   344	#ifdef IP_SET_HASH_WITH_NETS
   345	/**
   346	 * mtype_add_cidr - Add a CIDR entry to hash table bookkeeping
   347	 * @set: Pointer to the ip_set
   348	 * @h: Pointer to the htype
   349	 * @cidr: The CIDR prefix length
   350	 * @n: The index of the net_prefix array to add @cidr to
   351	 *
   352	 * Performs an update if @cidr is found, otherwise performs COW-style
   353	 * allocation and replacement via RCU.
   354	 *
   355	 * Return: 0 on success, negative error code on failure.
   356	 */
   357	static int
   358	mtype_add_cidr(struct ip_set *set, struct htype *h, u8 cidr, u8 n)
   359	{
   360		int i, j, found, len = 0, ret = 0;
   361		struct net_prefixes *nets, *tmp;
   362		struct net_prefix np;
   363	
   364		spin_lock_bh(&set->lock);
   365		nets = __ipset_dereference(h->rnets[n]);
   366		/* Add in increasing prefix order, so larger cidr first */
   367		for (i = 0, found = -1; i < nets->len; i++) {
 > 368			np = READ_ONCE(nets->nets[i]);
   369			if (np.count)
   370				len++;
   371			if (found != -1) {
   372				continue;
   373			} else if (np.cidr < cidr) {
   374				found = i;
   375			} else if (np.cidr == cidr) {
   376				if (np.count < CIDR_MAX_COUNT) {
   377					np.count++;
   378					WRITE_ONCE(nets->nets[i], np);
   379				} else {
   380					ret = -EOVERFLOW;
   381				}
   382				goto unlock;
   383			}
   384		}
   385		len++;
   386		tmp = kzalloc_flex(*tmp, nets, len, GFP_ATOMIC);
   387		if (!tmp) {
   388			ret = -ENOMEM;
   389			goto unlock;
   390		}
   391	
   392		tmp->len = len;
   393		seqcount_spinlock_init(&tmp->seq, &set->lock);
   394		for (i = 0, j = 0; i < nets->len; i++) {
   395			if (i == found) {
   396				tmp->nets[j].cidr = cidr;
   397				tmp->nets[j++].count = 1;
   398			}
   399			if (!nets->nets[i].count)
   400				continue;
   401			tmp->nets[j].cidr = nets->nets[i].cidr;
   402			tmp->nets[j++].count = nets->nets[i].count;
   403		}
   404		if (found == -1) {
   405			tmp->nets[j].cidr = cidr;
   406			tmp->nets[j].count = 1;
   407		}
   408		rcu_assign_pointer(h->rnets[n], tmp);
   409		kfree_rcu(nets, rcu);
   410	unlock:
   411		spin_unlock_bh(&set->lock);
   412		return ret;
   413	}
   414	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.