diff mbox

[02/10] libxl-pci: clean unused return variable

Message ID 1459514413-18682-3-git-send-email-paulinaszubarczyk@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paulina Szubarczyk April 1, 2016, 12:40 p.m. UTC
libxl_device_pci_assignable_list returns:
- list of the libxl_device_pci
- NULL in case of error

the rc variable is unused as return code.

Signed-off-by: Paulina Szubarczyk <paulinaszubarczyk@gmail.com>
---
 tools/libxl/libxl_pci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Roger Pau Monne April 1, 2016, 2:13 p.m. UTC | #1
On Fri, 1 Apr 2016, Paulina Szubarczyk wrote:
> libxl_device_pci_assignable_list returns:
> - list of the libxl_device_pci
> - NULL in case of error
> 
> the rc variable is unused as return code.
> 
> Signed-off-by: Paulina Szubarczyk <paulinaszubarczyk@gmail.com>
> ---
>  tools/libxl/libxl_pci.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
> index 3435ce2..6051ee4 100644
> --- a/tools/libxl/libxl_pci.c
> +++ b/tools/libxl/libxl_pci.c
> @@ -397,12 +397,11 @@ libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num)
>      libxl_device_pci *pcidevs = NULL, *new, *assigned;
>      struct dirent *de;
>      DIR *dir;
> -    int rc, num_assigned;
> +    int num_assigned;
>  
>      *num = 0;
>  
> -    rc = get_all_assigned_devices(gc, &assigned, &num_assigned);
> -    if ( rc )
> +    if ( get_all_assigned_devices(gc, &assigned, &num_assigned) )
>          goto out;

This is against libxl coding style, see the file in 
tools/libxl/CODING_STYLE:

  * Function calls which might fail (ie most function calls) are
    handled by putting the return/status value into a variable, and
    then checking it in a separate statement:
            char *dompath = libxl__xs_get_dompath(gc, bl->domid);
            if (!dompath) { rc = ERROR_FAIL; goto out; }

The only issues with this piece of code is the extra spaces inside the 
parentheses AFAICT.

There are other things that you can fix in this function, like removing 
the extra "out_closedir" label. There are cleaner ways to achieve the same 
using a single "out" label.

Roger.
diff mbox

Patch

diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c
index 3435ce2..6051ee4 100644
--- a/tools/libxl/libxl_pci.c
+++ b/tools/libxl/libxl_pci.c
@@ -397,12 +397,11 @@  libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num)
     libxl_device_pci *pcidevs = NULL, *new, *assigned;
     struct dirent *de;
     DIR *dir;
-    int rc, num_assigned;
+    int num_assigned;
 
     *num = 0;
 
-    rc = get_all_assigned_devices(gc, &assigned, &num_assigned);
-    if ( rc )
+    if ( get_all_assigned_devices(gc, &assigned, &num_assigned) )
         goto out;
 
     dir = opendir(SYSFS_PCIBACK_DRIVER);