Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2125604imm; Thu, 2 Aug 2018 06:41:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd9MUTU8+LNJTSF083I7Dmwc68Rpq6zp9DfM9h4PBtnNeAs3uI6cMw9Ams+lJP+drf/6vtV X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr2492660plb.248.1533217292540; Thu, 02 Aug 2018 06:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533217292; cv=none; d=google.com; s=arc-20160816; b=bmUGSQd7+lctA7v1UKc2oGluBQox7aJ6GGPg9lvSZN7oM+onlrRcK/RqsqB9vNfwiB rvO2K2k/aX0A90eGWCugexkiVZ8g1ylHz0uKF45VAVHaEsJkpqQS/J/REYwilT3/oEv4 0pZK9PsL0+BsesvgB1Pe0JdL5/gxczkvtDRJIIy87AYHSQK53danpwfO0UgTcS9ncNoy mC2JK9ekSO7wPh1JekW47jlfWlSNSqi6GcZeyI90ub6wBdTASEoA+YLMWDmXDqkiMTqJ 8tuJSYAC1LzdqYjyKrFci/Wum8I8k+HZofUejWyRhfkPCieDkXlO4rrf72oH56lTaqUC ADMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=AS2NpppW7LYGDzguFjTpNs0YMA+Ye9VrdktDa1x8osc=; b=m+Xf25HRTcWZnfbv3bHi9Qk8EGUxSx+IHjkhOnTlpT6pPWdDNUWRnSbBHKd+uehLgR ddwoKMEogBUsmHurYx2Bwy2VJY+lPwpKyLJtDq1Tb+K/KPxamhDIASZEWQsbKCUWIEzs QOkorBjQxU1cBqS0mEZqePkUoMPYyezArZcnfX1QjrJAociVUrPCVRDi8r/PhDbVMq1W kTK2EwrQunfEfI3fGybjH7Ax/yHY4DAHXFsLBDmaeYIsDuPQO7A3pLal0AP5cxgSm215 erWT6Eg7mqWjgVlWAlKI1VQlOYoB/bv6K+Ulv1N2dtY1dQiZx7HkKNN18tdwTHHJ9sFI pxLw== 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 h9-v6si2176564pfh.240.2018.08.02.06.41.18; Thu, 02 Aug 2018 06:41:32 -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 S2387620AbeHBPbi (ORCPT + 99 others); Thu, 2 Aug 2018 11:31:38 -0400 Received: from 15.mo6.mail-out.ovh.net ([188.165.39.161]:51069 "EHLO 15.mo6.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387527AbeHBPbi (ORCPT ); Thu, 2 Aug 2018 11:31:38 -0400 Received: from player698.ha.ovh.net (unknown [10.109.143.238]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 4C928172E27 for ; Thu, 2 Aug 2018 15:23:49 +0200 (CEST) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player698.ha.ovh.net (Postfix) with ESMTPSA id 898B75200B5; Thu, 2 Aug 2018 15:23:40 +0200 (CEST) Date: Thu, 2 Aug 2018 15:23:39 +0200 From: Greg Kurz To: piaojun Cc: Dominique Martinet , Latchesar Ionkov , Eric Van Hensbergen , Linux Kernel Mailing List , v9fs-developer@lists.sourceforge.net, Ron Minnich Subject: Re: [V9fs-developer] [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <20180802152339.194c2820@bahia.lan> In-Reply-To: <5B62658A.3010605@huawei.com> References: <5B6262F4.9080601@huawei.com> <20180802015439.GA27403@nautica> <5B62658A.3010605@huawei.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 424464266746960358 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtiedrleeggdeigecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2 Aug 2018 09:59:38 +0800 piaojun wrote: > Hi Dominique, > > On 2018/8/2 9:54, Dominique Martinet wrote: > > 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)? > > > Yes, local variable looks better. > > >> } > >> > >> 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 > > > strcmp looks simpler, and I will wait for a while to hear more > suggestions, and then post another patch for these fixes. > Nothing more to add. Please go ahead. > Thanks, > Jun > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > V9fs-developer mailing list > V9fs-developer@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/v9fs-developer