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

Marc-André Lureau posted 31 patches 8 years, 4 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 10/31] vvfat: use DIV_ROUND_UP
Posted by Marc-André Lureau 8 years, 4 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 426ca70e35..877f71dcdc 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -433,7 +433,7 @@ static inline direntry_t* create_long_filename(BDRVVVFATState* s,const char* fil
 {
     char buffer[258];
     int length=short2long_name(buffer,filename),
-        number_of_entries=(length+25)/26,i;
+        number_of_entries=DIV_ROUND_UP(length, 26),i;
     direntry_t* entry;
 
     for(i=0;i<number_of_entries;i++) {
@@ -2424,7 +2424,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] [Qemu-block] [PATCH 10/31] vvfat: use DIV_ROUND_UP
Posted by Eric Blake 8 years, 4 months ago
On 06/22/2017 07:41 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(-)
> 
> diff --git a/block/vvfat.c b/block/vvfat.c
> index 426ca70e35..877f71dcdc 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -433,7 +433,7 @@ static inline direntry_t* create_long_filename(BDRVVVFATState* s,const char* fil
>  {
>      char buffer[258];
>      int length=short2long_name(buffer,filename),
> -        number_of_entries=(length+25)/26,i;
> +        number_of_entries=DIV_ROUND_UP(length, 26),i;

This formatting made me do a double take (at first, I thought it was a
comma expression, before realizing it was a declaration).  While you are
touching it, can you please rewrite it into something more legible, such as:

int length = short2long_name(buffer, filename);
int number_of_entries = DIV_ROUND_UP(length, 26);
int i;

I don't mind declaring multiple variables in one declaration - provided
that we aren't also initializing them.  But mixing in the un-initialized
declaration of 'i' with other initialized variables is just awkward.

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