hw/nvram/fw_cfg: Simplify fw_cfg_add_from_generator() error propagation
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Tue, 21 Jul 2020 13:05:51 +0000 (15:05 +0200)
committerPhilippe Mathieu-Daudé <philmd@redhat.com>
Tue, 21 Jul 2020 14:47:31 +0000 (16:47 +0200)
Document FWCfgDataGeneratorClass::get_data() return NULL
on error, and non-NULL on success. This allow us to simplify
fw_cfg_add_from_generator(). Since we don't need a local
variable to propagate the error, we can remove the ERRP_GUARD()
macro.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200721131911.27380-2-philmd@redhat.com>

hw/nvram/fw_cfg.c
include/hw/nvram/fw_cfg.h

index 3b1811d3bfdde516077e7ff18534b8e547af343f..dfa1f2012a7d93ad4fa9da3a603ea6502af74f08 100644 (file)
@@ -1035,7 +1035,6 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
 void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
                                const char *gen_id, Error **errp)
 {
-    ERRP_GUARD();
     FWCfgDataGeneratorClass *klass;
     GByteArray *array;
     Object *obj;
@@ -1053,7 +1052,7 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
     }
     klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
     array = klass->get_data(obj, errp);
-    if (*errp) {
+    if (!array) {
         return;
     }
     size = array->len;
index 11feae317748c1e2f186f220595f9b38f71f14e8..bbcf4056494a408d545c3597b4abf85bfe94ad3d 100644 (file)
@@ -32,7 +32,9 @@ typedef struct FWCfgDataGeneratorClass {
      * @obj: the object implementing this interface
      * @errp: pointer to a NULL-initialized error object
      *
-     * Returns: reference to a byte array containing the data.
+     * Returns: reference to a byte array containing the data on success,
+     *          or NULL on error.
+     *
      * The caller should release the reference when no longer
      * required.
      */