[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH] lib/uknetdev: netdev register fails on lib param



einfo returns error when the user does not provide the library
parameters.

Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 lib/uknetdev/netdev.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index 74be618..87322c7 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -120,18 +120,16 @@ static struct uk_netdev_einfo *_alloc_einfo(struct 
uk_alloc *a)
 {
        struct uk_netdev_einfo *_einfo = NULL;
 
-       if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
-               _einfo = uk_zalloc(a, sizeof(*_einfo));
-               if (!_einfo) {
-                       uk_pr_warn("Failed to allocate memory for netdev 
config\n");
-                       return NULL;
-               }
-
-               _einfo->ipv4_addr = _parse_ipv4_addr();
-               _einfo->ipv4_net_mask = _parse_ipv4_net_mask();
-               _einfo->ipv4_gw_addr = _parse_ipv4_gw_addr();
+       _einfo = uk_zalloc(a, sizeof(*_einfo));
+       if (!_einfo) {
+               uk_pr_warn("Failed to allocate memory for netdev config\n");
+               return ERR2PTR(-ENOMEM);
        }
 
+       _einfo->ipv4_addr = _parse_ipv4_addr();
+       _einfo->ipv4_net_mask = _parse_ipv4_net_mask();
+       _einfo->ipv4_gw_addr = _parse_ipv4_gw_addr();
+
        return _einfo;
 }
 
@@ -162,9 +160,11 @@ int uk_netdev_drv_register(struct uk_netdev *dev, struct 
uk_alloc *a,
        if (!dev->_data)
                return -ENOMEM;
 
-       dev->_einfo = _alloc_einfo(a);
-       if (!dev->_einfo)
-               return -ENOMEM;
+       if (ipv4_addr || ipv4_subnet_mask || ipv4_gw_addr) {
+               dev->_einfo = _alloc_einfo(a);
+               if (PTRISERR(dev->_einfo))
+                       return PTR2ERR(dev->_einfo);
+       }
 
        UK_TAILQ_INSERT_TAIL(&uk_netdev_list, dev, _list);
        uk_pr_info("Registered netdev%"PRIu16": %p (%s)\n",
-- 
2.7.4




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.