Skip to content

Commit 0771951

Browse files
committed
hw/nvram/fw_cfg: Let fw_cfg_add_from_generator() return boolean value
Commits b6d7e9b..a43770d simplified the error propagation. Similarly to commit 6fd5bef "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. It's the call of fw_cfg_add_from_generator(): Error *local_err = NULL; fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp); if (local_err) { error_propagate(errp, local_err); return -1; } return 0; If it fails, parse_fw_cfg() sets an error and returns 0, which is wrong. Harmless, because the only caller passes &error_fatal. Reported-by: Peter Maydell <[email protected]> Fixes: Coverity CID 1430396: 'Constant' variable guards dead code (DEADCODE) Fixes: 6552d87 ("softmmu/vl: Let -fw_cfg option take a 'gen_id' argument") Reviewed-by: Laszlo Ersek <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]>
1 parent a3ad583 commit 0771951

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

hw/nvram/fw_cfg.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
10321032
return NULL;
10331033
}
10341034

1035-
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
1035+
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
10361036
const char *gen_id, Error **errp)
10371037
{
10381038
FWCfgDataGeneratorClass *klass;
@@ -1043,20 +1043,22 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
10431043
obj = object_resolve_path_component(object_get_objects_root(), gen_id);
10441044
if (!obj) {
10451045
error_setg(errp, "Cannot find object ID '%s'", gen_id);
1046-
return;
1046+
return false;
10471047
}
10481048
if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) {
10491049
error_setg(errp, "Object ID '%s' is not a '%s' subclass",
10501050
gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE);
1051-
return;
1051+
return false;
10521052
}
10531053
klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
10541054
array = klass->get_data(obj, errp);
10551055
if (!array) {
1056-
return;
1056+
return false;
10571057
}
10581058
size = array->len;
10591059
fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size);
1060+
1061+
return true;
10601062
}
10611063

10621064
static void fw_cfg_machine_reset(void *opaque)

include/hw/nvram/fw_cfg.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
304304
* will be used; also, a new entry will be added to the file directory
305305
* structure residing at key value FW_CFG_FILE_DIR, containing the item name,
306306
* data size, and assigned selector key value.
307+
*
308+
* Returns: %true on success, %false on error.
307309
*/
308-
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
310+
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
309311
const char *gen_id, Error **errp);
310312

311313
FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,

softmmu/vl.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,11 +2070,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
20702070
size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
20712071
buf = g_memdup(str, size);
20722072
} else if (nonempty_str(gen_id)) {
2073-
Error *local_err = NULL;
2074-
2075-
fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp);
2076-
if (local_err) {
2077-
error_propagate(errp, local_err);
2073+
if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
20782074
return -1;
20792075
}
20802076
return 0;

0 commit comments

Comments
 (0)