ia64/xen-unstable

changeset 17633:c6533d246a81

minios: free blkfront resources on error/shutdown

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon May 12 11:01:21 2008 +0100 (2008-05-12)
parents 9f8b8315339e
children 0f18d5454c7b
files extras/mini-os/blkfront.c
line diff
     1.1 --- a/extras/mini-os/blkfront.c	Mon May 12 10:36:27 2008 +0100
     1.2 +++ b/extras/mini-os/blkfront.c	Mon May 12 11:01:21 2008 +0100
     1.3 @@ -68,6 +68,21 @@ void blkfront_handler(evtchn_port_t port
     1.4      wake_up(&blkfront_queue);
     1.5  }
     1.6  
     1.7 +static void free_blkfront(struct blkfront_dev *dev)
     1.8 +{
     1.9 +    mask_evtchn(dev->evtchn);
    1.10 +
    1.11 +    free(dev->backend);
    1.12 +
    1.13 +    gnttab_end_access(dev->ring_ref);
    1.14 +    free_page(dev->ring.sring);
    1.15 +
    1.16 +    unbind_evtchn(dev->evtchn);
    1.17 +
    1.18 +    free(dev->nodename);
    1.19 +    free(dev);
    1.20 +}
    1.21 +
    1.22  struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info)
    1.23  {
    1.24      xenbus_transaction_t xbt;
    1.25 @@ -88,6 +103,7 @@ struct blkfront_dev *init_blkfront(char 
    1.26      printk("******************* BLKFRONT for %s **********\n\n\n", nodename);
    1.27  
    1.28      dev = malloc(sizeof(*dev));
    1.29 +    memset(dev, 0, sizeof(*dev));
    1.30      dev->nodename = strdup(nodename);
    1.31  
    1.32      snprintf(path, sizeof(path), "%s/backend-id", nodename);
    1.33 @@ -139,7 +155,7 @@ again:
    1.34  
    1.35  abort_transaction:
    1.36      xenbus_transaction_end(xbt, 1, &retry);
    1.37 -    return NULL;
    1.38 +    goto error;
    1.39  
    1.40  done:
    1.41  
    1.42 @@ -147,7 +163,7 @@ done:
    1.43      msg = xenbus_read(XBT_NIL, path, &dev->backend);
    1.44      if (msg) {
    1.45          printk("Error %s when reading the backend path %s\n", msg, path);
    1.46 -        return NULL;
    1.47 +        goto error;
    1.48      }
    1.49  
    1.50      printk("backend at %s\n", dev->backend);
    1.51 @@ -160,7 +176,7 @@ done:
    1.52          msg = xenbus_read(XBT_NIL, path, &c);
    1.53          if (msg) {
    1.54              printk("Error %s when reading the mode\n", msg);
    1.55 -            return NULL;
    1.56 +            goto error;
    1.57          }
    1.58          if (*c == 'w')
    1.59              dev->info.mode = O_RDWR;
    1.60 @@ -198,6 +214,10 @@ done:
    1.61      printk("**************************\n");
    1.62  
    1.63      return dev;
    1.64 +
    1.65 +error:
    1.66 +    free_blkfront(dev);
    1.67 +    return NULL;
    1.68  }
    1.69  
    1.70  void shutdown_blkfront(struct blkfront_dev *dev)
    1.71 @@ -220,11 +240,7 @@ void shutdown_blkfront(struct blkfront_d
    1.72  
    1.73      xenbus_unwatch_path(XBT_NIL, path);
    1.74  
    1.75 -    unbind_evtchn(dev->evtchn);
    1.76 -
    1.77 -    free(nodename);
    1.78 -    free(dev->backend);
    1.79 -    free(dev);
    1.80 +    free_blkfront(dev);
    1.81  }
    1.82  
    1.83  static void blkfront_wait_slot(struct blkfront_dev *dev)