From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Wei Liu <wei.liu2@citrix.com>, xen-devel@lists.xen.org
Cc: Charles Arnold <carnold@suse.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Ian Campbell <ian.campbell@citrix.com>
Subject: Re: [PATCH 4/4] libxenstat: qmp_read fix and cleanup
Date: Wed, 8 Apr 2015 16:25:06 +0100 [thread overview]
Message-ID: <55254852.4010204@citrix.com> (raw)
In-Reply-To: <1428505275-6563-5-git-send-email-wei.liu2@citrix.com>
On 08/04/15 16:01, Wei Liu wrote:
> The second argument of poll(2) is the number of file descriptors. POLLIN
> is defined as 1 so it happens to work.
>
> Also do two cleanups while I was there:
> 1. There is only one fd, so a one-element array is enough.
> 2. Initialise pfd to make code linter happy.
>
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Charles Arnold <carnold@suse.com>
> ---
> tools/xenstat/libxenstat/src/xenstat_qmp.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> index e4f343b..260cd34 100644
> --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c
> +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c
> @@ -289,13 +289,14 @@ static size_t qmp_write(int qfd, char *cmd, size_t cmd_len)
> static int qmp_read(int qfd, unsigned char **qstats)
> {
> unsigned char buf[1024], *ptr;
> - struct pollfd pfd[2];
> + struct pollfd pfd[1];
> int n, qsize = 0;
>
> *qstats = NULL;
> + memset(pfd, 0, sizeof(pfd));
> pfd[0].fd = qfd;
> pfd[0].events = POLLIN;
> - while ((n = poll(pfd, POLLIN, 10)) > 0) {
> + while ((n = poll(pfd, 1, 10)) > 0) {
> if (pfd[0].revents & POLLIN) {
> if ((n = read(qfd, buf, sizeof(buf))) < 0) {
> free(*qstats);
> @@ -311,6 +312,9 @@ static int qmp_read(int qfd, unsigned char **qstats)
> ptr[qsize] = 0;
> *qstats = ptr;
> }
> + memset(pfd, 0, sizeof(pfd));
> + pfd[0].fd = qfd;
> + pfd[0].events = POLLIN;
I don't think this is necessary. .fd and .events should be untouched by
poll().
Ignore the complaint about revents being uninitialised. That is because
Coverity doesn't have a model for poll(), and doesn't know that poll()
writes to revents.
I was going to find some copious free time to correctly model poll(),
which will fix several related defects.
~Andrew
> }
> return 1;
> }
next prev parent reply other threads:[~2015-04-08 15:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-08 15:01 [PATCH 0/4] libxenstat bug fixes and cleanups Wei Liu
2015-04-08 15:01 ` [PATCH 1/4] libxenstat: check xc_interface_open return value Wei Liu
2015-04-08 15:21 ` Andrew Cooper
2015-04-08 15:47 ` Wei Liu
2015-04-08 15:01 ` [PATCH 2/4] libxenstat: YAJL_GET_STRING may return NULL Wei Liu
2015-04-08 15:22 ` Andrew Cooper
2015-04-08 15:47 ` Ian Jackson
2015-04-08 15:01 ` [PATCH 3/4] libxenstat: always free qmp_stats Wei Liu
2015-04-08 15:49 ` Ian Jackson
2015-04-08 15:56 ` Wei Liu
2015-04-08 15:01 ` [PATCH 4/4] libxenstat: qmp_read fix and cleanup Wei Liu
2015-04-08 15:25 ` Andrew Cooper [this message]
2015-04-08 15:47 ` Wei Liu
2015-04-08 15:52 ` Ian Jackson
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=55254852.4010204@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=carnold@suse.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/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.