[PATCH v2 4/6] rpc: Change return type of virNetClientAddStream to void

Alexander Kuznetsov posted 6 patches 3 weeks, 2 days ago
[PATCH v2 4/6] rpc: Change return type of virNetClientAddStream to void
Posted by Alexander Kuznetsov 3 weeks, 2 days ago
This function return value is invariant since VIR_EXPAND_N check
removal in 7d2fd6e, so change its type and remove all dependent checks.

Found by Linux Verification Center (linuxtesting.org) with Svace.

Reported-by: Pavel Nekrasov <p.nekrasov@fobos-nt.ru>
Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
---
 src/remote/remote_driver.c | 10 ++--------
 src/rpc/gendispatch.pl     |  5 +----
 src/rpc/virnetclient.c     |  3 +--
 src/rpc/virnetclient.h     |  2 +-
 4 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 4a16b8ef1d..307f9ca945 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5663,10 +5663,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
                                         false)))
         return -1;
 
-    if (virNetClientAddStream(priv->client, netst) < 0) {
-        virObjectUnref(netst);
-        return -1;
-    }
+    virNetClientAddStream(priv->client, netst);
 
     st->driver = &remoteStreamDrv;
     st->privateData = netst;
@@ -6432,10 +6429,7 @@ remoteDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
                                         false)))
         goto cleanup;
 
