Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1548681imm; Wed, 1 Aug 2018 18:53:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeUA64ik+iTfUNceo0FWbINCYeNiG+ktUXaGG6RdJlgUOFLYe2a3Wpt2ej/hXiocoYyrZ2F X-Received: by 2002:a62:68c3:: with SMTP id d186-v6mr815896pfc.70.1533174782477; Wed, 01 Aug 2018 18:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533174782; cv=none; d=google.com; s=arc-20160816; b=Zgv9/tOCrMuDEGPlRzGYlkzr0PMqPmG6W2jvzSVhutb3ug0ormu098LarIX8Q4uH49 U9wN8iCa5nRP9Nt4yb3OFCHxjSChiag6yg8M/KcbXigNQhYN91NxBiSTWBm4BVLijzqg jZnowfNIS9pdXH1wJGAVp4JfAl7iMdsw9KFZW3un3OR/qEFNDoLMlHelWT2ETfRgDQO2 UAX47e+v/wqqYvxhqB0972IIlD7k5C9GBngKiOQxQZz2Fvx4sRlLa2xM5V7uXaQ2W+bI g/Hw4CrmWxM7eqVRwB6sGlv4cVhqgKsEJ40Xxi0+Znpjgui2NeWknMrnJr37wEJDZf2t bjbA== 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 :user-agent:date:message-id:subject:from:cc:to :arc-authentication-results; bh=pBWdKwM/DVOcnBZfD76D05Mrm124dnIXDMn3BXKylhE=; b=nJi52DlrDdEIMXxWAIJqc6or2PtM6H+2oGgDWaj9rDm7+kfdM3VCDgWs17n3X7XTLZ JakNRxWU7QxpiX7SOjtprQGV8wFbOGq+skizCmTQKX1WTYIrjd/xLR6B/aULprmpbjki hwCY4EuERJGBQkmlnmCCbODz7+p2xwmJhSEKMWtA5ib6P3zo5vpS7i1mkK1shpuvSjVt KewNn+NwjtHQ7D5s3s2BbFnKfi2w236kC06prgJkczdpuXza/TYUxnnwWzzHRI0P+Fd9 tHyZ8JQ5q/NdV/aGGQU/dKsWSAuCvKvUPOZPOPd9in7XckIFHs/BG5ku9vc1q0OuZe/A YAMw== 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 15-v6si461015pld.157.2018.08.01.18.52.24; Wed, 01 Aug 2018 18:53:02 -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 S1732358AbeHBDi2 (ORCPT + 99 others); Wed, 1 Aug 2018 23:38:28 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:53189 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725937AbeHBDi1 (ORCPT ); Wed, 1 Aug 2018 23:38:27 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 036182229E616; Thu, 2 Aug 2018 09:49:43 +0800 (CST) Received: from [10.177.253.249] (10.177.253.249) by smtp.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.399.0; Thu, 2 Aug 2018 09:49:43 +0800 To: Dominique Martinet CC: "akpm@linux-foundation.org" , "Eric Van Hensbergen" , Ron Minnich , "Latchesar Ionkov" , Greg Kurz , "Linux Kernel Mailing List" , From: piaojun Subject: [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <5B6262F4.9080601@huawei.com> Date: Thu, 2 Aug 2018 09:48:36 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.253.249] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; } 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)) { if (!chan->inuse) { chan->inuse = true; found = 1; --