From: Laszlo Ersek <lersek@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Markus Armbruster <armbru@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH-for-5.1] hw/nvram/fw_cfg: Let fw_cfg_add_from_generator() return boolean value
Date: Mon, 20 Jul 2020 23:57:42 +0200 [thread overview]
Message-ID: <34e8619f-4301-d746-fe3f-c340040c22c1@redhat.com> (raw)
In-Reply-To: <20200720123521.8135-1-philmd@redhat.com>
On 07/20/20 14:35, Philippe Mathieu-Daudé wrote:
> Commits b6d7e9b66f..a43770df5d simplified the error propagation.
> Similarly to commit 6fd5bef10b "qom: Make functions taking Error**
> return bool, not void", let fw_cfg_add_from_generator() return a
> boolean value, not void.
> This allow to simplify parse_fw_cfg() and fixes the error handling
> issue reported by Coverity (CID 1430396):
>
> In parse_fw_cfg():
>
> Variable assigned once to a constant guards dead code.
>
> Local variable local_err is assigned only once, to a constant
> value, making it effectively constant throughout its scope.
> If this is not the intent, examine the logic to see if there
> is a missing assignment that would make local_err not remain
> constant.
>
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Fixes: Coverity CID 1430396: 'Constant' variable guards dead code (DEADCODE)
> Fixes: 6552d87c48 ("softmmu/vl: Let -fw_cfg option take a 'gen_id' argument")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> include/hw/nvram/fw_cfg.h | 4 +++-
> hw/nvram/fw_cfg.c | 10 ++++++----
> softmmu/vl.c | 6 +-----
> 3 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
> index 11feae3177..d90857f092 100644
> --- a/include/hw/nvram/fw_cfg.h
> +++ b/include/hw/nvram/fw_cfg.h
> @@ -302,8 +302,10 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
> * will be used; also, a new entry will be added to the file directory
> * structure residing at key value FW_CFG_FILE_DIR, containing the item name,
> * data size, and assigned selector key value.
> + *
> + * Returns: %true on success, %false on error.
> */
> -void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
> +bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
> const char *gen_id, Error **errp);
>
> FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index 3b1811d3bf..c88aec4341 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -1032,7 +1032,7 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
> return NULL;
> }
>
> -void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
> +bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
> const char *gen_id, Error **errp)
> {
> ERRP_GUARD();
> @@ -1044,20 +1044,22 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
> obj = object_resolve_path_component(object_get_objects_root(), gen_id);
> if (!obj) {
> error_setg(errp, "Cannot find object ID '%s'", gen_id);
> - return;
> + return false;
> }
> if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) {
> error_setg(errp, "Object ID '%s' is not a '%s' subclass",
> gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE);
> - return;
> + return false;
> }
> klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
> array = klass->get_data(obj, errp);
> if (*errp) {
> - return;
> + return false;
> }
> size = array->len;
> fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size);
> +
> + return true;
> }
>
> static void fw_cfg_machine_reset(void *opaque)
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index f476ef89ed..3416241557 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2070,11 +2070,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
> size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
> buf = g_memdup(str, size);
> } else if (nonempty_str(gen_id)) {
> - Error *local_err = NULL;
> -
> - fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp);
> - if (local_err) {
> - error_propagate(errp, local_err);
> + if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
> return -1;
> }
> return 0;
>
The retvals seem OK, but I have no idea if this plays nicely with the
new ERRP_GUARD (which I'm just noticing in fw_cfg_add_from_generator()).
FWIW
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
next prev parent reply other threads:[~2020-07-20 21:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 12:35 [PATCH-for-5.1] hw/nvram/fw_cfg: Let fw_cfg_add_from_generator() return boolean value Philippe Mathieu-Daudé
2020-07-20 21:57 ` Laszlo Ersek [this message]
2020-07-21 8:33 ` Markus Armbruster
2020-07-22 17:50 ` Laszlo Ersek
2020-07-23 7:37 ` Markus Armbruster
2020-07-23 11:01 ` Laszlo Ersek
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=34e8619f-4301-d746-fe3f-c340040c22c1@redhat.com \
--to=lersek@redhat.com \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.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 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).