-    if (virNetClientAddStream(priv->client, netst) < 0) {
-        virObjectUnref(netst);
-        goto cleanup;
-    }
+    virNetClientAddStream(priv->client, netst);
 
     st->driver = &remoteStreamDrv;
     st->privateData = netst;
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index c5842dc796..724a6aed6e 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -1822,10 +1822,7 @@ elsif ($mode eq "client") {
             print "    if (!(netst = virNetClientStreamNew(priv->remoteProgram, $call->{constname}, priv->counter, sparse)))\n";
             print "        goto cleanup;\n";
             print "\n";
-            print "    if (virNetClientAddStream(priv->client, netst) < 0) {\n";
-            print "        virObjectUnref(netst);\n";
-            print "        goto cleanup;\n";
-            print "    }";
+            print "    virNetClientAddStream(priv->client, netst);\n";
             print "\n";
             print "    st->driver = &remoteStreamDrv;\n";
             print "    st->privateData = netst;\n";
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index f0d30b63ba..39ccbd739c 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1065,7 +1065,7 @@ void virNetClientAddProgram(virNetClient *client,
 }
 
 
-int virNetClientAddStream(virNetClient *client,
+void virNetClientAddStream(virNetClient *client,
                           virNetClientStream *st)
 {
     virObjectLock(client);
@@ -1074,7 +1074,6 @@ int virNetClientAddStream(virNetClient *client,
     client->streams[client->nstreams-1] = virObjectRef(st);
 
     virObjectUnlock(client);
-    return 0;
 }
 
 
diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
index 7726b57ef4..29099791a0 100644
--- a/src/rpc/virnetclient.h
+++ b/src/rpc/virnetclient.h
@@ -120,7 +120,7 @@ bool virNetClientHasPassFD(virNetClient *client);
 void virNetClientAddProgram(virNetClient *client,
                            virNetClientProgram *prog);
 
-int virNetClientAddStream(virNetClient *client,
+void virNetClientAddStream(virNetClient *client,
                           virNetClientStream *st);
 
 void virNetClientRemoveStream(virNetClient *client,
-- 
2.42.2
Re: [PATCH v2 4/6] rpc: Change return type of virNetClientAddStream to void
Posted by Jiri Denemark 1 week, 1 day ago
On Thu, Nov 28, 2024 at 18:21:20 +0300, Alexander Kuznetsov wrote:
> This function return value is invariant since VIR_EXPAND_N check
> removal in 7d2fd6e, so change its type and remove all dependent checks.
> 
> Found by Linux Verification Center (linuxtesting.org) with Svace.
> 
> Reported-by: Pavel Nekrasov <p.nekrasov@fobos-nt.ru>
> Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
> ---
>  src/remote/remote_driver.c | 10 ++--------
>  src/rpc/gendispatch.pl     |  5 +----
>  src/rpc/virnetclient.c     |  3 +--
>  src/rpc/virnetclient.h     |  2 +-
>  4 files changed, 5 insertions(+), 15 deletions(-)
...
> diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
> index f0d30b63ba..39ccbd739c 100644
> --- a/src/rpc/virnetclient.c
> +++ b/src/rpc/virnetclient.c
> @@ -1065,7 +1065,7 @@ void virNetClientAddProgram(virNetClient *client,
>  }
>  
>  
> -int virNetClientAddStream(virNetClient *client,
> +void virNetClientAddStream(virNetClient *client,
>                            virNetClientStream *st)

Indentation.

>  {
>      virObjectLock(client);
> @@ -1074,7 +1074,6 @@ int virNetClientAddStream(virNetClient *client,
>      client->streams[client->nstreams-1] = virObjectRef(st);
>  
>      virObjectUnlock(client);
> -    return 0;
>  }
>  
>  
> diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
> index 7726b57ef4..29099791a0 100644
> --- a/src/rpc/virnetclient.h
> +++ b/src/rpc/virnetclient.h
> @@ -120,7 +120,7 @@ bool virNetClientHasPassFD(virNetClient *client);
>  void virNetClientAddProgram(virNetClient *client,
>                             virNetClientProgram *prog);
>  
> -int virNetClientAddStream(virNetClient *client,
> +void virNetClientAddStream(virNetClient *client,
>                            virNetClientStream *st);

Indentation.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Re: [PATCH v2 4/6] rpc: Change return type of virNetClientAddStream to void
Posted by Jiri Denemark 1 week, 1 day ago
On Thu, Nov 28, 2024 at 18:21:20 +0300, Alexander Kuznetsov wrote:
> This function return value is invariant since VIR_EXPAND_N check
> removal in 7d2fd6e, so change its type and remove all dependent checks.
> 
> Found by Linux Verification Center (linuxtesting.org) with Svace.
> 
> Reported-by: Pavel Nekrasov <p.nekrasov@fobos-nt.ru>
> Signed-off-by: Alexander Kuznetsov <kuznetsovam@altlinux.org>
> ---
>  src/remote/remote_driver.c | 10 ++--------
>  src/rpc/gendispatch.pl     |  5 +----
>  src/rpc/virnetclient.c     |  3 +--
>  src/rpc/virnetclient.h     |  2 +-
>  4 files changed, 5 insertions(+), 15 deletions(-)
...
> diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
> index f0d30b63ba..39ccbd739c 100644
> --- a/src/rpc/virnetclient.c
> +++ b/src/rpc/virnetclient.c
> @@ -1065,7 +1065,7 @@ void virNetClientAddProgram(virNetClient *client,
>  }
>  
>  
> -int virNetClientAddStream(virNetClient *client,
> +void virNetClientAddStream(virNetClient *client,
>                            virNetClientStream *st)

Indentation.

>  {
>      virObjectLock(client);
> @@ -1074,7 +1074,6 @@ int virNetClientAddStream(virNetClient *client,
>      client->streams[client->nstreams-1] = virObjectRef(st);
>  
>      virObjectUnlock(client);
> -    return 0;
>  }
>  
>  
> diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
> index 7726b57ef4..29099791a0 100644
> --- a/src/rpc/virnetclient.h
> +++ b/src/rpc/virnetclient.h
> @@ -120,7 +120,7 @@ bool virNetClientHasPassFD(virNetClient *client);
>  void virNetClientAddProgram(virNetClient *client,
>                             virNetClientProgram *prog);
>  
> -int virNetClientAddStream(virNetClient *client,
> +void virNetClientAddStream(virNetClient *client,
>                            virNetClientStream *st);

Indentation.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>