Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp244559imm; Fri, 3 Aug 2018 02:45:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcmDEVQQDlHb0BOSdFYf1sYMLtrBSmRxUww5OgKFCsDhF1dvgJFdUI1p0VYPjiXSBRU/shc X-Received: by 2002:a62:229a:: with SMTP id p26-v6mr3610672pfj.53.1533289501754; Fri, 03 Aug 2018 02:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533289501; cv=none; d=google.com; s=arc-20160816; b=uGHH1zyFKs/CwQekXiwt5woUE3ryeSonGfJakrRphE6D0Yet+YDnv1wd2uxrpGWN6P yuhuvCfhk66k6cixYHmmHo1+zU2sXC7zHK+ZTs6NBOrey8JRpuTM48G1+JFET223XIpq 9f8XhOGDhKaSWbBKVglmj/4ZHvZ39GmvS/9nwPKKHXFzeI/5JGBVwAW3XBzSsM6Sjm94 4WjZKoSxtFSHdQ8oeW40ClOJM9PuPEdbEorUaPDUDm5IVDxKRFxZWQd6xinYZpxG892Q 05D3eMpfLfn+Hbrin8A8Cd4LSEf774Gve/c3UzSQp5DWc7zOoFw7atJ7xVvmV2zeI3nP fN9Q== 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=UYiqjyGRYddBjQTp4+h6dj+1gA1bX/zJGvVfXqj4Bm0=; b=iPdzVZHnIxh/8ZpQHnvIi1Ha5JATWLMu7XWe/QUC/2XrY0hiCMDFbT/sfOmd/rqNvj zqZ3YwP0Q/M0B5dUrx27SvUi8jGXGc0H92/hYqJus9WD62EZ89HTYElLsQw+oB5IjfHv TfZzJMfU/f249sZPmgcsWxIy2yo63tZH4e4MUvE/DpZc3cPKOUWXLOZXVGpt+zSijF+g cynIS+gIZw7hFu5R5B6vMTLe3tOqWBRrkWnKvj+voHvz8M2CvoqjsqgjYCPvsfs3WANm c3vpRpBuxI6BxDiwEdB5ibjWw7I/YKD6xYM9l7E+WVXe/sImxNgbCB4jbBMII+k3jtNB ZiTg== 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 f1-v6si3848335plm.375.2018.08.03.02.44.47; Fri, 03 Aug 2018 02:45:01 -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 S1732561AbeHCLio (ORCPT + 99 others); Fri, 3 Aug 2018 07:38:44 -0400 Received: from nautica.notk.org ([91.121.71.147]:37063 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732522AbeHCLio (ORCPT ); Fri, 3 Aug 2018 07:38:44 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 36880C009; Fri, 3 Aug 2018 11:43:12 +0200 (CEST) Date: Fri, 3 Aug 2018 11:42:57 +0200 From: Dominique Martinet To: piaojun Cc: "akpm@linux-foundation.org" , Greg Kurz , Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , Linux Kernel Mailing List , v9fs-developer@lists.sourceforge.net Subject: Re: [PATCH v3] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <20180803094257.GA21285@nautica> References: <5B641ECC.5030401@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5B641ECC.5030401@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 Fri, Aug 03, 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. LGTM, I'll pick this up. Thanks for the rework > Signed-off-by: Jun Piao > --- > net/9p/trans_virtio.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c > index d422bfc..46a5ab2 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; > > @@ -525,14 +523,15 @@ static ssize_t p9_mount_tag_show(struct device *dev, > { > struct virtio_chan *chan; > struct virtio_device *vdev; > + int tag_len; > > vdev = dev_to_virtio(dev); > chan = vdev->priv; > + tag_len = strlen(chan->tag); > > - memcpy(buf, chan->tag, chan->tag_len); > - buf[chan->tag_len] = 0; > + memcpy(buf, chan->tag, tag_len + 1); > > - return chan->tag_len + 1; > + return tag_len + 1; > } > > static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); > @@ -585,7 +584,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 +593,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 +652,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 (!strcmp(devname, chan->tag)) { > if (!chan->inuse) { > chan->inuse = true; > found = 1; > --