Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp224186imm; Fri, 3 Aug 2018 02:24:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfgGbixfYBggp3HSy7go4Dh6thteMX8AwZxatl+9ovCAvE8Oi7k15vuk3ajLsS/sodeqx4/ X-Received: by 2002:a62:6948:: with SMTP id e69-v6mr3520120pfc.166.1533288274121; Fri, 03 Aug 2018 02:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533288274; cv=none; d=google.com; s=arc-20160816; b=PUrNVj7hrsi8JJXp8vxQSX7FbBt6WrW6wa+u9L/f0sUMEPadyWXRqDsUwyTMGLyRVs ouSUYN+By6q8gfDo24NY0ThJu1CwYOzYERDxclq+MJ2uwHm5F8AsLWCdF/JMA9xGs+Kw pvEmYqX7O6N5tYNeVKIfhIQgnZgJHDLlGhW9dIjz/Mfkqjq8eEzMuyPtNjuaHn1Cdui7 ern6FXNlddHrlAJg/GuICDZKyou2sSJnsrl98gTBs7mV40oma3fd0e+65vxKg/Fm3+eG wuKWcY6kfOA/1CgORGwoyBGdcf3MIWoAhz1utnqbjTzevzT8Xat2zLGrwjTMZ8S1kVlN /GiQ== 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=jjEHDIz7OTgRAPBm6/yi8adK3+3FmsEbvM0YZOh716w=; b=PePad7ZFtHDc08IpwAU5GDWXB1PTRqb9ixbDdb8nVz0B6/bP+e2UwiR+g0b6EBUGTJ RvA4Z+IXTFtM0PW0nlNHzi/SmOlRVO73zxbRrkYUjJR8n+DKcoMmXho1zrQeFiEOOdsO Dw0cqiXA31GEOZrYtUqnhzGJtMBdSS9DKF6bziPcQZifSXRcBp3+7SGYRqL3Co5DczhM Bq2pfOTJB+M+wFzvdH3vaTHvl8IJYjHRejQuZ/YzKkaG0O7OoH2pIt5pnVgaAX8L/OPY N/wONlEhVoBcaMJKdDOJqWWZJC2eWacOrHuI1dhAqaa2K63op/JR3TM9A/XIytN0xtaZ iNHA== 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 3-v6si3774882pld.36.2018.08.03.02.24.19; Fri, 03 Aug 2018 02:24:34 -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 S1732277AbeHCLSX (ORCPT + 99 others); Fri, 3 Aug 2018 07:18:23 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:45217 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728122AbeHCLSX (ORCPT ); Fri, 3 Aug 2018 07:18:23 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B4C14AE70EA69; Fri, 3 Aug 2018 17:22:52 +0800 (CST) Received: from [10.177.253.249] (10.177.253.249) by smtp.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.399.0; Fri, 3 Aug 2018 17:22:50 +0800 To: Dominique Martinet CC: "akpm@linux-foundation.org" , Greg Kurz , Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , "Linux Kernel Mailing List" , From: piaojun Subject: [PATCH v3] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <5B641ECC.5030401@huawei.com> Date: Fri, 3 Aug 2018 17:22:20 +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 | 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; --