mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* drivers/net/virtio_net.c:6456:36: warning: 'sprintf' may write a terminating nul past the end of the destination
@ 2026-07-02  4:44 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2026-07-02  4:44 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: oe-kbuild-all, linux-kernel

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   4a50a141f05a8d1737661b19ee22ff8455b94409
commit: e7d4c1c5a54648fd5b787a4a0f81521ec7260bcd virtio: introduce extended features
date:   12 months ago
config: arm64-randconfig-002-20260702 (https://download.01.org/0day-ci/archive/20260702/202607021239.0UXE4ICC-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260702/202607021239.0UXE4ICC-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
| Fixes: e7d4c1c5a546 ("virtio: introduce extended features")
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202607021239.0UXE4ICC-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/net/virtio_net.c: In function 'virtnet_probe':
>> drivers/net/virtio_net.c:6456:36: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
      sprintf(vi->rq[i].name, "input.%u", i);
                                       ^
   drivers/net/virtio_net.c:6456:3: note: 'sprintf' output between 8 and 17 bytes into a destination of size 16
      sprintf(vi->rq[i].name, "input.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/net/virtio_net.c:6457:35: warning: '%u' directive writing between 1 and 10 bytes into a region of size 9 [-Wformat-overflow=]
      sprintf(vi->sq[i].name, "output.%u", i);
                                      ^~
   drivers/net/virtio_net.c:6457:27: note: directive argument in the range [0, 2147483647]
      sprintf(vi->sq[i].name, "output.%u", i);
                              ^~~~~~~~~~~
   drivers/net/virtio_net.c:6457:3: note: 'sprintf' output between 9 and 18 bytes into a destination of size 16
      sprintf(vi->sq[i].name, "output.%u", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/sprintf +6456 drivers/net/virtio_net.c

d85b758f72b05a Michael S. Tsirkin 2017-03-09  6415  
986a4f4d452dec Jason Wang         2012-12-07  6416  static int virtnet_find_vqs(struct virtnet_info *vi)
3f9c10b0d478a3 Amit Shah          2011-12-22  6417  {
c2c6325e1645b5 Jiri Pirko         2024-07-08  6418  	struct virtqueue_info *vqs_info;
986a4f4d452dec Jason Wang         2012-12-07  6419  	struct virtqueue **vqs;
e3fe8d28c67bf6 Zhu Yanjun         2024-01-04  6420  	int ret = -ENOMEM;
e3fe8d28c67bf6 Zhu Yanjun         2024-01-04  6421  	int total_vqs;
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6422  	bool *ctx;
e3fe8d28c67bf6 Zhu Yanjun         2024-01-04  6423  	u16 i;
986a4f4d452dec Jason Wang         2012-12-07  6424  
986a4f4d452dec Jason Wang         2012-12-07  6425  	/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
986a4f4d452dec Jason Wang         2012-12-07  6426  	 * possible N-1 RX/TX queue pairs used in multiqueue mode, followed by
986a4f4d452dec Jason Wang         2012-12-07  6427  	 * possible control vq.
986a4f4d452dec Jason Wang         2012-12-07  6428  	 */
986a4f4d452dec Jason Wang         2012-12-07  6429  	total_vqs = vi->max_queue_pairs * 2 +
986a4f4d452dec Jason Wang         2012-12-07  6430  		    virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ);
986a4f4d452dec Jason Wang         2012-12-07  6431  
986a4f4d452dec Jason Wang         2012-12-07  6432  	/* Allocate space for find_vqs parameters */
6396bb221514d2 Kees Cook          2018-06-12  6433  	vqs = kcalloc(total_vqs, sizeof(*vqs), GFP_KERNEL);
986a4f4d452dec Jason Wang         2012-12-07  6434  	if (!vqs)
986a4f4d452dec Jason Wang         2012-12-07  6435  		goto err_vq;
c2c6325e1645b5 Jiri Pirko         2024-07-08  6436  	vqs_info = kcalloc(total_vqs, sizeof(*vqs_info), GFP_KERNEL);
c2c6325e1645b5 Jiri Pirko         2024-07-08  6437  	if (!vqs_info)
c2c6325e1645b5 Jiri Pirko         2024-07-08  6438  		goto err_vqs_info;
192f68cf35f5ee Jason Wang         2017-07-19  6439  	if (!vi->big_packets || vi->mergeable_rx_bufs) {
6396bb221514d2 Kees Cook          2018-06-12  6440  		ctx = kcalloc(total_vqs, sizeof(*ctx), GFP_KERNEL);
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6441  		if (!ctx)
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6442  			goto err_ctx;
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6443  	} else {
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6444  		ctx = NULL;
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6445  	}
986a4f4d452dec Jason Wang         2012-12-07  6446  
986a4f4d452dec Jason Wang         2012-12-07  6447  	/* Parameters for control virtqueue, if any */
986a4f4d452dec Jason Wang         2012-12-07  6448  	if (vi->has_cvq) {
c2c6325e1645b5 Jiri Pirko         2024-07-08  6449  		vqs_info[total_vqs - 1].name = "control";
986a4f4d452dec Jason Wang         2012-12-07  6450  	}
986a4f4d452dec Jason Wang         2012-12-07  6451  
986a4f4d452dec Jason Wang         2012-12-07  6452  	/* Allocate/initialize parameters for send/receive virtqueues */
986a4f4d452dec Jason Wang         2012-12-07  6453  	for (i = 0; i < vi->max_queue_pairs; i++) {
c2c6325e1645b5 Jiri Pirko         2024-07-08  6454  		vqs_info[rxq2vq(i)].callback = skb_recv_done;
c2c6325e1645b5 Jiri Pirko         2024-07-08  6455  		vqs_info[txq2vq(i)].callback = skb_xmit_done;
e3fe8d28c67bf6 Zhu Yanjun         2024-01-04 @6456  		sprintf(vi->rq[i].name, "input.%u", i);
e3fe8d28c67bf6 Zhu Yanjun         2024-01-04  6457  		sprintf(vi->sq[i].name, "output.%u", i);
c2c6325e1645b5 Jiri Pirko         2024-07-08  6458  		vqs_info[rxq2vq(i)].name = vi->rq[i].name;
c2c6325e1645b5 Jiri Pirko         2024-07-08  6459  		vqs_info[txq2vq(i)].name = vi->sq[i].name;
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6460  		if (ctx)
c2c6325e1645b5 Jiri Pirko         2024-07-08  6461  			vqs_info[rxq2vq(i)].ctx = true;
986a4f4d452dec Jason Wang         2012-12-07  6462  	}
986a4f4d452dec Jason Wang         2012-12-07  6463  
6c85d6b653caeb Jiri Pirko         2024-07-08  6464  	ret = virtio_find_vqs(vi->vdev, total_vqs, vqs, vqs_info, NULL);
986a4f4d452dec Jason Wang         2012-12-07  6465  	if (ret)
986a4f4d452dec Jason Wang         2012-12-07  6466  		goto err_find;
3f9c10b0d478a3 Amit Shah          2011-12-22  6467  
986a4f4d452dec Jason Wang         2012-12-07  6468  	if (vi->has_cvq) {
986a4f4d452dec Jason Wang         2012-12-07  6469  		vi->cvq = vqs[total_vqs - 1];
986a4f4d452dec Jason Wang         2012-12-07  6470  		if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN))
f646968f8f7c62 Patrick McHardy    2013-04-19  6471  			vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
986a4f4d452dec Jason Wang         2012-12-07  6472  	}
3f9c10b0d478a3 Amit Shah          2011-12-22  6473  
986a4f4d452dec Jason Wang         2012-12-07  6474  	for (i = 0; i < vi->max_queue_pairs; i++) {
986a4f4d452dec Jason Wang         2012-12-07  6475  		vi->rq[i].vq = vqs[rxq2vq(i)];
d85b758f72b05a Michael S. Tsirkin 2017-03-09  6476  		vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq);
986a4f4d452dec Jason Wang         2012-12-07  6477  		vi->sq[i].vq = vqs[txq2vq(i)];
986a4f4d452dec Jason Wang         2012-12-07  6478  	}
3f9c10b0d478a3 Amit Shah          2011-12-22  6479  
2fa3c8a8b23041 Tonghao Zhang      2018-05-31  6480  	/* run here: ret == 0. */
3f9c10b0d478a3 Amit Shah          2011-12-22  6481  
3f9c10b0d478a3 Amit Shah          2011-12-22  6482  
986a4f4d452dec Jason Wang         2012-12-07  6483  err_find:
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6484  	kfree(ctx);
d45b897b11eaf9 Michael S. Tsirkin 2017-03-06  6485  err_ctx:
c2c6325e1645b5 Jiri Pirko         2024-07-08  6486  	kfree(vqs_info);
c2c6325e1645b5 Jiri Pirko         2024-07-08  6487  err_vqs_info:
986a4f4d452dec Jason Wang         2012-12-07  6488  	kfree(vqs);
986a4f4d452dec Jason Wang         2012-12-07  6489  err_vq:
986a4f4d452dec Jason Wang         2012-12-07  6490  	return ret;
3f9c10b0d478a3 Amit Shah          2011-12-22  6491  }
986a4f4d452dec Jason Wang         2012-12-07  6492  

:::::: The code at line 6456 was first introduced by commit
:::::: e3fe8d28c67bf6c291e920c6d04fa22afa14e6e4 virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings

:::::: TO: Zhu Yanjun <yanjun.zhu@linux.dev>
:::::: CC: Jakub Kicinski <kuba@kernel.org>

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-02  4:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-02  4:44 drivers/net/virtio_net.c:6456:36: warning: 'sprintf' may write a terminating nul past the end of the destination kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®