[libvirt] [PATCH 06/10] conf: Introduce virDomainDeviceInfoNew()

Andrea Bolognani posted 10 patches 7 years, 10 months ago
[libvirt] [PATCH 06/10] conf: Introduce virDomainDeviceInfoNew()
Posted by Andrea Bolognani 7 years, 10 months ago
It allocates and initializes a virDomainDeviceInfo struct
in one fell swoop.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/conf/device_conf.c | 13 +++++++++++++
 src/conf/device_conf.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 4644580..6ead830 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -32,6 +32,19 @@
 
 #define VIR_FROM_THIS VIR_FROM_DEVICE
 
+virDomainDeviceInfoPtr
+virDomainDeviceInfoNew(void)
+{
+    virDomainDeviceInfoPtr info;
+
+    if (VIR_ALLOC(info) < 0)
+        return NULL;
+
+    virDomainDeviceInfoClear(info);
+
+    return info;
+}
+
 void
 virDomainDeviceInfoClear(virDomainDeviceInfoPtr info)
 {
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 53abe1b..8f641bc 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -170,6 +170,7 @@ struct _virDomainDeviceInfo {
     char *loadparm;
 };
 
+virDomainDeviceInfoPtr virDomainDeviceInfoNew(void);
 void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info);
 int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
                             virDomainDeviceInfoPtr src);
-- 
2.7.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 06/10] conf: Introduce virDomainDeviceInfoNew()
Posted by Peter Krempa 7 years, 10 months ago
On Thu, Jun 29, 2017 at 20:03:59 +0200, Andrea Bolognani wrote:
> It allocates and initializes a virDomainDeviceInfo struct
> in one fell swoop.
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  src/conf/device_conf.c | 13 +++++++++++++
>  src/conf/device_conf.h |  1 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
> index 4644580..6ead830 100644
> --- a/src/conf/device_conf.c
> +++ b/src/conf/device_conf.c
> @@ -32,6 +32,19 @@
>  
>  #define VIR_FROM_THIS VIR_FROM_DEVICE
>  
> +virDomainDeviceInfoPtr
> +virDomainDeviceInfoNew(void)
> +{
> +    virDomainDeviceInfoPtr info;
> +
> +    if (VIR_ALLOC(info) < 0)
> +        return NULL;
> +
> +    virDomainDeviceInfoClear(info);

This is a lot of duplicated 0 setting. Given a quick scroll to the other
*New function ... we only set parameters which are non-null. 

The only code path calling the clearing fucntion which is not in a
fucntion which then frees the object completely is in
virDomainDeviceInfoParseXML. I don't think we need to do it here and
additionally the objects are not reused thus you should not need to set
anything non-null anywhere else.

ACK to the wrapper except for the call to virDomainDeviceInfoClear
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list