Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1552061imm; Wed, 1 Aug 2018 18:58:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfMH9PnLbHW0YRgmv92pfnrYT1NwYO4FzCWf+jwbr/mwPhAeE217FSpsU9QwZFdPBTxJEWH X-Received: by 2002:a63:bf08:: with SMTP id v8-v6mr716716pgf.3.1533175087024; Wed, 01 Aug 2018 18:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533175087; cv=none; d=google.com; s=arc-20160816; b=njLF225Bo86FZFgzQ0yXkPLfNiV/i6iPAwg/unAfYvf9dl6ZC/VAyIXo1WZcpOpFZK 3jPOHL30ecD6KOr3KAGCY/PjZjDZxLvtkLTJZAsgwlxU+F6X/PeU3Nzel5/Uhinw5/gq BlZNCmgz4jKI7LYKfcgKA7hFdmbjO4X6hf1Q12VMaNJ4TfLBO62IBOdX7jlg1kESurVj WQ96tNuIvGAW28X4Hfo1zqPQ3Fw9pjUFK9fSpArqTdjs1H8N+IHv/k7krxGbzN6Lhz4I ZOt+Wktq2PSMD8m1fZSAF/XFPB/7/a7PLj5mpLw9i5E4FwDwVJ6zNm+r8TyPuFmznndN HTaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=XCa325PLIlnbF7H0zrkevjGcU1WCjWniV6Q/zRZhfqU=; b=L8IvoxghFWTvESwTnT7gjdv2/peJA6pg0ndUo9wfPPFxwWO8FDxV+HZhILMvTmESSE 8TpPGr7RoaQjdXhD37PEt8z4Bn7m+DEuY/rr+i5x7Q94zmbA3Ec1DYgkGXwWmg2HdaBe jqPe9L0L5781iSjgUqc7/QgfBc9PKrngQERfoPWXpx++ct36silRMSz0CohkRGwKr89B LRSB7E/fGJCaChquGEjh1WgF/WM9TZmwrG+bz9P1bu0tvKQbhTJVPLoOrdIg7qaR2Lkc nfqSfazd6eNtl2pSt4pfsVHt671cgCore/CHH5IqHP9eLj0wfXeN/bz0h0ILPsphWv8v CmJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12-v6si589057pfj.190.2018.08.01.18.57.28; Wed, 01 Aug 2018 18:58:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732193AbeHBDni (ORCPT + 99 others); Wed, 1 Aug 2018 23:43:38 -0400 Received: from nautica.notk.org ([91.121.71.147]:55480 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731503AbeHBDni (ORCPT ); Wed, 1 Aug 2018 23:43:38 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 22291C009; Thu, 2 Aug 2018 03:54:54 +0200 (CEST) Date: Thu, 2 Aug 2018 03:54:39 +0200 From: Dominique Martinet To: piaojun Cc: "akpm@linux-foundation.org" , Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , Greg Kurz , Linux Kernel Mailing List , v9fs-developer@lists.sourceforge.net Subject: Re: [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <20180802015439.GA27403@nautica> References: <5B6262F4.9080601@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5B6262F4.9080601@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org piaojun wrote on Thu, Aug 02, 2018: > chan->tag is Non-null terminated which will result in printing messy code > when debugging code. So we should add '\0' for tag to make the code more > convenient and robust. In addition, I drop char->tag_len to simplify the > code. Some new lines in commit message would be appreciated. That aside, I have a couple of nitpicks, but it looks good to me - thanks > > Signed-off-by: Jun Piao > --- > net/9p/trans_virtio.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c > index d422bfc..0fe9c37 100644 > --- a/net/9p/trans_virtio.c > +++ b/net/9p/trans_virtio.c > @@ -89,10 +89,8 @@ struct virtio_chan { > unsigned long p9_max_pages; > /* Scatterlist: can be too big for stack. */ > struct scatterlist sg[VIRTQUEUE_NUM]; > - > - int tag_len; > /* > - * tag name to identify a mount Non-null terminated > + * tag name to identify a mount null terminated > */ > char *tag; > > @@ -529,10 +527,9 @@ static ssize_t p9_mount_tag_show(struct device *dev, > vdev = dev_to_virtio(dev); > chan = vdev->priv; > > - memcpy(buf, chan->tag, chan->tag_len); > - buf[chan->tag_len] = 0; > + memcpy(buf, chan->tag, strlen(chan->tag) + 1); > > - return chan->tag_len + 1; > + return strlen(chan->tag) + 1; Use a local variable for strlen(chan->tag)? > } > > static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); > @@ -585,7 +582,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) > err = -EINVAL; > goto out_free_vq; > } > - tag = kmalloc(tag_len, GFP_KERNEL); > + tag = kzalloc(tag_len + 1, GFP_KERNEL); > if (!tag) { > err = -ENOMEM; > goto out_free_vq; > @@ -594,7 +591,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) > virtio_cread_bytes(vdev, offsetof(struct virtio_9p_config, tag), > tag, tag_len); > chan->tag = tag; > - chan->tag_len = tag_len; > err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); > if (err) { > goto out_free_tag; > @@ -654,8 +650,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) > > mutex_lock(&virtio_9p_lock); > list_for_each_entry(chan, &virtio_chan_list, chan_list) { > - if (!strncmp(devname, chan->tag, chan->tag_len) && > - strlen(devname) == chan->tag_len) { > + if (!strncmp(devname, chan->tag, strlen(chan->tag) + 1)) { strncmp(x, y, strlen(y)+1) is precisely what strcmp does so let's use the simpler version -- Dominique