diff mbox

[07/16] xen: Use DIV_ROUND_UP

Message ID 1464712565-14857-8-git-send-email-lvivier@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Vivier May 31, 2016, 4:35 p.m. UTC
Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).

This patch is the result of coccinelle script
scripts/coccinelle/round.cocci

CC: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 hw/display/xenfb.c | 4 ++--
 xen-hvm.c          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Stefano Stabellini June 1, 2016, 9:33 a.m. UTC | #1
On Tue, 31 May 2016, Laurent Vivier wrote:
> Replace (((n) + (d) - 1) /(d)) by DIV_ROUND_UP(n,d).
> 
> This patch is the result of coccinelle script
> scripts/coccinelle/round.cocci
> 
> CC: Stefano Stabellini <sstabellini@kernel.org>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


>  hw/display/xenfb.c | 4 ++--
>  xen-hvm.c          | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
> index 9866dfd..570b097 100644
> --- a/hw/display/xenfb.c
> +++ b/hw/display/xenfb.c
> @@ -472,9 +472,9 @@ static int xenfb_map_fb(struct XenFB *xenfb)
>          xenfb->pixels = NULL;
>      }
>  
> -    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
> +    xenfb->fbpages = DIV_ROUND_UP(xenfb->fb_len, XC_PAGE_SIZE);
>      n_fbdirs = xenfb->fbpages * mode / 8;
> -    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
> +    n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
>  
>      pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
>      fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
> diff --git a/xen-hvm.c b/xen-hvm.c
> index 01ee25d..a0da8d7 100644
> --- a/xen-hvm.c
> +++ b/xen-hvm.c
> @@ -567,7 +567,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state,
>  {
>      hwaddr npages = size >> TARGET_PAGE_BITS;
>      const int width = sizeof(unsigned long) * 8;
> -    unsigned long bitmap[(npages + width - 1) / width];
> +    unsigned long bitmap[DIV_ROUND_UP(npages, width)];
>      int rc, i, j;
>      const XenPhysmap *physmap = NULL;
>  
> -- 
> 2.5.5
>
diff mbox

Patch

diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c
index 9866dfd..570b097 100644
--- a/hw/display/xenfb.c
+++ b/hw/display/xenfb.c
@@ -472,9 +472,9 @@  static int xenfb_map_fb(struct XenFB *xenfb)
         xenfb->pixels = NULL;
     }
 
-    xenfb->fbpages = (xenfb->fb_len + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
+    xenfb->fbpages = DIV_ROUND_UP(xenfb->fb_len, XC_PAGE_SIZE);
     n_fbdirs = xenfb->fbpages * mode / 8;
-    n_fbdirs = (n_fbdirs + (XC_PAGE_SIZE - 1)) / XC_PAGE_SIZE;
+    n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
 
     pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
     fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
diff --git a/xen-hvm.c b/xen-hvm.c
index 01ee25d..a0da8d7 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -567,7 +567,7 @@  static void xen_sync_dirty_bitmap(XenIOState *state,
 {
     hwaddr npages = size >> TARGET_PAGE_BITS;
     const int width = sizeof(unsigned long) * 8;
-    unsigned long bitmap[(npages + width - 1) / width];
+    unsigned long bitmap[DIV_ROUND_UP(npages, width)];
     int rc, i, j;
     const XenPhysmap *physmap = NULL;