diff options
author | piaojun <piaojun@huawei.com> | 2018-08-03 05:22:20 -0400 |
---|---|---|
committer | Dominique Martinet <dominique.martinet@cea.fr> | 2018-08-12 20:34:58 -0400 |
commit | edcd9d977354304cb85aee61c2b96809edce41ed (patch) | |
tree | 6e389a241468352500b8e5f1de9a46ed21903f34 | |
parent | 23cba9cbde0bba05d772b335fe5f66aa82b9ad19 (diff) |
net/9p/trans_virtio.c: add null terminal for mount tag
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.
Link: http://lkml.kernel.org/r/5B641ECC.5030401@huawei.com
Signed-off-by: Jun Piao <piaojun@huawei.com>
Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
-rw-r--r-- | net/9p/trans_virtio.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 08264bae3f5d..7728b0acde09 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
@@ -89,10 +89,8 @@ struct virtio_chan { | |||
89 | unsigned long p9_max_pages; | 89 | unsigned long p9_max_pages; |
90 | /* Scatterlist: can be too big for stack. */ | 90 | /* Scatterlist: can be too big for stack. */ |
91 | struct scatterlist sg[VIRTQUEUE_NUM]; | 91 | struct scatterlist sg[VIRTQUEUE_NUM]; |
92 | |||
93 | int tag_len; | ||
94 | /* | 92 | /* |
95 | * tag name to identify a mount Non-null terminated | 93 | * tag name to identify a mount null terminated |
96 | */ | 94 | */ |
97 | char *tag; | 95 | char *tag; |
98 | 96 | ||
@@ -528,14 +526,15 @@ static ssize_t p9_mount_tag_show(struct device *dev, | |||
528 | { | 526 | { |
529 | struct virtio_chan *chan; | 527 | struct virtio_chan *chan; |
530 | struct virtio_device *vdev; | 528 | struct virtio_device *vdev; |
529 | int tag_len; | ||
531 | 530 | ||
532 | vdev = dev_to_virtio(dev); | 531 | vdev = dev_to_virtio(dev); |
533 | chan = vdev->priv; | 532 | chan = vdev->priv; |
533 | tag_len = strlen(chan->tag); | ||
534 | 534 | ||
535 | memcpy(buf, chan->tag, chan->tag_len); | 535 | memcpy(buf, chan->tag, tag_len + 1); |
536 | buf[chan->tag_len] = 0; | ||
537 | 536 | ||
538 | return chan->tag_len + 1; | 537 | return tag_len + 1; |
539 | } | 538 | } |
540 | 539 | ||
541 | static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); | 540 | static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); |
@@ -588,7 +587,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
588 | err = -EINVAL; | 587 | err = -EINVAL; |
589 | goto out_free_vq; | 588 | goto out_free_vq; |
590 | } | 589 | } |
591 | tag = kmalloc(tag_len, GFP_KERNEL); | 590 | tag = kzalloc(tag_len + 1, GFP_KERNEL); |
592 | if (!tag) { | 591 | if (!tag) { |
593 | err = -ENOMEM; | 592 | err = -ENOMEM; |
594 | goto out_free_vq; | 593 | goto out_free_vq; |
@@ -597,7 +596,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
597 | virtio_cread_bytes(vdev, offsetof(struct virtio_9p_config, tag), | 596 | virtio_cread_bytes(vdev, offsetof(struct virtio_9p_config, tag), |
598 | tag, tag_len); | 597 | tag, tag_len); |
599 | chan->tag = tag; | 598 | chan->tag = tag; |
600 | chan->tag_len = tag_len; | ||
601 | err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); | 599 | err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); |
602 | if (err) { | 600 | if (err) { |
603 | goto out_free_tag; | 601 | goto out_free_tag; |
@@ -660,8 +658,7 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args) | |||
660 | 658 | ||
661 | mutex_lock(&virtio_9p_lock); | 659 | mutex_lock(&virtio_9p_lock); |
662 | list_for_each_entry(chan, &virtio_chan_list, chan_list) { | 660 | list_for_each_entry(chan, &virtio_chan_list, chan_list) { |
663 | if (!strncmp(devname, chan->tag, chan->tag_len) && | 661 | if (!strcmp(devname, chan->tag)) { |
664 | strlen(devname) == chan->tag_len) { | ||
665 | if (!chan->inuse) { | 662 | if (!chan->inuse) { |
666 | chan->inuse = true; | 663 | chan->inuse = true; |
667 | found = 1; | 664 | found = 1; |