linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: piaojun <piaojun@huawei.com>
To: Greg Kurz <groug@kaod.org>
Cc: Dominique Martinet <asmadeus@codewreck.org>,
	Latchesar Ionkov <lucho@ionkov.net>,
	Eric Van Hensbergen <ericvh@gmail.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	<v9fs-developer@lists.sourceforge.net>,
	Ron Minnich <rminnich@sandia.gov>
Subject: Re: [V9fs-developer] [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag
Date: Fri, 3 Aug 2018 09:45:50 +0800	[thread overview]
Message-ID: <5B63B3CE.3040601@huawei.com> (raw)
In-Reply-To: <20180802152339.194c2820@bahia.lan>

Hi Greg and Dominique,

We'd better reach an agreement about the patch fix. In my opinion,
replacing strlen(chan->tag) with a local variable sounds reasonable, and
changing strncmp to strcmp may be little beneficial, as strcmp is more
dangerours such as buffer-flow. So I'd like to hear your suggestion for
the next version of the patch, or this patch is good enough?

Thanks,
Jun

On 2018/8/2 21:23, Greg Kurz wrote:
> On Thu, 2 Aug 2018 09:59:38 +0800
> piaojun <piaojun@huawei.com> 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 <piaojun@huawei.com>
>>>> ---
>>>>  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
> 
> .
> 

  reply	other threads:[~2018-08-03  1:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02  1:48 [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag piaojun
2018-08-02  1:54 ` Dominique Martinet
2018-08-02  1:59   ` piaojun
2018-08-02 13:23     ` [V9fs-developer] " Greg Kurz
2018-08-03  1:45       ` piaojun [this message]
2018-08-03  2:06         ` Dominique Martinet
2018-08-03  2:09           ` Dominique Martinet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5B63B3CE.3040601@huawei.com \
    --to=piaojun@huawei.com \
    --cc=asmadeus@codewreck.org \
    --cc=ericvh@gmail.com \
    --cc=groug@kaod.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=rminnich@sandia.gov \
    --cc=v9fs-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).