[PATCH 3/3] storageBackendCreateRaw: remove unused created variable

Michal Privoznik mprivozn at redhat.com
Tue Jan 5 13:11:59 UTC 2021


On 12/29/20 12:29 PM, Yi Li wrote:
> refactor and remove unused created variable
> 
> Signed-off-by: Yi Li <yili at winhong.com>
> ---
>   src/storage/storage_util.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
> index c6d0f7a97c..c02ece8253 100644
> --- a/src/storage/storage_util.c
> +++ b/src/storage/storage_util.c
> @@ -384,11 +384,10 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool,
>                           unsigned int flags)
>   {
>       virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
> -    int ret = -1;
> +    int ret = 0;

No, please don't initialize this to zero. The pattern we use (and are 
used to) is:

   int ret = -1;

   if (something)
     goto cleanup;

   if (something else)
     goto cleanup;

   ret = 0;
  cleanup:
   if (ret < 0)
     cleanupWhatsNeeded();

   return ret;


Alternatively, we can rename 'cleanup' to 'error' and do the following 
(without even having to use @ret variable):

   if (something)
     goto error;

   if (something else)
     goto error;

   return 0;
  error:
   cleanupWhatsNeeded();
   return -1;

Michal




More information about the libvir-list mailing list