[PATCH V2 1/9] conf: use g_autofree and remove unnecessary label
Ján Tomko
jtomko at redhat.com
Mon Jan 9 03:36:01 UTC 2023
On a Friday in 2023, Jiang Jiacheng wrote:
>Signed-off-by: Jiang Jiacheng <jiangjiacheng at huawei.com>
>---
> src/conf/domain_audit.c | 121 ++++++++++---------------------
> src/conf/node_device_util.c | 49 +++++--------
> src/conf/nwfilter_conf.c | 55 +++++---------
> src/conf/virnetworkobj.c | 85 ++++++++--------------
> src/conf/virnetworkportdef.c | 12 +--
> src/conf/virnwfilterbindingobj.c | 22 ++----
> src/conf/virnwfilterobj.c | 19 ++---
> src/conf/virstorageobj.c | 23 ++----
> 8 files changed, 129 insertions(+), 257 deletions(-)
>
[...]
>diff --git a/src/conf/node_device_util.c b/src/conf/node_device_util.c
>index dfec1a91ce..c2fa73afc1 100644
>--- a/src/conf/node_device_util.c
>+++ b/src/conf/node_device_util.c
>@@ -78,7 +78,7 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
> {
> unsigned int parent_host;
> char *name = NULL;
>- char *parent_hoststr = NULL;
>+ g_autofree char *parent_hoststr = NULL;
> bool skip_capable_check = false;
>
> VIR_DEBUG("parent='%s', wwnn='%s' wwpn='%s'",
>@@ -91,27 +91,27 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
> fchost->parent_wwpn))) {
> virReportError(VIR_ERR_XML_ERROR, "%s",
> _("cannot find parent using provided wwnn/wwpn"));
>- goto cleanup;
>+ return name;
> }
> } else if (fchost->parent_fabric_wwn) {
> if (!(parent_hoststr =
> virVHBAGetHostByFabricWWN(NULL, fchost->parent_fabric_wwn))) {
> virReportError(VIR_ERR_XML_ERROR, "%s",
> _("cannot find parent using provided fabric_wwn"));
>- goto cleanup;
>+ return name;
> }
> } else {
> if (!(parent_hoststr = virVHBAFindVportHost(NULL))) {
> virReportError(VIR_ERR_XML_ERROR, "%s",
> _("'parent' for vHBA not specified, and "
> "cannot find one on this host"));
>- goto cleanup;
>+ return name;
> }
> skip_capable_check = true;
> }
>
> if (virSCSIHostGetNumber(parent_hoststr, &parent_host) < 0)
>- goto cleanup;
>+ return name;
>
> /* NOTE:
> * We do not save the parent_hoststr in fchost->parent since
>@@ -125,23 +125,21 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
> virReportError(VIR_ERR_XML_ERROR,
> _("parent '%s' specified for vHBA does not exist"),
> parent_hoststr);
>- goto cleanup;
>+ return name;
> }
>
> if (virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
> VPORT_CREATE) < 0)
>- goto cleanup;
>+ return name;
>
> /* Let's ensure the device was created */
> virWaitForDevices();
> if (!(name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
> ignore_value(virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
> VPORT_DELETE));
>- goto cleanup;
>+ return name;
In all the cases above, name can only be NULL, so returning NULL
directly is better for clarity.
> }
>
>- cleanup:
>- VIR_FREE(parent_hoststr);
> return name;
> }
>
>diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
>index 9a95ae6c12..e5ea45b0b7 100644
>--- a/src/conf/nwfilter_conf.c
>+++ b/src/conf/nwfilter_conf.c
>@@ -2375,10 +2375,10 @@ virNWFilterRuleDefFixup(virNWFilterRuleDef *rule)
> static virNWFilterRuleDef *
> virNWFilterRuleParse(xmlNodePtr node)
> {
>- char *action;
>- char *direction;
>- char *prio;
>- char *statematch;
>+ g_autofree char *action = NULL;
>+ g_autofree char *direction = NULL;
>+ g_autofree char *prio = NULL;
>+ g_autofree char *statematch = NULL;
> bool found;
> int found_i = 0;
> int priority;
>@@ -2476,17 +2476,11 @@ virNWFilterRuleParse(xmlNodePtr node)
>
> virNWFilterRuleDefFixup(ret);
>
>- cleanup:
>- VIR_FREE(prio);
>- VIR_FREE(action);
>- VIR_FREE(direction);
>- VIR_FREE(statematch);
>-
> return ret;
>
> err_exit:
> g_clear_pointer(&ret, virNWFilterRuleDefFree);
>- goto cleanup;
>+ return ret;
Clearer as:
return NULL;
> }
>
>
>@@ -2707,24 +2693,21 @@ virNWFilterSaveConfig(const char *configDir,
> virNWFilterDef *def)
> {
> int ret = -1;
>- char *xml;
>+ g_autofree char *xml = NULL;
> char uuidstr[VIR_UUID_STRING_BUFLEN];
>- char *configFile = NULL;
>+ g_autofree char *configFile = NULL;
>
> if (!(xml = virNWFilterDefFormat(def)))
>- goto cleanup;
>+ return ret;
>
> if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
>- goto cleanup;
>+ return ret;
>
In the two returns above:
return -1;
(As a followup, the ret variable can be removed)
> virUUIDFormat(def->uuid, uuidstr);
> ret = virXMLSaveFile(configFile,
> virXMLPickShellSafeComment(def->name, uuidstr),
> "nwfilter-edit", xml);
>
>- cleanup:
>- VIR_FREE(configFile);
>- VIR_FREE(xml);
> return ret;
> }
>
I will squash in the following before pushing:
diff --git a/src/conf/node_device_util.c b/src/conf/node_device_util.c
index c2fa73afc1..3c2fc4e258 100644
--- a/src/conf/node_device_util.c
+++ b/src/conf/node_device_util.c
@@ -91,27 +91,27 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
fchost->parent_wwpn))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot find parent using provided wwnn/wwpn"));
- return name;
+ return NULL;
}
} else if (fchost->parent_fabric_wwn) {
if (!(parent_hoststr =
virVHBAGetHostByFabricWWN(NULL, fchost->parent_fabric_wwn))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("cannot find parent using provided fabric_wwn"));
- return name;
+ return NULL;
}
} else {
if (!(parent_hoststr = virVHBAFindVportHost(NULL))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("'parent' for vHBA not specified, and "
"cannot find one on this host"));
- return name;
+ return NULL;
}
skip_capable_check = true;
}
if (virSCSIHostGetNumber(parent_hoststr, &parent_host) < 0)
- return name;
+ return NULL;
/* NOTE:
* We do not save the parent_hoststr in fchost->parent since
@@ -125,19 +125,19 @@ virNodeDeviceCreateVport(virStorageAdapterFCHost *fchost)
virReportError(VIR_ERR_XML_ERROR,
_("parent '%s' specified for vHBA does not exist"),
parent_hoststr);
- return name;
+ return NULL;
}
if (virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
VPORT_CREATE) < 0)
- return name;
+ return NULL;
/* Let's ensure the device was created */
virWaitForDevices();
if (!(name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
ignore_value(virVHBAManageVport(parent_host, fchost->wwpn, fchost->wwnn,
VPORT_DELETE));
- return name;
+ return NULL;
}
return name;
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index e5ea45b0b7..5453b6db05 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2480,7 +2480,7 @@ virNWFilterRuleParse(xmlNodePtr node)
err_exit:
g_clear_pointer(&ret, virNWFilterRuleDefFree);
- return ret;
+ return NULL;
}
@@ -2698,10 +2698,10 @@ virNWFilterSaveConfig(const char *configDir,
g_autofree char *configFile = NULL;
if (!(xml = virNWFilterDefFormat(def)))
- return ret;
+ return -1;
if (!(configFile = virFileBuildPath(configDir, def->name, ".xml")))
- return ret;
+ return -1;
virUUIDFormat(def->uuid, uuidstr);
ret = virXMLSaveFile(configFile,
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20230109/fa854b80/attachment.sig>
More information about the libvir-list
mailing list