qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Add missing initialization for g_autofree variables
@ 2021-03-15 10:13 mrezanin
  2021-03-15 10:21 ` Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: mrezanin @ 2021-03-15 10:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Thomas Huth, Cornelia Huck

From: Miroslav Rezanina <mrezanin@redhat.com>

When declaring g_autofree variable without inicialization, compiler
will raise "may be used uninitialized in this function" warning due
to automatic free handling.

This is mentioned in docs/devel/style.rst (quote from section
"Automatic memory deallocation"):

  * Variables declared with g_auto* MUST always be initialized,
    otherwise the cleanup function will use uninitialized stack memory

Add inicialization for these declarations to prevent the warning and
comply with coding style.

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

---
* v3:
  -- allocate in s390_pci_update_dma_avail instead of NULL init

* v2:
  -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
     fixed by patch sent by Zenghui Yu (multi-process: Initialize
     variables declared with g_auto*)
---
 hw/s390x/s390-pci-vfio.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index ead4f222d5..2a153fa8c9 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -29,14 +29,11 @@
  */
 bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
 {
-    g_autofree struct vfio_iommu_type1_info *info;
-    uint32_t argsz;
+    uint32_t argsz = sizeof(struct vfio_iommu_type1_info);
+    g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz);
 
     assert(avail);
 
-    argsz = sizeof(struct vfio_iommu_type1_info);
-    info = g_malloc0(argsz);
-
     /*
      * If the specified argsz is not large enough to contain all capabilities
      * it will be updated upon return from the ioctl.  Retry until we have
@@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
  */
 void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
 {
-    g_autofree struct vfio_device_info *info;
+    g_autofree struct vfio_device_info *info = NULL;
     VFIOPCIDevice *vfio_pci;
     uint32_t argsz;
     int fd;
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Add missing initialization for g_autofree variables
  2021-03-15 10:13 [PATCH v3] Add missing initialization for g_autofree variables mrezanin
@ 2021-03-15 10:21 ` Philippe Mathieu-Daudé
  2021-03-15 10:42 ` Cornelia Huck
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-03-15 10:21 UTC (permalink / raw)
  To: mrezanin, qemu-devel, qemu-s390x; +Cc: Thomas Huth, Cornelia Huck

On 3/15/21 11:13 AM, mrezanin@redhat.com wrote:
> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> When declaring g_autofree variable without inicialization, compiler

Typo "initialization"

> will raise "may be used uninitialized in this function" warning due
> to automatic free handling.
> 
> This is mentioned in docs/devel/style.rst (quote from section
> "Automatic memory deallocation"):
> 
>   * Variables declared with g_auto* MUST always be initialized,
>     otherwise the cleanup function will use uninitialized stack memory
> 
> Add inicialization for these declarations to prevent the warning and

"initialization"

> comply with coding style.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> 
> ---
> * v3:
>   -- allocate in s390_pci_update_dma_avail instead of NULL init
> 
> * v2:
>   -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
>      fixed by patch sent by Zenghui Yu (multi-process: Initialize
>      variables declared with g_auto*)
> ---
>  hw/s390x/s390-pci-vfio.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)

Maybe "hw/s390x/s390-pci-vfio" prefix in subject?

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Add missing initialization for g_autofree variables
  2021-03-15 10:13 [PATCH v3] Add missing initialization for g_autofree variables mrezanin
  2021-03-15 10:21 ` Philippe Mathieu-Daudé
@ 2021-03-15 10:42 ` Cornelia Huck
  2021-03-15 13:31   ` Matthew Rosato
  2021-03-15 11:34 ` Thomas Huth
  2021-03-15 17:32 ` Cornelia Huck
  3 siblings, 1 reply; 6+ messages in thread
From: Cornelia Huck @ 2021-03-15 10:42 UTC (permalink / raw)
  To: mrezanin; +Cc: qemu-s390x, Thomas Huth, qemu-devel, Matthew Rosato

On Mon, 15 Mar 2021 11:13:52 +0100
mrezanin@redhat.com wrote:

> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> When declaring g_autofree variable without inicialization, compiler
> will raise "may be used uninitialized in this function" warning due
> to automatic free handling.
> 
> This is mentioned in docs/devel/style.rst (quote from section
> "Automatic memory deallocation"):
> 
>   * Variables declared with g_auto* MUST always be initialized,
>     otherwise the cleanup function will use uninitialized stack memory
> 
> Add inicialization for these declarations to prevent the warning and
> comply with coding style.

Fixes: cd7498d07fbb ("s390x/pci: Add routine to get the vfio dma available count")
Fixes: 1e7552ff5c34 ("s390x/pci: get zPCI function info from host")

I can fix the spelling mistakes pointed out by Phil while applying, and
also add an 's390x/pci' prefix.

Would not mind a quick test run from someone with the hardware.

> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> 
> ---
> * v3:
>   -- allocate in s390_pci_update_dma_avail instead of NULL init
> 
> * v2:
>   -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
>      fixed by patch sent by Zenghui Yu (multi-process: Initialize
>      variables declared with g_auto*)
> ---
>  hw/s390x/s390-pci-vfio.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index ead4f222d5..2a153fa8c9 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -29,14 +29,11 @@
>   */
>  bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
>  {
> -    g_autofree struct vfio_iommu_type1_info *info;
> -    uint32_t argsz;
> +    uint32_t argsz = sizeof(struct vfio_iommu_type1_info);
> +    g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz);
>  
>      assert(avail);
>  
> -    argsz = sizeof(struct vfio_iommu_type1_info);
> -    info = g_malloc0(argsz);
> -
>      /*
>       * If the specified argsz is not large enough to contain all capabilities
>       * it will be updated upon return from the ioctl.  Retry until we have
> @@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
>   */
>  void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
>  {
> -    g_autofree struct vfio_device_info *info;
> +    g_autofree struct vfio_device_info *info = NULL;
>      VFIOPCIDevice *vfio_pci;
>      uint32_t argsz;
>      int fd;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Add missing initialization for g_autofree variables
  2021-03-15 10:13 [PATCH v3] Add missing initialization for g_autofree variables mrezanin
  2021-03-15 10:21 ` Philippe Mathieu-Daudé
  2021-03-15 10:42 ` Cornelia Huck
@ 2021-03-15 11:34 ` Thomas Huth
  2021-03-15 17:32 ` Cornelia Huck
  3 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2021-03-15 11:34 UTC (permalink / raw)
  To: mrezanin, qemu-devel; +Cc: Cornelia Huck

On 15/03/2021 11.13, mrezanin@redhat.com wrote:
> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> When declaring g_autofree variable without inicialization, compiler
> will raise "may be used uninitialized in this function" warning due
> to automatic free handling.
> 
> This is mentioned in docs/devel/style.rst (quote from section
> "Automatic memory deallocation"):
> 
>    * Variables declared with g_auto* MUST always be initialized,
>      otherwise the cleanup function will use uninitialized stack memory
> 
> Add inicialization for these declarations to prevent the warning and
> comply with coding style.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> 
> ---
> * v3:
>    -- allocate in s390_pci_update_dma_avail instead of NULL init
> 
> * v2:
>    -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
>       fixed by patch sent by Zenghui Yu (multi-process: Initialize
>       variables declared with g_auto*)
> ---
>   hw/s390x/s390-pci-vfio.c | 9 +++------
>   1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index ead4f222d5..2a153fa8c9 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -29,14 +29,11 @@
>    */
>   bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
>   {
> -    g_autofree struct vfio_iommu_type1_info *info;
> -    uint32_t argsz;
> +    uint32_t argsz = sizeof(struct vfio_iommu_type1_info);
> +    g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz);
>   
>       assert(avail);
>   
> -    argsz = sizeof(struct vfio_iommu_type1_info);
> -    info = g_malloc0(argsz);
> -
>       /*
>        * If the specified argsz is not large enough to contain all capabilities
>        * it will be updated upon return from the ioctl.  Retry until we have
> @@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
>    */
>   void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
>   {
> -    g_autofree struct vfio_device_info *info;
> +    g_autofree struct vfio_device_info *info = NULL;
>       VFIOPCIDevice *vfio_pci;
>       uint32_t argsz;
>       int fd;
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Add missing initialization for g_autofree variables
  2021-03-15 10:42 ` Cornelia Huck
@ 2021-03-15 13:31   ` Matthew Rosato
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Rosato @ 2021-03-15 13:31 UTC (permalink / raw)
  To: Cornelia Huck, mrezanin; +Cc: qemu-s390x, Thomas Huth, qemu-devel

On 3/15/21 6:42 AM, Cornelia Huck wrote:
> On Mon, 15 Mar 2021 11:13:52 +0100
> mrezanin@redhat.com wrote:
> 
>> From: Miroslav Rezanina <mrezanin@redhat.com>
>>
>> When declaring g_autofree variable without inicialization, compiler
>> will raise "may be used uninitialized in this function" warning due
>> to automatic free handling.
>>
>> This is mentioned in docs/devel/style.rst (quote from section
>> "Automatic memory deallocation"):
>>
>>    * Variables declared with g_auto* MUST always be initialized,
>>      otherwise the cleanup function will use uninitialized stack memory
>>
>> Add inicialization for these declarations to prevent the warning and
>> comply with coding style.
> 
> Fixes: cd7498d07fbb ("s390x/pci: Add routine to get the vfio dma available count")
> Fixes: 1e7552ff5c34 ("s390x/pci: get zPCI function info from host")
> 
> I can fix the spelling mistakes pointed out by Phil while applying, and
> also add an 's390x/pci' prefix.
> 
> Would not mind a quick test run from someone with the hardware.

Sure, I took this for a spin (ConnectX-3 VF via vfio-pci) and made sure 
both code paths were being driven without issue.  Code looks fine as well.

Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>

> 
>>
>> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
>>
>> ---
>> * v3:
>>    -- allocate in s390_pci_update_dma_avail instead of NULL init
>>
>> * v2:
>>    -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
>>       fixed by patch sent by Zenghui Yu (multi-process: Initialize
>>       variables declared with g_auto*)
>> ---
>>   hw/s390x/s390-pci-vfio.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
>> index ead4f222d5..2a153fa8c9 100644
>> --- a/hw/s390x/s390-pci-vfio.c
>> +++ b/hw/s390x/s390-pci-vfio.c
>> @@ -29,14 +29,11 @@
>>    */
>>   bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
>>   {
>> -    g_autofree struct vfio_iommu_type1_info *info;
>> -    uint32_t argsz;
>> +    uint32_t argsz = sizeof(struct vfio_iommu_type1_info);
>> +    g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz);
>>   
>>       assert(avail);
>>   
>> -    argsz = sizeof(struct vfio_iommu_type1_info);
>> -    info = g_malloc0(argsz);
>> -
>>       /*
>>        * If the specified argsz is not large enough to contain all capabilities
>>        * it will be updated upon return from the ioctl.  Retry until we have
>> @@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
>>    */
>>   void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
>>   {
>> -    g_autofree struct vfio_device_info *info;
>> +    g_autofree struct vfio_device_info *info = NULL;
>>       VFIOPCIDevice *vfio_pci;
>>       uint32_t argsz;
>>       int fd;
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] Add missing initialization for g_autofree variables
  2021-03-15 10:13 [PATCH v3] Add missing initialization for g_autofree variables mrezanin
                   ` (2 preceding siblings ...)
  2021-03-15 11:34 ` Thomas Huth
@ 2021-03-15 17:32 ` Cornelia Huck
  3 siblings, 0 replies; 6+ messages in thread
From: Cornelia Huck @ 2021-03-15 17:32 UTC (permalink / raw)
  To: mrezanin; +Cc: Thomas Huth, qemu-devel

On Mon, 15 Mar 2021 11:13:52 +0100
mrezanin@redhat.com wrote:

> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> When declaring g_autofree variable without inicialization, compiler
> will raise "may be used uninitialized in this function" warning due
> to automatic free handling.
> 
> This is mentioned in docs/devel/style.rst (quote from section
> "Automatic memory deallocation"):
> 
>   * Variables declared with g_auto* MUST always be initialized,
>     otherwise the cleanup function will use uninitialized stack memory
> 
> Add inicialization for these declarations to prevent the warning and
> comply with coding style.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> 
> ---
> * v3:
>   -- allocate in s390_pci_update_dma_avail instead of NULL init
> 
> * v2:
>   -- Removed fixes in hw/remote/memory.c and hw/remote/proxy.c
>      fixed by patch sent by Zenghui Yu (multi-process: Initialize
>      variables declared with g_auto*)
> ---
>  hw/s390x/s390-pci-vfio.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
> index ead4f222d5..2a153fa8c9 100644
> --- a/hw/s390x/s390-pci-vfio.c
> +++ b/hw/s390x/s390-pci-vfio.c
> @@ -29,14 +29,11 @@
>   */
>  bool s390_pci_update_dma_avail(int fd, unsigned int *avail)
>  {
> -    g_autofree struct vfio_iommu_type1_info *info;
> -    uint32_t argsz;
> +    uint32_t argsz = sizeof(struct vfio_iommu_type1_info);
> +    g_autofree struct vfio_iommu_type1_info *info = g_malloc0(argsz);
>  
>      assert(avail);
>  
> -    argsz = sizeof(struct vfio_iommu_type1_info);
> -    info = g_malloc0(argsz);
> -
>      /*
>       * If the specified argsz is not large enough to contain all capabilities
>       * it will be updated upon return from the ioctl.  Retry until we have
> @@ -230,7 +227,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
>   */
>  void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
>  {
> -    g_autofree struct vfio_device_info *info;
> +    g_autofree struct vfio_device_info *info = NULL;
>      VFIOPCIDevice *vfio_pci;
>      uint32_t argsz;
>      int fd;

Thanks, applied.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-15 17:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-15 10:13 [PATCH v3] Add missing initialization for g_autofree variables mrezanin
2021-03-15 10:21 ` Philippe Mathieu-Daudé
2021-03-15 10:42 ` Cornelia Huck
2021-03-15 13:31   ` Matthew Rosato
2021-03-15 11:34 ` Thomas Huth
2021-03-15 17:32 ` Cornelia Huck

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).