[ovs-dev,06/14] datapath-windows: Cleanup IpHelper.c

Message ID 20180709134056.7060-7-aserdean@ovn.org
State Changes Requested
Headers show
Series
  • Cleanup datapath-windows
Related show

Commit Message

Alin Gabriel Serdean July 9, 2018, 1:40 p.m.
Assign variables directly instead of reassigning them after.

Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
---
 datapath-windows/ovsext/IpHelper.c | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

Patch

diff --git a/datapath-windows/ovsext/IpHelper.c b/datapath-windows/ovsext/IpHelper.c
index 6bbd096c5..1ec10eb3d 100644
--- a/datapath-windows/ovsext/IpHelper.c
+++ b/datapath-windows/ovsext/IpHelper.c
@@ -368,11 +368,10 @@  OvsGetRoute(SOCKADDR_INET *destinationAddress,
     LIST_FORALL_SAFE(head, link, next) {
         SOCKADDR_INET crtSrcAddr = { 0 };
         MIB_IPFORWARD_ROW2 crtRoute = { 0 };
-        POVS_IPHELPER_INSTANCE crtInstance = NULL;
+        POVS_IPHELPER_INSTANCE crtInstance =
+            CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
         WCHAR interfaceName[IF_MAX_STRING_SIZE + 1];
 
-        crtInstance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
-
         ExAcquireResourceExclusiveLite(&crtInstance->lock, TRUE);
         result = GetBestRoute2(&crtInstance->internalRow.InterfaceLuid, 0,
                                NULL, destinationAddress, 0, &crtRoute,
@@ -385,7 +384,6 @@  OvsGetRoute(SOCKADDR_INET *destinationAddress,
 
         if (minMetric > crtRoute.Metric &&
             (!srcIp || srcIp == crtSrcAddr.Ipv4.sin_addr.S_un.S_addr)) {
-            status = STATUS_SUCCESS;
             size_t len = 0;
             minMetric = crtRoute.Metric;
             LOCK_STATE_EX lockState;
@@ -538,9 +536,8 @@  OvsUpdateIpInterfaceNotification(PMIB_IPINTERFACE_ROW ipRow)
     ExAcquireResourceExclusiveLite(&ovsInstanceListLock, TRUE);
     head = &(ovsInstanceList);
     LIST_FORALL_SAFE(head, link, next) {
-        POVS_IPHELPER_INSTANCE instance = NULL;
-
-        instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+        POVS_IPHELPER_INSTANCE instance =
+            CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
         ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
         if (OvsCheckInstanceRow(&instance->internalRow,
@@ -578,9 +575,8 @@  OvsAddIpInterfaceNotification(PMIB_IPINTERFACE_ROW ipRow)
     ExAcquireResourceExclusiveLite(&ovsInstanceListLock, TRUE);
     head = &(ovsInstanceList);
     LIST_FORALL_SAFE(head, link, next) {
-        POVS_IPHELPER_INSTANCE instance = NULL;
-
-        instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+        POVS_IPHELPER_INSTANCE instance =
+            CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
         ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
         if (OvsCheckInstanceRow(&instance->internalRow, &ipRow->InterfaceLuid,
@@ -684,9 +680,8 @@  OvsRemoveIpInterfaceNotification(PMIB_IPINTERFACE_ROW ipRow)
     ExAcquireResourceExclusiveLite(&ovsInstanceListLock, TRUE);
     head = &(ovsInstanceList);
     LIST_FORALL_SAFE(head, link, next) {
-        POVS_IPHELPER_INSTANCE instance = NULL;
-
-        instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+        POVS_IPHELPER_INSTANCE instance =
+            CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
         ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
         if (OvsCheckInstanceRow(&instance->internalRow, &ipRow->InterfaceLuid,
@@ -821,9 +816,8 @@  OvsChangeCallbackUnicastIpAddress(PVOID context,
         ExAcquireResourceExclusiveLite(&ovsInstanceListLock, TRUE);
         head = &(ovsInstanceList);
         LIST_FORALL_SAFE(head, link, next) {
-            POVS_IPHELPER_INSTANCE instance = NULL;
-
-            instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+            POVS_IPHELPER_INSTANCE instance =
+                CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
             ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
             if (instance->isIpConfigured &&
@@ -860,9 +854,8 @@  OvsChangeCallbackUnicastIpAddress(PVOID context,
         ExAcquireResourceExclusiveLite(&ovsInstanceListLock, TRUE);
         head = &(ovsInstanceList);
         LIST_FORALL_SAFE(head, link, next) {
-            POVS_IPHELPER_INSTANCE instance = NULL;
-
-            instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+            POVS_IPHELPER_INSTANCE instance =
+                CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
             ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
             if (instance->isIpConfigured &&
@@ -1461,8 +1454,8 @@  OvsIpHelperDeleteAllInstances()
     head = &ovsInstanceList;
     if (!IsListEmpty(head)) {
         LIST_FORALL_SAFE(head, link, next) {
-            POVS_IPHELPER_INSTANCE instance = NULL;
-            instance = CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
+            POVS_IPHELPER_INSTANCE instance =
+                CONTAINING_RECORD(link, OVS_IPHELPER_INSTANCE, link);
 
             ExAcquireResourceExclusiveLite(&instance->lock, TRUE);
 
@@ -1985,11 +1978,10 @@  ip_helper_wait:
 NTSTATUS
 OvsInitIpHelper(NDIS_HANDLE ndisFilterHandle)
 {
-    NTSTATUS status = NDIS_STATUS_SUCCESS;
+    NTSTATUS status = ExInitializeResourceLite(&ovsInstanceListLock);
     HANDLE threadHandle;
     UINT32 i;
 
-    status = ExInitializeResourceLite(&ovsInstanceListLock);
     if (status != NDIS_STATUS_SUCCESS) {
         return status;
     }