From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: fam@euphon.net, Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org,
pbonzini@redhat.com
Subject: Re: [PATCH 0/2] qemu/queue.h: clear linked list pointers on remove
Date: Tue, 25 Feb 2020 11:06:57 +0100 [thread overview]
Message-ID: <031a3ba8-eed0-834a-0b5c-5e77d0429f34@redhat.com> (raw)
In-Reply-To: <20200225090534.GB4178@stefanha-x1.localdomain>
On 2/25/20 10:05 AM, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 12:54:37PM +0100, Philippe Mathieu-Daudé wrote:
>> On 2/24/20 12:39 PM, Stefan Hajnoczi wrote:
>>> On Mon, Feb 24, 2020 at 02:55:33AM -0800, no-reply@patchew.org wrote:
>>>> === OUTPUT BEGIN ===
>>>> 1/2 Checking commit f913b2430ad3 (qemu/queue.h: clear linked list pointers on remove)
>>>> ERROR: do not use assignment in if condition
>>>> #65: FILE: include/qemu/queue.h:314:
>>>> + if (((head)->sqh_first = elm->field.sqe_next) == NULL) \
>>>>
>>>> total: 1 errors, 0 warnings, 59 lines checked
>>>
>>> The same pattern is used elsewhere in this file. This code comes from
>>> BSD and doesn't comply with QEMU's coding style.
>>
>> Checkpatch is right, assigning out of the if statement makes the review
>> easier, and we can avoid the 'elm' null deref:
>
> The rest of the file uses if ((a = b) == NULL), so making it
> inconsistent in this one instance isn't very satisfying.
>
>> #define QSIMPLEQ_REMOVE_HEAD(head, field) do { \
>> - if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL)\
>> + typeof((head)->sqh_first) elm = (head)->sqh_first; \
>> + (head)->sqh_first = elm->field.sqe_next; \
>> + if (elm == NULL) { \
>
> The previous line would have segfaulted if elm was NULL so this check
> doesn't make sense.
>
> This macro assumes there is at least one element in the list.
Ah good point, thanks.
>
> The point of the check is to fix up the sqh_last pointer in the head
> when the final element is removed from the list.
>
>> (head)->sqh_last = &(head)->sqh_first; \
>> + } else { \
>> + elm->field.sqe_next = NULL; \
>> + } \
>> } while (/*CONSTCOND*/0)
next prev parent reply other threads:[~2020-02-25 10:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 10:34 [PATCH 0/2] qemu/queue.h: clear linked list pointers on remove Stefan Hajnoczi
2020-02-24 10:34 ` [PATCH 1/2] " Stefan Hajnoczi
2020-02-24 11:51 ` Philippe Mathieu-Daudé
2020-02-25 9:01 ` Stefan Hajnoczi
2020-02-24 10:34 ` [PATCH 2/2] aio-posix: remove confusing QLIST_SAFE_REMOVE() Stefan Hajnoczi
2020-02-24 10:55 ` [PATCH 0/2] qemu/queue.h: clear linked list pointers on remove no-reply
2020-02-24 11:39 ` Stefan Hajnoczi
2020-02-24 11:54 ` Philippe Mathieu-Daudé
2020-02-25 9:05 ` Stefan Hajnoczi
2020-02-25 10:06 ` Philippe Mathieu-Daudé [this message]
2020-03-09 16:40 ` Stefan Hajnoczi
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=031a3ba8-eed0-834a-0b5c-5e77d0429f34@redhat.com \
--to=philmd@redhat.com \
--cc=fam@euphon.net \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=stefanha@redhat.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 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).