Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1863171rda; Tue, 24 Oct 2023 05:54:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwg4G4Ic+hmC3e1cim0FOwfiq5QJxGcAPUuz9bTLWO8Y9aUM2kHHBBYAWlLzjSmLo9jXTR X-Received: by 2002:a05:6300:808b:b0:17e:2ff:13c6 with SMTP id ap11-20020a056300808b00b0017e02ff13c6mr2499324pzc.8.1698152050257; Tue, 24 Oct 2023 05:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698152050; cv=none; d=google.com; s=arc-20160816; b=aKvhmGsdz3g91x6FFNOXpbAt0X0HXnuL2ovWIEsOfbCOy6U10j+0sSFJ12JrbgJHKD 6Q83HDq2Ci7uOKoam7g/2nBPpjaa5a2dnxAMCi3pyt2LgJa4NCW8O1OOLxVPsFnVyxIs 8cL0nf8+GzwuaK6PqTB4nBpBtKnyoOMYS7Y080Q7BxjpCTtcvBMPbzQRK0nfnWaAX4FO XRhjzcLO8jhf4mmFjZwRWTGxP4GxKINurwsVZSjRqf/Qg9gDFb2cbm9aJjrmQc/gb02L YoE8sImaFVpVIUhKV8q1vVM9PxGuVxVCJkqgIGEGD2rCh27zHRPkiOZnkbcNGvnVUAJ4 4L6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RmLarUo7D/BXs7zx6nAos+1yGhe5BOkCbiwZbs9L0h0=; fh=VJW9491tK0R+YBwOiKNWG35PMJwPHEp1B6HHJm09Wx8=; b=01hjC3QP8UMfXW6f9gHypraIUp1EFBH0/vdnegjEQDhWW4PJfcjAAc9Ttx2cHYDITE WKofFx0QdsCQB1o/Jp1yNtv7YRIUoRZ3EvxTtB/3qGNxbWIcHwZhPfiWyMQMQyV9S2uN gl1okhmP7UtFk1nOfOHsYtYOQ0e1auBSbt1tNkOqWpfkyJcA4anatBXV3IqGZJLQeimO 4n0GAEZTa5jPbOXKK+aGusRioDuomNtTxZPQPGG1YORapqsgQpzzDrPnAVQzHUaFhlU/ eTPRQAsFjGcwwrA12p+4z1imZbetO+ufyWivWW1xsQ1ARjzlRq7pucaQoZxKUaoL+Tp4 Mrew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=lNfXVsDO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id r27-20020a638f5b000000b005898e10f9c4si8424120pgn.203.2023.10.24.05.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 05:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=lNfXVsDO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E250E80411A6; Tue, 24 Oct 2023 05:54:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234423AbjJXMx6 (ORCPT + 99 others); Tue, 24 Oct 2023 08:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234527AbjJXMx4 (ORCPT ); Tue, 24 Oct 2023 08:53:56 -0400 Received: from kylie.crudebyte.com (kylie.crudebyte.com [5.189.157.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8EC90 for ; Tue, 24 Oct 2023 05:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Content-Type:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Content-ID:Content-Description; bh=RmLarUo7D/BXs7zx6nAos+1yGhe5BOkCbiwZbs9L0h0=; b=lNfXVsDOXtd9alDSiEMenIba7Z OvnWE4Z/42OjBlG3VvSN5rl5TIfiOf5zhT6qe9txA17Kvv6YKEsDXjtmCS2yD51hAORCj5SdQNKb5 fBdpheuDP3dOFNuyBoOuZpOcJcLYtoXihXdiF5145mWIQRhQoellcKtUtXdywJjTpcXw4HbfXzUPi JLM9x5kZ5pkTpKBIijZfpthvQ3GxkBXf9zA+zDCOg4q++vTUSVBRlDr5r3qk2QFyRtBW6W+JirIlj Z1SUpIDiKFzq+M/hu9pvgM0HVaGX56mwBQMsjCyDHd8GO/tTCvE2C29WB2TDk/YIgOq0QvqtPMQIN VYurRKQIhhr4X8l+zAsPo3hLUh4dAVBktigpJQ6cubiuNZXzl1Goz1KusRnlvtKmJPI01/aOFfdLm cgu5RTxGGg+nb6blgSHTsv+dlIOWkWaG3vvxd387x2H+8jj8pEbArfX3iJLueWmiCD/BywGKlZ9lz 38XO/eZ9MQYp+oFkPRzkLz5FL0Pd8tonKanpEgnm5nLbCB1u9J2QkaCF5o3MZLf8+xyCK1xvUU55c 8bHXoGI/ZTAxFEq3dYrguPlnBKwM13Jb1TD/+I4qciq3+joIi0VqekZbx/pLPHf6qg42ZX33TOv1L KRkyFLQvXuC5zQ5OSs1fk2Ak4EmcfPELXEpPmwJqg=; From: Christian Schoenebeck To: v9fs@lists.linux.dev, ericvh@kernel.org, Dominique Martinet Cc: lucho@ionkov.net, linux-kernel@vger.kernel.org, Dominique Martinet Subject: Re: [PATCH 3/3] 9p/net: xen: fix false positive printf format overflow warning Date: Tue, 24 Oct 2023 14:52:53 +0200 Message-ID: <4016006.DBIyO7nNK6@silver> In-Reply-To: <20231023233704.1185154-4-asmadeus@codewreck.org> References: <20231023233704.1185154-1-asmadeus@codewreck.org> <20231023233704.1185154-4-asmadeus@codewreck.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 05:54:07 -0700 (PDT) On Tuesday, October 24, 2023 1:37:04 AM CEST Dominique Martinet wrote: > Use a local variable to make the compiler happy about this warning: > net/9p/trans_xen.c: In function =E2=80=98xen_9pfs_front_changed=E2=80=99: > net/9p/trans_xen.c:444:39: warning: =E2=80=98%d=E2=80=99 directive writin= g between 1 and 11 bytes into a region of size 8 [-Wformat-overflow=3D] > 444 | sprintf(str, "ring-ref%d", i); > | ^~ > In function =E2=80=98xen_9pfs_front_init=E2=80=99, > inlined from =E2=80=98xen_9pfs_front_changed=E2=80=99 at net/9p/trans= _xen.c:516:8, > inlined from =E2=80=98xen_9pfs_front_changed=E2=80=99 at net/9p/trans= _xen.c:504:13: > net/9p/trans_xen.c:444:30: note: directive argument in the range [-214748= 3644, 2147483646] > 444 | sprintf(str, "ring-ref%d", i); > | ^~~~~~~~~~~~ > net/9p/trans_xen.c:444:17: note: =E2=80=98sprintf=E2=80=99 output between= 10 and 20 bytes into a destination of size 16 > 444 | sprintf(str, "ring-ref%d", i); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > net/9p/trans_xen.c: In function =E2=80=98xen_9pfs_front_changed=E2=80=99: > net/9p/trans_xen.c:450:45: warning: =E2=80=98%d=E2=80=99 directive writin= g between 1 and 11 bytes into a region of size 2 [-Wformat-overflow=3D] > 450 | sprintf(str, "event-channel-%d", i); > | ^~ > In function =E2=80=98xen_9pfs_front_init=E2=80=99, > inlined from =E2=80=98xen_9pfs_front_changed=E2=80=99 at net/9p/trans= _xen.c:516:8, > inlined from =E2=80=98xen_9pfs_front_changed=E2=80=99 at net/9p/trans= _xen.c:504:13: > net/9p/trans_xen.c:450:30: note: directive argument in the range [-214748= 3644, 2147483646] > 450 | sprintf(str, "event-channel-%d", i); > | ^~~~~~~~~~~~~~~~~~ > net/9p/trans_xen.c:450:17: note: =E2=80=98sprintf=E2=80=99 output between= 16 and 26 bytes into a destination of size 16 > 450 | sprintf(str, "event-channel-%d", i); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >=20 > There is no change in logic: there only are a constant number of rings, > and there also already is a BUILD_BUG_ON that checks if that constant > goes over 9 as anything bigger would no longer fit the event-channel-%d > destination size. >=20 > In theory having that size as part of the struct means it could be > modified by another thread and makes the compiler lose track of possible > values for 'i' here, using a local variable makes it happy. Or ... what about dropping struct's 'num_rings' member and using the consta= nt XEN_9PFS_NUM_RINGS everywhere instead? As this is really a compile-time val= ue after all. > Signed-off-by: Dominique Martinet > --- > While looking at warnings with W=3D1, I noticed this one in net/9p. >=20 > This is silly but shouldn't hurt, num_rings is never changed so there is > no risk of introducing a race here, it's just helping the compiler a > bit. >=20 > net/9p is also now warning-free at W=3D1 >=20 > net/9p/trans_xen.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) >=20 > diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c > index 1fffe2bed5b0..79e91f31a84a 100644 > --- a/net/9p/trans_xen.c > +++ b/net/9p/trans_xen.c > @@ -382,7 +382,7 @@ static int xen_9pfs_front_init(struct xenbus_device *= dev) > struct xenbus_transaction xbt; > struct xen_9pfs_front_priv *priv =3D dev_get_drvdata(&dev->dev); > char *versions, *v; > - unsigned int max_rings, max_ring_order, len =3D 0; > + unsigned int num_rings, max_rings, max_ring_order, len =3D 0; > =20 > versions =3D xenbus_read(XBT_NIL, dev->otherend, "versions", &len); > if (IS_ERR(versions)) > @@ -408,15 +408,15 @@ static int xen_9pfs_front_init(struct xenbus_device= *dev) > if (p9_xen_trans.maxsize > XEN_FLEX_RING_SIZE(max_ring_order)) > p9_xen_trans.maxsize =3D XEN_FLEX_RING_SIZE(max_ring_order) / 2; > =20 > - priv->num_rings =3D XEN_9PFS_NUM_RINGS; > - priv->rings =3D kcalloc(priv->num_rings, sizeof(*priv->rings), > + num_rings =3D priv->num_rings =3D XEN_9PFS_NUM_RINGS; > + priv->rings =3D kcalloc(num_rings, sizeof(*priv->rings), > GFP_KERNEL); > if (!priv->rings) { > kfree(priv); > return -ENOMEM; > } > =20 > - for (i =3D 0; i < priv->num_rings; i++) { > + for (i =3D 0; i < num_rings; i++) { > priv->rings[i].priv =3D priv; > ret =3D xen_9pfs_front_alloc_dataring(dev, &priv->rings[i], > max_ring_order); > @@ -434,10 +434,11 @@ static int xen_9pfs_front_init(struct xenbus_device= *dev) > if (ret) > goto error_xenbus; > ret =3D xenbus_printf(xbt, dev->nodename, "num-rings", "%u", > - priv->num_rings); > + num_rings); > if (ret) > goto error_xenbus; > - for (i =3D 0; i < priv->num_rings; i++) { > + > + for (i =3D 0; i < num_rings; i++) { > char str[16]; > =20 > BUILD_BUG_ON(XEN_9PFS_NUM_RINGS > 9); >=20