All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, mjt@tls.msk.ru,
	peter.huangpeng@huawei.com, armbru@redhat.com, kraxel@redhat.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v3 2/5] spice-qemu-char: fix parameter checks in qemu_chr_parse_* functions
Date: Tue, 04 Nov 2014 13:27:06 +0000	[thread overview]
Message-ID: <87389zumdx.fsf@linaro.org> (raw)
In-Reply-To: <1415098223-32404-3-git-send-email-zhang.zhanghailiang@huawei.com>


zhanghailiang <zhang.zhanghailiang@huawei.com> writes:

> For functions qemu_chr_parse_spice_vmc and qemu_chr_parse_spice_port,
> we should also check if parameter name is empty, and it will help finding
> the wrong configure, such as
> 'qemu-system-x86_64 -chardev spiceport(or spiceport),id=id,name='
>
> After check the parameter in parse function, we can remove the
> superfluous parameter checks in qemu_chr_open_spice_*
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  spice-qemu-char.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/spice-qemu-char.c b/spice-qemu-char.c
> index 8106e06..d3c1f5c 100644
> --- a/spice-qemu-char.c
> +++ b/spice-qemu-char.c
> @@ -290,11 +290,6 @@ CharDriverState *qemu_chr_open_spice_vmc(const char *type)
>  {
>      const char **psubtype = spice_server_char_device_recognized_subtypes();
>  
> -    if (type == NULL) {
> -        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
> -        print_allowed_subtypes();
> -        return NULL;
> -    }

As with patch 1 I'd at least assert the contract. But this also drops a
helpful info dump on a missing parameter.

>      for (; *psubtype != NULL; ++psubtype) {
>          if (strcmp(type, *psubtype) == 0) {
>              break;
> @@ -315,11 +310,6 @@ CharDriverState *qemu_chr_open_spice_port(const char *name)
>      CharDriverState *chr;
>      SpiceCharDriver *s;
>  
> -    if (name == NULL) {
> -        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
> -        return NULL;
> -    }
> -
>      chr = chr_open("port", spice_port_set_fe_open);
>      s = chr->opaque;
>      s->sin.portname = g_strdup(name);
> @@ -345,7 +335,7 @@ static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend,
>  {
>      const char *name = qemu_opt_get(opts, "name");
>  
> -    if (name == NULL) {
> +    if (name == NULL || !name[0]) {
>          error_setg(errp, "chardev: spice channel: no name given");
>          return;
>      }
> @@ -358,7 +348,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,
>  {
>      const char *name = qemu_opt_get(opts, "name");
>  
> -    if (name == NULL) {
> +    if (name == NULL || !name[0]) {
>          error_setg(errp, "chardev: spice port: no name given");
>          return;
>      }

Same comments as for 1/5

-- 
Alex Bennée


WARNING: multiple messages have this Message-ID (diff)
From: "Alex Bennée" <alex.bennee@linaro.org>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, mjt@tls.msk.ru,
	peter.huangpeng@huawei.com, armbru@redhat.com, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 2/5] spice-qemu-char: fix parameter checks in qemu_chr_parse_* functions
Date: Tue, 04 Nov 2014 13:27:06 +0000	[thread overview]
Message-ID: <87389zumdx.fsf@linaro.org> (raw)
In-Reply-To: <1415098223-32404-3-git-send-email-zhang.zhanghailiang@huawei.com>


zhanghailiang <zhang.zhanghailiang@huawei.com> writes:

> For functions qemu_chr_parse_spice_vmc and qemu_chr_parse_spice_port,
> we should also check if parameter name is empty, and it will help finding
> the wrong configure, such as
> 'qemu-system-x86_64 -chardev spiceport(or spiceport),id=id,name='
>
> After check the parameter in parse function, we can remove the
> superfluous parameter checks in qemu_chr_open_spice_*
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  spice-qemu-char.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/spice-qemu-char.c b/spice-qemu-char.c
> index 8106e06..d3c1f5c 100644
> --- a/spice-qemu-char.c
> +++ b/spice-qemu-char.c
> @@ -290,11 +290,6 @@ CharDriverState *qemu_chr_open_spice_vmc(const char *type)
>  {
>      const char **psubtype = spice_server_char_device_recognized_subtypes();
>  
> -    if (type == NULL) {
> -        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
> -        print_allowed_subtypes();
> -        return NULL;
> -    }

As with patch 1 I'd at least assert the contract. But this also drops a
helpful info dump on a missing parameter.

>      for (; *psubtype != NULL; ++psubtype) {
>          if (strcmp(type, *psubtype) == 0) {
>              break;
> @@ -315,11 +310,6 @@ CharDriverState *qemu_chr_open_spice_port(const char *name)
>      CharDriverState *chr;
>      SpiceCharDriver *s;
>  
> -    if (name == NULL) {
> -        fprintf(stderr, "spice-qemu-char: missing name parameter\n");
> -        return NULL;
> -    }
> -
>      chr = chr_open("port", spice_port_set_fe_open);
>      s = chr->opaque;
>      s->sin.portname = g_strdup(name);
> @@ -345,7 +335,7 @@ static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend,
>  {
>      const char *name = qemu_opt_get(opts, "name");
>  
> -    if (name == NULL) {
> +    if (name == NULL || !name[0]) {
>          error_setg(errp, "chardev: spice channel: no name given");
>          return;
>      }
> @@ -358,7 +348,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,
>  {
>      const char *name = qemu_opt_get(opts, "name");
>  
> -    if (name == NULL) {
> +    if (name == NULL || !name[0]) {
>          error_setg(errp, "chardev: spice port: no name given");
>          return;
>      }

Same comments as for 1/5

-- 
Alex Bennée

  reply	other threads:[~2014-11-04 13:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 10:50 [Qemu-trivial] [PATCH v3 0/5] Trivial patch about qemu-char zhanghailiang
2014-11-04 10:50 ` [Qemu-devel] " zhanghailiang
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 1/5] qemu-char: fix parameter check in some qemu_chr_parse_* functions zhanghailiang
2014-11-04 10:50   ` [Qemu-devel] " zhanghailiang
2014-11-04 13:25   ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:25     ` Alex Bennée
2014-11-05  7:05     ` [Qemu-trivial] " Michael Tokarev
2014-11-05  7:05       ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-05 12:19       ` [Qemu-trivial] [Qemu-devel] " zhanghailiang
2014-11-05 12:19         ` [Qemu-devel] [Qemu-trivial] " zhanghailiang
2014-11-05 13:28         ` [Qemu-trivial] [Qemu-devel] " Alex Bennée
2014-11-05 13:28           ` [Qemu-devel] [Qemu-trivial] " Alex Bennée
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 2/5] spice-qemu-char: fix parameter checks in " zhanghailiang
2014-11-04 10:50   ` [Qemu-devel] " zhanghailiang
2014-11-04 13:27   ` Alex Bennée [this message]
2014-11-04 13:27     ` Alex Bennée
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 3/5] qemu-char: fix incorrect state in error message zhanghailiang
2014-11-04 10:50   ` [Qemu-devel] " zhanghailiang
2014-11-04 13:31   ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:31     ` Alex Bennée
2014-11-05  7:08   ` [Qemu-trivial] " Michael Tokarev
2014-11-05  7:08     ` [Qemu-devel] " Michael Tokarev
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 4/5] qemu-char: convert some open functions to use Error API zhanghailiang
2014-11-04 10:50   ` [Qemu-devel] " zhanghailiang
2014-11-04 13:39   ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:39     ` Alex Bennée
2014-11-05  7:15     ` [Qemu-trivial] " Michael Tokarev
2014-11-05  7:15       ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-11-05  9:08       ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
2014-11-05  9:08         ` [Qemu-devel] [Qemu-trivial] " Markus Armbruster
2014-11-04 10:50 ` [Qemu-trivial] [PATCH v3 5/5] spice-qemu-char: convert some " zhanghailiang
2014-11-04 10:50   ` [Qemu-devel] " zhanghailiang
2014-11-04 13:41   ` [Qemu-trivial] " Alex Bennée
2014-11-04 13:41     ` Alex Bennée

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=87389zumdx.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --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.