Message ID | 1408378243-19713-5-git-send-email-armbru@redhat.com |
---|---|
State | New |
Headers | show |
On 18.08.2014 18:10, Markus Armbruster wrote: > They clutter the code. Unfortunately, I can't figure out how to make > Coccinelle drop all of them, so I have to settle for common special > cases: > > @@ > type T; > T *pt; > void *pv; > @@ > - pt = (T *)pv; > + pt = pv; > @@ > type T; > @@ > - (T *) > (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| > g_try_malloc\|g_try_malloc0\|g_try_realloc\| > g_try_new\|g_try_new0\|g_try_renew\)(...)) > > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > block/vhdx-log.c | 2 +- > block/vvfat.c | 8 ++++---- > hw/ide/microdrive.c | 2 +- > 3 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/block/vhdx-log.c b/block/vhdx-log.c > index eb5c7a0..4267e60 100644 > --- a/block/vhdx-log.c > +++ b/block/vhdx-log.c > @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, > buffer = qemu_blockalign(bs, total_length); > memcpy(buffer, &new_hdr, sizeof(new_hdr)); > > - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); > + new_desc = (buffer + sizeof(new_hdr)); > data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); > data_tmp = data; You could drop the parantheses here. Also, I still don't like void pointer arithmetic, but well... ;-) Reviewed-by: Max Reitz <mreitz@redhat.com>
On Mon, Aug 18, 2014 at 06:10:43PM +0200, Markus Armbruster wrote: > They clutter the code. Unfortunately, I can't figure out how to make > Coccinelle drop all of them, so I have to settle for common special > cases: > > @@ > type T; > T *pt; > void *pv; > @@ > - pt = (T *)pv; > + pt = pv; > @@ > type T; > @@ > - (T *) > (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| > g_try_malloc\|g_try_malloc0\|g_try_realloc\| > g_try_new\|g_try_new0\|g_try_renew\)(...)) > > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > block/vhdx-log.c | 2 +- > block/vvfat.c | 8 ++++---- > hw/ide/microdrive.c | 2 +- > 3 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/block/vhdx-log.c b/block/vhdx-log.c > index eb5c7a0..4267e60 100644 > --- a/block/vhdx-log.c > +++ b/block/vhdx-log.c > @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, > buffer = qemu_blockalign(bs, total_length); > memcpy(buffer, &new_hdr, sizeof(new_hdr)); > > - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); > + new_desc = (buffer + sizeof(new_hdr)); Agree with Max, in that the parenthesis could be removed. Not worthy of a respin normally, but since the point of this patch is to unclutter the code, I guess it makes sense to fix it. > data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); > data_tmp = data; > > diff --git a/block/vvfat.c b/block/vvfat.c > index f877e85..401539d 100644 > --- a/block/vvfat.c > +++ b/block/vvfat.c > @@ -732,7 +732,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) > if(first_cluster == 0 && (is_dotdot || is_dot)) > continue; > > - buffer=(char*)g_malloc(length); > + buffer=g_malloc(length); You missed a spot to put spaces around the '=' here. Nothing worthy of a respin, of course - just a note in case you decide to respin. [...] With or without the changes above: Reviewed-by: Jeff Cody <jcody@redhat.com>
Jeff Cody <jcody@redhat.com> writes: > On Mon, Aug 18, 2014 at 06:10:43PM +0200, Markus Armbruster wrote: >> They clutter the code. Unfortunately, I can't figure out how to make >> Coccinelle drop all of them, so I have to settle for common special >> cases: >> >> @@ >> type T; >> T *pt; >> void *pv; >> @@ >> - pt = (T *)pv; >> + pt = pv; >> @@ >> type T; >> @@ >> - (T *) >> (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| >> g_try_malloc\|g_try_malloc0\|g_try_realloc\| >> g_try_new\|g_try_new0\|g_try_renew\)(...)) >> >> Signed-off-by: Markus Armbruster <armbru@redhat.com> >> --- >> block/vhdx-log.c | 2 +- >> block/vvfat.c | 8 ++++---- >> hw/ide/microdrive.c | 2 +- >> 3 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/block/vhdx-log.c b/block/vhdx-log.c >> index eb5c7a0..4267e60 100644 >> --- a/block/vhdx-log.c >> +++ b/block/vhdx-log.c >> @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, >> buffer = qemu_blockalign(bs, total_length); >> memcpy(buffer, &new_hdr, sizeof(new_hdr)); >> >> - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); >> + new_desc = (buffer + sizeof(new_hdr)); > > Agree with Max, in that the parenthesis could be removed. Not worthy > of a respin normally, but since the point of this patch is to > unclutter the code, I guess it makes sense to fix it. Max and you are right. I neglected to clean up the patch produced by spatch. >> data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); >> data_tmp = data; >> >> diff --git a/block/vvfat.c b/block/vvfat.c >> index f877e85..401539d 100644 >> --- a/block/vvfat.c >> +++ b/block/vvfat.c >> @@ -732,7 +732,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) >> if(first_cluster == 0 && (is_dotdot || is_dot)) >> continue; >> >> - buffer=(char*)g_malloc(length); >> + buffer=g_malloc(length); > > You missed a spot to put spaces around the '=' here. Nothing worthy > of a respin, of course - just a note in case you decide to respin. Right again. Although perhaps vvfat should remain ugly, to warn unwary travellers ;) > [...] > > With or without the changes above: > > Reviewed-by: Jeff Cody <jcody@redhat.com> Thanks!
Max Reitz <mreitz@redhat.com> writes: > On 18.08.2014 18:10, Markus Armbruster wrote: >> They clutter the code. Unfortunately, I can't figure out how to make >> Coccinelle drop all of them, so I have to settle for common special >> cases: >> >> @@ >> type T; >> T *pt; >> void *pv; >> @@ >> - pt = (T *)pv; >> + pt = pv; >> @@ >> type T; >> @@ >> - (T *) >> (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| >> g_try_malloc\|g_try_malloc0\|g_try_realloc\| >> g_try_new\|g_try_new0\|g_try_renew\)(...)) >> >> Signed-off-by: Markus Armbruster <armbru@redhat.com> >> --- >> block/vhdx-log.c | 2 +- >> block/vvfat.c | 8 ++++---- >> hw/ide/microdrive.c | 2 +- >> 3 files changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/block/vhdx-log.c b/block/vhdx-log.c >> index eb5c7a0..4267e60 100644 >> --- a/block/vhdx-log.c >> +++ b/block/vhdx-log.c >> @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, >> buffer = qemu_blockalign(bs, total_length); >> memcpy(buffer, &new_hdr, sizeof(new_hdr)); >> - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); >> + new_desc = (buffer + sizeof(new_hdr)); >> data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); >> data_tmp = data; > > You could drop the parantheses here. Also, I still don't like void > pointer arithmetic, but well... ;-) Separate issue, related because it would put the cast right back. We use plenty of GCCisms. If we ever want to port to a toolchain that doesn't support them, adding the cast clutter to avoid arithmetic on void * will be the least of our worries. If we decide to hunt down this particular GCCism anyway, there's -Wpointer-arith. Without that, it's a game of whack-a-mole. > Reviewed-by: Max Reitz <mreitz@redhat.com> Thanks!
Markus Armbruster <armbru@redhat.com> writes: > Jeff Cody <jcody@redhat.com> writes: > >> On Mon, Aug 18, 2014 at 06:10:43PM +0200, Markus Armbruster wrote: >>> They clutter the code. Unfortunately, I can't figure out how to make >>> Coccinelle drop all of them, so I have to settle for common special >>> cases: >>> >>> @@ >>> type T; >>> T *pt; >>> void *pv; >>> @@ >>> - pt = (T *)pv; >>> + pt = pv; >>> @@ >>> type T; >>> @@ >>> - (T *) >>> (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| >>> g_try_malloc\|g_try_malloc0\|g_try_realloc\| >>> g_try_new\|g_try_new0\|g_try_renew\)(...)) >>> >>> Signed-off-by: Markus Armbruster <armbru@redhat.com> >>> --- >>> block/vhdx-log.c | 2 +- >>> block/vvfat.c | 8 ++++---- >>> hw/ide/microdrive.c | 2 +- >>> 3 files changed, 6 insertions(+), 6 deletions(-) >>> >>> diff --git a/block/vhdx-log.c b/block/vhdx-log.c >>> index eb5c7a0..4267e60 100644 >>> --- a/block/vhdx-log.c >>> +++ b/block/vhdx-log.c >>> @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, >>> buffer = qemu_blockalign(bs, total_length); >>> memcpy(buffer, &new_hdr, sizeof(new_hdr)); >>> >>> - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); >>> + new_desc = (buffer + sizeof(new_hdr)); >> >> Agree with Max, in that the parenthesis could be removed. Not worthy >> of a respin normally, but since the point of this patch is to >> unclutter the code, I guess it makes sense to fix it. > > Max and you are right. I neglected to clean up the patch produced by > spatch. Cleaned up in v3. >>> data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); >>> data_tmp = data; >>> >>> diff --git a/block/vvfat.c b/block/vvfat.c >>> index f877e85..401539d 100644 >>> --- a/block/vvfat.c >>> +++ b/block/vvfat.c >>> @@ -732,7 +732,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) >>> if(first_cluster == 0 && (is_dotdot || is_dot)) >>> continue; >>> >>> - buffer=(char*)g_malloc(length); >>> + buffer=g_malloc(length); >> >> You missed a spot to put spaces around the '=' here. Nothing worthy >> of a respin, of course - just a note in case you decide to respin. > > Right again. Although perhaps vvfat should remain ugly, to warn unwary > travellers ;) Cleaned up in v3. [...]
diff --git a/block/vhdx-log.c b/block/vhdx-log.c index eb5c7a0..4267e60 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -923,7 +923,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, buffer = qemu_blockalign(bs, total_length); memcpy(buffer, &new_hdr, sizeof(new_hdr)); - new_desc = (VHDXLogDescriptor *) (buffer + sizeof(new_hdr)); + new_desc = (buffer + sizeof(new_hdr)); data_sector = buffer + (desc_sectors * VHDX_LOG_SECTOR_SIZE); data_tmp = data; diff --git a/block/vvfat.c b/block/vvfat.c index f877e85..401539d 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -732,7 +732,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) if(first_cluster == 0 && (is_dotdot || is_dot)) continue; - buffer=(char*)g_malloc(length); + buffer=g_malloc(length); snprintf(buffer,length,"%s/%s",dirname,entry->d_name); if(stat(buffer,&st)<0) { @@ -767,7 +767,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) /* create mapping for this file */ if(!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size)) { - s->current_mapping=(mapping_t*)array_get_next(&(s->mapping)); + s->current_mapping = array_get_next(&(s->mapping)); s->current_mapping->begin=0; s->current_mapping->end=st.st_size; /* @@ -811,12 +811,12 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) } /* reget the mapping, since s->mapping was possibly realloc()ed */ - mapping = (mapping_t*)array_get(&(s->mapping), mapping_index); + mapping = array_get(&(s->mapping), mapping_index); first_cluster += (s->directory.next - mapping->info.dir.first_dir_index) * 0x20 / s->cluster_size; mapping->end = first_cluster; - direntry = (direntry_t*)array_get(&(s->directory), mapping->dir_index); + direntry = array_get(&(s->directory), mapping->dir_index); set_begin_of_direntry(direntry, mapping->begin); return 0; diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c index 2d70ddb..15671b8 100644 --- a/hw/ide/microdrive.c +++ b/hw/ide/microdrive.c @@ -567,7 +567,7 @@ PCMCIACardState *dscm1xxxx_init(DriveInfo *dinfo) } md->bus.ifs[0].drive_kind = IDE_CFATA; md->bus.ifs[0].mdata_size = METADATA_SIZE; - md->bus.ifs[0].mdata_storage = (uint8_t *) g_malloc0(METADATA_SIZE); + md->bus.ifs[0].mdata_storage = g_malloc0(METADATA_SIZE); return PCMCIA_CARD(md); }
They clutter the code. Unfortunately, I can't figure out how to make Coccinelle drop all of them, so I have to settle for common special cases: @@ type T; T *pt; void *pv; @@ - pt = (T *)pv; + pt = pv; @@ type T; @@ - (T *) (\(g_malloc\|g_malloc0\|g_realloc\|g_new\|g_new0\|g_renew\| g_try_malloc\|g_try_malloc0\|g_try_realloc\| g_try_new\|g_try_new0\|g_try_renew\)(...)) Signed-off-by: Markus Armbruster <armbru@redhat.com> --- block/vhdx-log.c | 2 +- block/vvfat.c | 8 ++++---- hw/ide/microdrive.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)