Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1592220rdb; Mon, 8 Jan 2024 04:30:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8gFfflaNCoKgpVxP3m0wF28clH5MBBKOpB3Iyr1alQzXZ1z1t3/p5gJpIREWsZf53Zi8t X-Received: by 2002:a17:907:788e:b0:a29:8ee3:e0b7 with SMTP id ku14-20020a170907788e00b00a298ee3e0b7mr766897ejc.102.1704717041622; Mon, 08 Jan 2024 04:30:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704717041; cv=none; d=google.com; s=arc-20160816; b=idHkt0Ben9iot8Y+BLCGP59sOPUAX9IV4QjU0wSpauRkhPPEOyVWXD8uRT6jAaP5pX bmxz2KO+4HaiuUIPD3kjZ3smADqpvK7dWHuFdr4L31JUTmJydjDegd21c1Th+VAU0jne +uTPZfq6DF3Wond/xj7LrTan+7BB/ngF4jgbNICoZl6QzK8B2Od0ze/Q07SMTpZaZQIt g+ErW4plYhrAX07HE+Bgef419L8qZg1PMoBORp7dZ9PIAGgctUa8QdnQckZa8IugWe20 aBhFV7Mphj812W+vJR9pz+p010783ybYfwm5j+/i0QDbZwBksb2cfNzbvSJxETvBVOuN LEAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=2Qk/cONMeTi8MyPueCfuZHgxYxLVKYpgcx7NGclcvW4=; fh=yf6jziqQy8OTcViw3XnxwF2xCQ9/bedZToo6goLITFo=; b=sB/syXOVtMauZio7GFtDUCAlK7frgYuuPwQYzDiTTTmrGmgUYt1nuK3QF0duJFokG8 x7Ag2NTTjXS1yA3JSUPSoj1ZgoqAoyeekflvq2a9Jko7zDUtxzyxcG/5ow3To659g6ec ipVforqG7J3MFcfSg1/f2pqA+y+z4wVo+YY3xKhiXToE7oaOt6j47U5wznx/TSKTNWfo I7CeKMknVG9XKj1ip7FtvKaUYARsz8IoXouysKdUuC+pnUvtamBj7FSg9f1P1z9il3J0 JnT7fnzh3cBmbH18XYGNu8XT9XE4mTw4L8wDM5fnYGbP2/xdlEe4SMT/mykUtQ93zlQs t9Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p9AfNFur; spf=pass (google.com: domain of linux-kernel+bounces-19503-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t3-20020a17090605c300b00a26e257793esi3143527ejt.452.2024.01.08.04.30.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 04:30:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19503-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p9AfNFur; spf=pass (google.com: domain of linux-kernel+bounces-19503-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 20EA01F22B5B for ; Mon, 8 Jan 2024 12:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B08914AA9; Mon, 8 Jan 2024 12:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p9AfNFur" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55DBB405EA; Mon, 8 Jan 2024 12:28:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A78DC433C7; Mon, 8 Jan 2024 12:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704716906; bh=DIRZMWKXKKAnLBsFnFzwOy/7jeFqFxs2HaaS1MGyc68=; h=From:To:Cc:Subject:Date:From; b=p9AfNFur0i0oRt+xSkPpYUSYN3HVcK5zIbO52U2404MlddnK59eKp5pzSwMgoZQjV iiWAkdP9hRzKDwZ+oX03pjQ2WEW4JDTQ58to4nUistaO/JC41KVEkKT3fCbZ2mE3z4 EEwIX015ijGZCdzhyfJhXhbN4Rcj+HX6y/EG0uQnCouVpFrw9WbOOLP/UAMxF+IhQ3 I4jmVw6NsG2nXP2TKgxJK2N3TIkY3yzGnqRNuE6k8Wie7P3xp6h46V99s1V/7Hg3gW UIghNzUIegAgYwDI7K5oCae9Q+MdacE2KkprM2PYUY92DJizNi1yr+L6GeXfe5bT47 JK/G19yDNG4AQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stefan Hajnoczi , Suwan Kim , kernel test robot , "Michael S . Tsirkin" , Sasha Levin , jasowang@redhat.com, axboe@kernel.dk, virtualization@lists.linux.dev, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 1/5] virtio_blk: fix snprintf truncation compiler warning Date: Mon, 8 Jan 2024 07:28:12 -0500 Message-ID: <20240108122823.2090312-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.71 Content-Transfer-Encoding: 8bit From: Stefan Hajnoczi [ Upstream commit b8e0792449928943c15d1af9f63816911d139267 ] Commit 4e0400525691 ("virtio-blk: support polling I/O") triggers the following gcc 13 W=1 warnings: drivers/block/virtio_blk.c: In function ‘init_vq’: drivers/block/virtio_blk.c:1077:68: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Wformat-truncation=] 1077 | snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%d", i); | ^~ drivers/block/virtio_blk.c:1077:58: note: directive argument in the range [-2147483648, 65534] 1077 | snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%d", i); | ^~~~~~~~~~~~~ drivers/block/virtio_blk.c:1077:17: note: ‘snprintf’ output between 11 and 21 bytes into a destination of size 16 1077 | snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%d", i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is a false positive because the lower bound -2147483648 is incorrect. The true range of i is [0, num_vqs - 1] where 0 < num_vqs < 65536. The code mixes int, unsigned short, and unsigned int types in addition to using "%d" for an unsigned value. Use unsigned short and "%u" consistently to solve the compiler warning. Cc: Suwan Kim Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202312041509.DIyvEt9h-lkp@intel.com/ Signed-off-by: Stefan Hajnoczi Message-Id: <20231204140743.1487843-1-stefanha@redhat.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/block/virtio_blk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index efa5535a8e1d8..3124837aa406f 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -609,12 +609,12 @@ static void virtblk_config_changed(struct virtio_device *vdev) static int init_vq(struct virtio_blk *vblk) { int err; - int i; + unsigned short i; vq_callback_t **callbacks; const char **names; struct virtqueue **vqs; unsigned short num_vqs; - unsigned int num_poll_vqs; + unsigned short num_poll_vqs; struct virtio_device *vdev = vblk->vdev; struct irq_affinity desc = { 0, }; @@ -658,13 +658,13 @@ static int init_vq(struct virtio_blk *vblk) for (i = 0; i < num_vqs - num_poll_vqs; i++) { callbacks[i] = virtblk_done; - snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req.%d", i); + snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req.%u", i); names[i] = vblk->vqs[i].name; } for (; i < num_vqs; i++) { callbacks[i] = NULL; - snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%d", i); + snprintf(vblk->vqs[i].name, VQ_NAME_LEN, "req_poll.%u", i); names[i] = vblk->vqs[i].name; } -- 2.43.0