WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2/3] Fix compile warnings: ignoring return value of '

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2/3] Fix compile warnings: ignoring return value of 'xenbus_register_backend' ..
From: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Date: Thu, 8 Oct 2009 13:23:09 -0400
Cc: Jeremy Fitzhardinge <jeremy@xxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Delivery-date: Thu, 08 Oct 2009 10:29:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1255022590-9578-2-git-send-email-konrad.wilk@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1255022590-9578-1-git-send-email-konrad.wilk@xxxxxxxxxx> <1255022590-9578-2-git-send-email-konrad.wilk@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
We neglect to check the return value of xenbus_register_backend
and take actions when that fails. This patch fixes that and adds
code to deal with those type of failures.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
---
 drivers/xen/blkback/blkback.c   |   18 +++++++++++++-----
 drivers/xen/blkback/common.h    |    4 ++--
 drivers/xen/blkback/interface.c |    6 +++++-
 drivers/xen/blkback/xenbus.c    |    5 ++---
 drivers/xen/netback/common.h    |    2 +-
 drivers/xen/netback/netback.c   |   12 +++++++++++-
 drivers/xen/netback/xenbus.c    |    4 ++--
 7 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/drivers/xen/blkback/blkback.c b/drivers/xen/blkback/blkback.c
index e9e3de1..d0f9bd3 100644
--- a/drivers/xen/blkback/blkback.c
+++ b/drivers/xen/blkback/blkback.c
@@ -614,6 +614,7 @@ static void make_response(blkif_t *blkif, u64 id,
 static int __init blkif_init(void)
 {
        int i, mmap_pages;
+       int rc = 0;
 
        if (!xen_pv_domain())
                return -ENODEV;
@@ -626,13 +627,17 @@ static int __init blkif_init(void)
                                        mmap_pages, GFP_KERNEL);
        pending_pages         = alloc_empty_pages_and_pagevec(mmap_pages);
 
-       if (!pending_reqs || !pending_grant_handles || !pending_pages)
+       if (!pending_reqs || !pending_grant_handles || !pending_pages) {
+               rc = -ENOMEM;
                goto out_of_memory;
+       }
 
        for (i = 0; i < mmap_pages; i++)
                pending_grant_handles[i] = BLKBACK_INVALID_HANDLE;
 
-       blkif_interface_init();
+       rc = blkif_interface_init();
+       if (rc)
+               goto failed_init;
 
        memset(pending_reqs, 0, sizeof(pending_reqs));
        INIT_LIST_HEAD(&pending_free);
@@ -640,16 +645,19 @@ static int __init blkif_init(void)
        for (i = 0; i < blkif_reqs; i++)
                list_add_tail(&pending_reqs[i].free_list, &pending_free);
 
-       blkif_xenbus_init();
+       rc = blkif_xenbus_init();
+       if (rc)
+               goto failed_init;
 
        return 0;
 
  out_of_memory:
+       printk("%s: out of memory\n", __FUNCTION__);
+ failed_init:
        kfree(pending_reqs);
        kfree(pending_grant_handles);
        free_empty_pages_and_pagevec(pending_pages, mmap_pages);
-       printk("%s: out of memory\n", __FUNCTION__);
-       return -ENOMEM;
+       return rc;
 }
 
 module_init(blkif_init);
diff --git a/drivers/xen/blkback/common.h b/drivers/xen/blkback/common.h
index 57b7825..aaf3648 100644
--- a/drivers/xen/blkback/common.h
+++ b/drivers/xen/blkback/common.h
@@ -124,9 +124,9 @@ struct phys_req {
 
 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation);
 
-void blkif_interface_init(void);
+int blkif_interface_init(void);
 
-void blkif_xenbus_init(void);
+int blkif_xenbus_init(void);
 
 irqreturn_t blkif_be_int(int irq, void *dev_id);
 int blkif_schedule(void *arg);
diff --git a/drivers/xen/blkback/interface.c b/drivers/xen/blkback/interface.c
index c6c3e14..4c68fa7 100644
--- a/drivers/xen/blkback/interface.c
+++ b/drivers/xen/blkback/interface.c
@@ -175,8 +175,12 @@ void blkif_free(blkif_t *blkif)
        kmem_cache_free(blkif_cachep, blkif);
 }
 
-void __init blkif_interface_init(void)
+int __init blkif_interface_init(void)
 {
        blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t),
                                         0, 0, NULL);
+       if (!blkif_cachep)
+               return -ENOMEM;
+
+       return 0;       
 }
diff --git a/drivers/xen/blkback/xenbus.c b/drivers/xen/blkback/xenbus.c
index 650f4b3..04c0a12 100644
--- a/drivers/xen/blkback/xenbus.c
+++ b/drivers/xen/blkback/xenbus.c
@@ -535,8 +535,7 @@ static struct xenbus_driver blkback = {
 };
 
 
-void blkif_xenbus_init(void)
+int blkif_xenbus_init(void)
 {
-       /* XXX must_check */
-       (void)xenbus_register_backend(&blkback);
+       return xenbus_register_backend(&blkback);
 }
diff --git a/drivers/xen/netback/common.h b/drivers/xen/netback/common.h
index 9056be0..0675946 100644
--- a/drivers/xen/netback/common.h
+++ b/drivers/xen/netback/common.h
@@ -194,7 +194,7 @@ static inline void  netif_put(struct xen_netif *netif)
                wake_up(&netif->waiting_to_free);
 }
 
-void netif_xenbus_init(void);
+int netif_xenbus_init(void);
 
 #define netif_schedulable(netif)                               \
        (netif_running((netif)->dev) && netback_carrier_ok(netif))
diff --git a/drivers/xen/netback/netback.c b/drivers/xen/netback/netback.c
index d7d738e..860c61e 100644
--- a/drivers/xen/netback/netback.c
+++ b/drivers/xen/netback/netback.c
@@ -1536,6 +1536,7 @@ static int __init netback_init(void)
 {
        int i;
        struct page *page;
+       int rc = 0;
 
        if (!xen_domain())
                return -ENODEV;
@@ -1583,7 +1584,9 @@ static int __init netback_init(void)
 
        //netif_accel_init();
 
-       netif_xenbus_init();
+       rc = netif_xenbus_init();
+       if (rc)
+               goto failed_init;
 
 #ifdef NETBE_DEBUG_INTERRUPT
        (void)bind_virq_to_irqhandler(VIRQ_DEBUG,
@@ -1595,6 +1598,13 @@ static int __init netback_init(void)
 #endif
 
        return 0;
+
+failed_init:
+       free_empty_pages_and_pagevec(mmap_pages, MAX_PENDING_REQS);
+       del_timer(&netbk_tx_pending_timer);
+       del_timer(&net_timer);
+       return rc;
+
 }
 
 module_init(netback_init);
diff --git a/drivers/xen/netback/xenbus.c b/drivers/xen/netback/xenbus.c
index a492288..c46b235 100644
--- a/drivers/xen/netback/xenbus.c
+++ b/drivers/xen/netback/xenbus.c
@@ -447,8 +447,8 @@ static struct xenbus_driver netback = {
 };
 
 
-void netif_xenbus_init(void)
+int netif_xenbus_init(void)
 {
        printk(KERN_CRIT "registering netback\n");
-       (void)xenbus_register_backend(&netback);
+       return xenbus_register_backend(&netback);
 }
-- 
1.6.2.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel