All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gonglei <arei.gonglei@huawei.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Huangweidong \(C\)" <weidong.huang@huawei.com>,
	Zhanghailiang <zhang.zhanghailiang@huawei.com>,
	"qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
	Michael Tokarev <mjt@tls.msk.ru>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"Huangpeng \(Peter\)" <peter.huangpeng@huawei.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 1/9] l2tpv3: fix fd leak
Date: Tue, 18 Nov 2014 16:07:53 +0800	[thread overview]
Message-ID: <546AFE59.6040208@huawei.com> (raw)
In-Reply-To: <87y4r9vtf1.fsf@blackfin.pond.sub.org>

On 2014/11/18 15:50, Markus Armbruster wrote:

> Michael Tokarev <mjt@tls.msk.ru> writes:
> 
>> 15.11.2014 13:06, arei.gonglei@huawei.com wrote:
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> In this false branch, fd will leak when it is zero.
>>> Change the testing condition.
>>
>> Why fd==0 is a concern here?  It is a very unlikely
>> situation that fd0 will be picked - firstly because
>> fd0 is almost always open, and second - even if it
>> isn't open, it will be picked much earlier than this
>> code path, ie, some other file will use fd0 before.
>>
>> But even if the concern is real (after all, better
>> stay correct than spread bad code pattern, even if
>> in reality we don't care as this can't happen), why
>> not add 0 to the equality?
>>
>> Why people especially compare with -1?  Any negative
>> value is illegal here and in lots of other places,
>> and many software packages used to return -errno in
>> error cases, which is definitely != -1.  I'm not
>> saying that comparing with -1 is bad in _this_
>> particular case, but why not do it generally in
>> all cases?
>>
>> More, comparing with 0 is faster and shorter than
>> comparing with -1...
>>
>> So if it were me, I'd change it to >= 0, not to
>> == -1.  Here and in all other millions of places
>> in qemu code where it compares with -1... ;)
> 
> Yup.
> 
> In the case of close(), I wouldn't even bother to check, except Coverity
> gets excited when it sees an invalid fd flow into close().  Rightfully
> so when the invalid fd is non-negative, overeager when it's negative.

Thank you, guys.
Paolo had fixed it :)

Best regards,
-Gonglei



WARNING: multiple messages have this Message-ID (diff)
From: Gonglei <arei.gonglei@huawei.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Huangweidong (C)" <weidong.huang@huawei.com>,
	Zhanghailiang <zhang.zhanghailiang@huawei.com>,
	"qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
	Michael Tokarev <mjt@tls.msk.ru>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"Huangpeng (Peter)" <peter.huangpeng@huawei.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/9] l2tpv3: fix fd leak
Date: Tue, 18 Nov 2014 16:07:53 +0800	[thread overview]
Message-ID: <546AFE59.6040208@huawei.com> (raw)
In-Reply-To: <87y4r9vtf1.fsf@blackfin.pond.sub.org>

On 2014/11/18 15:50, Markus Armbruster wrote:

> Michael Tokarev <mjt@tls.msk.ru> writes:
> 
>> 15.11.2014 13:06, arei.gonglei@huawei.com wrote:
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> In this false branch, fd will leak when it is zero.
>>> Change the testing condition.
>>
>> Why fd==0 is a concern here?  It is a very unlikely
>> situation that fd0 will be picked - firstly because
>> fd0 is almost always open, and second - even if it
>> isn't open, it will be picked much earlier than this
>> code path, ie, some other file will use fd0 before.
>>
>> But even if the concern is real (after all, better
>> stay correct than spread bad code pattern, even if
>> in reality we don't care as this can't happen), why
>> not add 0 to the equality?
>>
>> Why people especially compare with -1?  Any negative
>> value is illegal here and in lots of other places,
>> and many software packages used to return -errno in
>> error cases, which is definitely != -1.  I'm not
>> saying that comparing with -1 is bad in _this_
>> particular case, but why not do it generally in
>> all cases?
>>
>> More, comparing with 0 is faster and shorter than
>> comparing with -1...
>>
>> So if it were me, I'd change it to >= 0, not to
>> == -1.  Here and in all other millions of places
>> in qemu code where it compares with -1... ;)
> 
> Yup.
> 
> In the case of close(), I wouldn't even bother to check, except Coverity
> gets excited when it sees an invalid fd flow into close().  Rightfully
> so when the invalid fd is non-negative, overeager when it's negative.

Thank you, guys.
Paolo had fixed it :)

Best regards,
-Gonglei

  reply	other threads:[~2014-11-18  8:10 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-15 10:06 [Qemu-trivial] [PATCH 0/9] Fix Coverity warning reports arei.gonglei
2014-11-15 10:06 ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 1/9] l2tpv3: fix fd leak arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-17 16:51   ` [Qemu-trivial] " Stefan Hajnoczi
2014-11-17 16:51     ` Stefan Hajnoczi
2014-11-17 16:58   ` [Qemu-trivial] " Michael Tokarev
2014-11-17 16:58     ` [Qemu-devel] " Michael Tokarev
2014-11-18  7:50     ` [Qemu-trivial] " Markus Armbruster
2014-11-18  7:50       ` Markus Armbruster
2014-11-18  8:07       ` Gonglei [this message]
2014-11-18  8:07         ` Gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 2/9] mips_mipssim: fix use-after-free for filename arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 3/9] qga: fix false negative argument passing arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 4/9] loader: fix NEGATIVE_RETURNS arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 5/9] nvme: remove superfluous check arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-17 16:55   ` [Qemu-trivial] " Stefan Hajnoczi
2014-11-17 16:55     ` Stefan Hajnoczi
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 6/9] acl: fix memory leak arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-17 10:48   ` [Qemu-trivial] " Paolo Bonzini
2014-11-17 10:48     ` [Qemu-devel] " Paolo Bonzini
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 7/9] qemu-char: fix MISSING_COMMA arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 8/9] shpc: fix dead code arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-15 10:06 ` [Qemu-trivial] [PATCH 9/9] hcd-musb: fix dereference null return value arei.gonglei
2014-11-15 10:06   ` [Qemu-devel] " arei.gonglei
2014-11-17 10:58   ` [Qemu-trivial] " Paolo Bonzini
2014-11-17 10:58     ` [Qemu-devel] " Paolo Bonzini
2014-11-17 11:18     ` [Qemu-trivial] " Gonglei
2014-11-17 11:18       ` [Qemu-devel] " Gonglei
2014-11-17 12:55       ` [Qemu-trivial] " Gonglei
2014-11-17 12:55         ` [Qemu-devel] " Gonglei
2014-11-17 13:36         ` [Qemu-trivial] " Gerd Hoffmann
2014-11-17 13:36           ` [Qemu-devel] " Gerd Hoffmann
2014-11-17 13:39           ` [Qemu-trivial] " Paolo Bonzini
2014-11-17 13:39             ` [Qemu-devel] " Paolo Bonzini

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=546AFE59.6040208@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=armbru@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=weidong.huang@huawei.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.