[Qemu-devel] [PATCH v2 10/29] vvfat: use DIV_ROUND_UP

Marc-André Lureau posted 29 patches 8 years, 7 months ago
[Qemu-devel] [PATCH v2 10/29] vvfat: use DIV_ROUND_UP
Posted by Marc-André Lureau 8 years, 7 months ago
I used the clang-tidy qemu-round check to generate the fix:
https://github.com/elmarco/clang-tools-extra

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 block/vvfat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index 4fd28e1e87..c08c4fb525 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -437,7 +437,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename)
         return NULL;
     }
 
-    number_of_entries = (length * 2 + 25) / 26;
+    number_of_entries = DIV_ROUND_UP(length * 2, 26);
 
     for(i=0;i<number_of_entries;i++) {
         entry=array_get_next(&(s->directory));
@@ -2520,7 +2520,7 @@ static int commit_one_file(BDRVVVFATState* s,
                 (size > offset && c >=2 && !fat_eof(s, c)));
 
         ret = vvfat_read(s->bs, cluster2sector(s, c),
-            (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);
+            (uint8_t*)cluster, DIV_ROUND_UP(rest_size, 0x200));
 
         if (ret < 0) {
             qemu_close(fd);
-- 
2.13.1.395.gf7b71de06


Re: [Qemu-devel] [PATCH v2 10/29] vvfat: use DIV_ROUND_UP
Posted by Eric Blake 8 years, 7 months ago
On 07/13/2017 11:32 AM, Marc-André Lureau wrote:
> I used the clang-tidy qemu-round check to generate the fix:
> https://github.com/elmarco/clang-tools-extra
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  block/vvfat.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/block/vvfat.c b/block/vvfat.c
> index 4fd28e1e87..c08c4fb525 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -437,7 +437,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename)
>          return NULL;
>      }
>  
> -    number_of_entries = (length * 2 + 25) / 26;
> +    number_of_entries = DIV_ROUND_UP(length * 2, 26);

Wow - a non-power-of-2!  Good thing our macro works for that.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH v2 10/29] vvfat: use DIV_ROUND_UP
Posted by Richard Henderson 8 years, 7 months ago
On 07/13/2017 06:32 AM, Marc-André Lureau wrote:
> I used the clang-tidy qemu-round check to generate the fix:
> https://github.com/elmarco/clang-tools-extra
> 
> Signed-off-by: Marc-André Lureau<marcandre.lureau@redhat.com>
> ---
>   block/vvfat.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~