ia64/xen-unstable

changeset 17639:3ea09a104f5a

minios: free fbfront resources on error/shutdown

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 13 09:47:52 2008 +0100 (2008-05-13)
parents 2ab64478bd81
children 900228550847
files extras/mini-os/fbfront.c
line diff
     1.1 --- a/extras/mini-os/fbfront.c	Tue May 13 09:21:28 2008 +0100
     1.2 +++ b/extras/mini-os/fbfront.c	Tue May 13 09:47:52 2008 +0100
     1.3 @@ -49,6 +49,20 @@ void kbdfront_handler(evtchn_port_t port
     1.4      wake_up(&kbdfront_queue);
     1.5  }
     1.6  
     1.7 +static void free_kbdfront(struct kbdfront_dev *dev)
     1.8 +{
     1.9 +    mask_evtchn(dev->evtchn);
    1.10 +
    1.11 +    free(dev->backend);
    1.12 +
    1.13 +    free_page(dev->page);
    1.14 +
    1.15 +    unbind_evtchn(dev->evtchn);
    1.16 +
    1.17 +    free(dev->nodename);
    1.18 +    free(dev);
    1.19 +}
    1.20 +
    1.21  struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer)
    1.22  {
    1.23      xenbus_transaction_t xbt;
    1.24 @@ -122,7 +136,7 @@ again:
    1.25  
    1.26  abort_transaction:
    1.27      xenbus_transaction_end(xbt, 1, &retry);
    1.28 -    return NULL;
    1.29 +    goto error;
    1.30  
    1.31  done:
    1.32  
    1.33 @@ -130,7 +144,7 @@ done:
    1.34      msg = xenbus_read(XBT_NIL, path, &dev->backend);
    1.35      if (msg) {
    1.36          printk("Error %s when reading the backend path %s\n", msg, path);
    1.37 -        return NULL;
    1.38 +        goto error;
    1.39      }
    1.40  
    1.41      printk("backend at %s\n", dev->backend);
    1.42 @@ -153,6 +167,9 @@ done:
    1.43      printk("************************** KBDFRONT\n");
    1.44  
    1.45      return dev;
    1.46 +error:
    1.47 +    free_kbdfront(dev);
    1.48 +    return NULL;
    1.49  }
    1.50  
    1.51  int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n)
    1.52 @@ -208,12 +225,7 @@ void shutdown_kbdfront(struct kbdfront_d
    1.53  
    1.54      xenbus_unwatch_path(XBT_NIL, path);
    1.55  
    1.56 -    unbind_evtchn(dev->evtchn);
    1.57 -
    1.58 -    free_page(dev->page);
    1.59 -    free(nodename);
    1.60 -    free(dev->backend);
    1.61 -    free(dev);
    1.62 +    free_kbdfront(dev);
    1.63  }
    1.64  
    1.65  #ifdef HAVE_LIBC
    1.66 @@ -272,6 +284,20 @@ void fbfront_handler(evtchn_port_t port,
    1.67      wake_up(&fbfront_queue);
    1.68  }
    1.69  
    1.70 +static void free_fbfront(struct fbfront_dev *dev)
    1.71 +{
    1.72 +    mask_evtchn(dev->evtchn);
    1.73 +
    1.74 +    free(dev->backend);
    1.75 +
    1.76 +    free_page(dev->page);
    1.77 +
    1.78 +    unbind_evtchn(dev->evtchn);
    1.79 +
    1.80 +    free(dev->nodename);
    1.81 +    free(dev);
    1.82 +}
    1.83 +
    1.84  int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n)
    1.85  {
    1.86      struct xenfb_page *page = dev->page;
    1.87 @@ -401,7 +427,7 @@ again:
    1.88  
    1.89  abort_transaction:
    1.90      xenbus_transaction_end(xbt, 1, &retry);
    1.91 -    return NULL;
    1.92 +    goto error;
    1.93  
    1.94  done:
    1.95  
    1.96 @@ -409,7 +435,7 @@ done:
    1.97      msg = xenbus_read(XBT_NIL, path, &dev->backend);
    1.98      if (msg) {
    1.99          printk("Error %s when reading the backend path %s\n", msg, path);
   1.100 -        return NULL;
   1.101 +        goto error;
   1.102      }
   1.103  
   1.104      printk("backend at %s\n", dev->backend);
   1.105 @@ -435,6 +461,10 @@ done:
   1.106      printk("************************** FBFRONT\n");
   1.107  
   1.108      return dev;
   1.109 +
   1.110 +error:
   1.111 +    free_fbfront(dev);
   1.112 +    return NULL;
   1.113  }
   1.114  
   1.115  static void fbfront_out_event(struct fbfront_dev *dev, union xenfb_out_event *event)
   1.116 @@ -521,10 +551,7 @@ void shutdown_fbfront(struct fbfront_dev
   1.117  
   1.118      unbind_evtchn(dev->evtchn);
   1.119  
   1.120 -    free_page(dev->page);
   1.121 -    free(nodename);
   1.122 -    free(dev->backend);
   1.123 -    free(dev);
   1.124 +    free_fbfront(dev);
   1.125  }
   1.126  
   1.127  #ifdef HAVE_LIBC