[ovs-dev] [PATCH 1/3] ovs-lldp: Get rid of pointless null pointer check.

Ben Pfaff blp at ovn.org
Fri Mar 26 18:30:22 UTC 2021


lldpd_alloc_hardware() always returns nonnull.

At the same time, there's no reason that lldpd_alloc_hardware() doesn't
take a const char *, so change that.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 lib/lldp/lldpd.c | 2 +-
 lib/lldp/lldpd.h | 2 +-
 lib/ovs-lldp.c   | 8 +-------
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c
index 34738535dbd1..a024dc5e5835 100644
--- a/lib/lldp/lldpd.c
+++ b/lib/lldp/lldpd.c
@@ -77,7 +77,7 @@ lldpd_get_hardware(struct lldpd *cfg, char *name, int index,
 }
 
 struct lldpd_hardware *
-lldpd_alloc_hardware(struct lldpd *cfg, char *name, int index)
+lldpd_alloc_hardware(struct lldpd *cfg, const char *name, int index)
 {
     struct lldpd_hardware *hw;
 
diff --git a/lib/lldp/lldpd.h b/lib/lldp/lldpd.h
index 5267c112af5e..3f5be84a205e 100644
--- a/lib/lldp/lldpd.h
+++ b/lib/lldp/lldpd.h
@@ -76,7 +76,7 @@ lldpd_first_hardware(struct lldpd *lldpd)
 /* lldpd.c */
 struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
     char *, int, struct lldpd_ops *);
-struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int);
+struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, const char *, int);
 void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
 struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize,
     u_int32_t iface);
diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c
index 05c1dd4344be..162311fa45c3 100644
--- a/lib/ovs-lldp.c
+++ b/lib/ovs-lldp.c
@@ -801,13 +801,7 @@ lldp_create(const struct netdev *netdev,
     ovs_list_init(&lldp->lldpd->g_chassis);
     ovs_list_push_back(&lldp->lldpd->g_chassis, &lchassis->list);
 
-    if ((hw = lldpd_alloc_hardware(lldp->lldpd,
-                                   (char *) netdev_get_name(netdev),
-                                   0)) == NULL) {
-        VLOG_WARN("Unable to allocate space for %s",
-                  (char *) netdev_get_name(netdev));
-        out_of_memory();
-    }
+    hw = lldpd_alloc_hardware(lldp->lldpd, netdev_get_name(netdev), 0);
 
     ovs_refcount_init(&lldp->ref_cnt);
 #ifndef _WIN32
-- 
2.29.2



More information about the dev mailing list