ia64/xen-unstable

changeset 15784:f4a0804d18f9

xencomm: Code style cleanups.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Aug 28 15:44:19 2007 +0100 (2007-08-28)
parents c93e2a822d6f
children 2aee2e4eacc8
files xen/common/xencomm.c
line diff
     1.1 --- a/xen/common/xencomm.c	Tue Aug 28 15:32:27 2007 +0100
     1.2 +++ b/xen/common/xencomm.c	Tue Aug 28 15:44:19 2007 +0100
     1.3 @@ -1,4 +1,6 @@
     1.4 -/*
     1.5 +/******************************************************************************
     1.6 + * xencomm.c
     1.7 + *
     1.8   * This program is free software; you can redistribute it and/or modify
     1.9   * it under the terms of the GNU General Public License as published by
    1.10   * the Free Software Foundation; either version 2 of the License, or
    1.11 @@ -34,13 +36,13 @@
    1.12  #define xc_dprintk(f, a...) ((void)0)
    1.13  #endif
    1.14  
    1.15 -static void*
    1.16 +static void *
    1.17  xencomm_vaddr(unsigned long paddr, struct page_info *page)
    1.18  {
    1.19      return (void*)((paddr & ~PAGE_MASK) | (unsigned long)page_to_virt(page));
    1.20  }
    1.21  
    1.22 -/* get_page() to prevent from another vcpu freeing the page */
    1.23 +/* get_page() to prevent another vcpu freeing the page. */
    1.24  static int
    1.25  xencomm_get_page(unsigned long paddr, struct page_info **page)
    1.26  {
    1.27 @@ -103,19 +105,19 @@ xencomm_ctxt_address(struct xencomm_ctxt
    1.28  }
    1.29  
    1.30  static int
    1.31 -xencomm_ctxt_init(const void* handle, struct xencomm_ctxt *ctxt)
    1.32 +xencomm_ctxt_init(const void *handle, struct xencomm_ctxt *ctxt)
    1.33  {
    1.34      struct page_info *page;
    1.35      struct xencomm_desc *desc;
    1.36      int ret;
    1.37  
    1.38 -    /* avoid unaligned access */
    1.39 -    if ( (unsigned long)handle % __alignof__(*desc) != 0 )
    1.40 +    /* Avoid unaligned access. */
    1.41 +    if ( ((unsigned long)handle % __alignof__(*desc)) != 0 )
    1.42          return -EINVAL;
    1.43      if ( xencomm_desc_cross_page_boundary((unsigned long)handle) )
    1.44          return -EINVAL;
    1.45  
    1.46 -    /* first we need to access the descriptor */
    1.47 +    /* First we need to access the descriptor. */
    1.48      ret = xencomm_get_page((unsigned long)handle, &page);
    1.49      if ( ret )
    1.50          return ret;
    1.51 @@ -128,10 +130,8 @@ xencomm_ctxt_init(const void* handle, st
    1.52          return -EINVAL;
    1.53      }
    1.54  
    1.55 -    ctxt->nr_addrs = desc->nr_addrs; /* copy before use.
    1.56 -                                      * It is possible for a guest domain to
    1.57 -                                      * modify concurrently.
    1.58 -                                      */
    1.59 +    /* Copy before use: It is possible for a guest to modify concurrently. */
    1.60 +    ctxt->nr_addrs = desc->nr_addrs;
    1.61      ctxt->desc_in_paddr = (struct xencomm_desc*)handle;
    1.62      ctxt->page = page;
    1.63      ctxt->address = &desc->address[0];
    1.64 @@ -141,28 +141,29 @@ xencomm_ctxt_init(const void* handle, st
    1.65  static int
    1.66  xencomm_ctxt_next(struct xencomm_ctxt *ctxt, int i)
    1.67  {
    1.68 +    unsigned long paddr;
    1.69 +    struct page_info *page;
    1.70 +    int ret;
    1.71 +
    1.72      BUG_ON(i >= ctxt->nr_addrs);
    1.73 -    /* in i == 0 case, we already calculated in xecomm_addr_init() */
    1.74 +
    1.75 +    /* In i == 0 case, we already calculated in xecomm_addr_init(). */
    1.76      if ( i != 0 )
    1.77          ctxt->address++;
    1.78 -    
    1.79 -    /* When crossing page boundary, machine address must be calculated. */
    1.80 -    if ( ((unsigned long)ctxt->address & ~PAGE_MASK) == 0 )
    1.81 -    {
    1.82 -        unsigned long paddr =
    1.83 -            (unsigned long)&(ctxt->desc_in_paddr->address[i]);
    1.84 -        struct page_info *page;
    1.85 -        int ret;
    1.86  
    1.87 -        ret = xencomm_get_page(paddr, &page);
    1.88 -        if ( ret == 0 )
    1.89 -        {
    1.90 -            put_page(ctxt->page);
    1.91 -            ctxt->page = page;
    1.92 -            ctxt->address = xencomm_vaddr(paddr, page);
    1.93 -        }
    1.94 +    if ( ((unsigned long)ctxt->address & ~PAGE_MASK) != 0 )
    1.95 +        return 0;
    1.96 +
    1.97 +    /* Crossing page boundary: machine address must be calculated. */
    1.98 +    paddr = (unsigned long)&ctxt->desc_in_paddr->address[i];
    1.99 +    ret = xencomm_get_page(paddr, &page);
   1.100 +    if ( ret )
   1.101          return ret;
   1.102 -    }
   1.103 +
   1.104 +    put_page(ctxt->page);
   1.105 +    ctxt->page = page;
   1.106 +    ctxt->address = xencomm_vaddr(paddr, page);
   1.107 +
   1.108      return 0;
   1.109  }
   1.110  
   1.111 @@ -177,25 +178,22 @@ xencomm_copy_chunk_from(
   1.112      unsigned long to, unsigned long paddr, unsigned int  len)
   1.113  {
   1.114      struct page_info *page;
   1.115 +    int res;
   1.116  
   1.117 -    while (1)
   1.118 -    {
   1.119 -        int res;
   1.120 +    do {
   1.121          res = xencomm_get_page(paddr, &page);
   1.122 -        if ( res != 0 )
   1.123 -        {
   1.124 -            if ( res == -EAGAIN )
   1.125 -                continue; /* Try again. */
   1.126 -            return res;
   1.127 -        }
   1.128 -        xc_dprintk("%lx[%d] -> %lx\n",
   1.129 -                   (unsigned long)xencomm_vaddr(paddr, page), len, to);
   1.130 +    } while ( res == -EAGAIN );
   1.131  
   1.132 -        memcpy((void *)to, xencomm_vaddr(paddr, page), len);
   1.133 -        put_page(page);
   1.134 -        return 0;
   1.135 -    }
   1.136 -    /* NOTREACHED */
   1.137 +    if ( res )
   1.138 +        return res;
   1.139 +
   1.140 +    xc_dprintk("%lx[%d] -> %lx\n",
   1.141 +               (unsigned long)xencomm_vaddr(paddr, page), len, to);
   1.142 +
   1.143 +    memcpy((void *)to, xencomm_vaddr(paddr, page), len);
   1.144 +    put_page(page);
   1.145 +
   1.146 +    return 0;
   1.147  }
   1.148  
   1.149  static unsigned long
   1.150 @@ -296,25 +294,22 @@ xencomm_copy_chunk_to(
   1.151      unsigned long paddr, unsigned long from, unsigned int  len)
   1.152  {
   1.153      struct page_info *page;
   1.154 +    int res;
   1.155  
   1.156 -    while (1)
   1.157 -    {
   1.158 -        int res;
   1.159 +    do {
   1.160          res = xencomm_get_page(paddr, &page);
   1.161 -        if ( res != 0 )
   1.162 -        {
   1.163 -            if ( res == -EAGAIN )
   1.164 -                continue; /* Try again.  */
   1.165 -            return res;
   1.166 -        }
   1.167 -        xc_dprintk("%lx[%d] -> %lx\n", from, len,
   1.168 -                   (unsigned long)xencomm_vaddr(paddr, page));
   1.169 +    } while ( res == -EAGAIN );
   1.170  
   1.171 -        memcpy(xencomm_vaddr(paddr, page), (void *)from, len);
   1.172 -        put_page(page);
   1.173 -        return 0;
   1.174 -    }
   1.175 -    /* NOTREACHED */
   1.176 +    if ( res )
   1.177 +        return res;
   1.178 +
   1.179 +    xc_dprintk("%lx[%d] -> %lx\n", from, len,
   1.180 +               (unsigned long)xencomm_vaddr(paddr, page));
   1.181 +
   1.182 +    memcpy(xencomm_vaddr(paddr, page), (void *)from, len);
   1.183 +    put_page(page);
   1.184 +
   1.185 +    return 0;
   1.186  }
   1.187  
   1.188  static unsigned long
   1.189 @@ -494,3 +489,13 @@ out:
   1.190      xencomm_ctxt_done(&ctxt);
   1.191      return res;
   1.192  }
   1.193 +
   1.194 +/*
   1.195 + * Local variables:
   1.196 + * mode: C
   1.197 + * c-set-style: "BSD"
   1.198 + * c-basic-offset: 4
   1.199 + * tab-width: 4
   1.200 + * indent-tabs-mode: nil
   1.201 + * End:
   1.202 + */