Skip to contentSkip to conversation

block: Clean up some bad code in the vvfat driver

PATCH Applied Thomas Huth 5 participants 10 messages Sep 13, 2017 – Sep 19, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Clean up some bad code in the vvfat driver

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

---
 block/vvfat.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
block/vvfat.c +2 -24
index c54fa94..777a8cd 100644
@@ -56,15 +56,6 @@
 
 static void checkpoint(void);
 
-#ifdef __MINGW32__
-void nonono(const char* file, int line, const char* msg) {
-    fprintf(stderr, "Nonono! %s:%d %s\n", file, line, msg);
-    exit(-5);
-}
-#undef assert
-#define assert(a) do {if (!(a)) nonono(__FILE__, __LINE__, #a);}while(0)
-#endif
-
 #else
 
 #define DLOG(a)
@@ -3269,24 +3260,11 @@ static void bdrv_vvfat_init(void)
 block_init(bdrv_vvfat_init);
 
 #ifdef DEBUG
-static void checkpoint(void) {
+static void checkpoint(void)
+{
     assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2);
     check1(vvv);
     check2(vvv);
     assert(!vvv->current_mapping || vvv->current_fd || (vvv->current_mapping->mode & MODE_DIRECTORY));
-#if 0
-    if (((direntry_t*)vvv->directory.pointer)[1].attributes != 0xf)
-        fprintf(stderr, "Nonono!\n");
-    mapping_t* mapping;
-    direntry_t* direntry;
-    assert(vvv->mapping.size >= vvv->mapping.item_size * vvv->mapping.next);
-    assert(vvv->directory.size >= vvv->directory.item_size * vvv->directory.next);
-    if (vvv->mapping.next<47)
-        return;
-    assert((mapping = array_get(&(vvv->mapping), 47)));
-    assert(mapping->dir_index < vvv->directory.next);
-    direntry = array_get(&(vvv->directory), mapping->dir_index);
-    assert(!memcmp(direntry->name, "USB     H  ", 11) || direntry->name[0]==0);
-#endif
 }
 #endif
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Thomas Huth

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Quoted 5 lines
---
 block/vvfat.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 8 lines · Thomas Huth

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

oh no

#3 lore raw
Quoted 12 lines · John Snow
Quoted 8 lines · Thomas Huth

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76

whoa :)

#4 lore raw

[Qemu-devel] Dead code in cpu-models.h (was: block: Clean up some bad code in the vvfat driver)

Quoted 1 line · Paolo Bonzini

On 13/09/2017 21:08, John Snow wrote:

[...]

Quoted 9 lines
Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

Quoted 6 lines
$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76

whoa :)

Igor recently already removed the dead definitions from cpu-models.c :

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=aef779605779579afbafff

I guess we could now remove the corresponding dead definitions from the header, too...

Any volunteers?

Thomas

#5 lore raw

Re: [Qemu-devel] Dead code in cpu-models.h

Quoted 21 lines · Thomas Huth
Quoted 1 line · Paolo Bonzini

On 13/09/2017 21:08, John Snow wrote:

[...]

Quoted 9 lines
Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

Quoted 6 lines
$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76

whoa :)

Igor recently already removed the dead definitions from cpu-models.c :

Quoted 9 lines

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=aef779605779579afbafff

I guess we could now remove the corresponding dead definitions from the header, too...

Any volunteers?

Thomas

Well, I can just take a chainsaw to it blindly if you want to critique it.

#6 lore raw

Re: [Qemu-devel] Dead code in cpu-models.h

Quoted 26 lines · John Snow
Quoted 23 lines · Thomas Huth
Quoted 1 line · Paolo Bonzini

On 13/09/2017 21:08, John Snow wrote:

[...]

Quoted 9 lines
Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

Quoted 6 lines
$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76

whoa :)

Igor recently already removed the dead definitions from cpu-models.c :

https://git.qemu.org/?p=qemu.git;a=commitdiff;h=aef779605779579afbafff

Quoted 9 lines
Quoted 6 lines

I guess we could now remove the corresponding dead definitions from the header, too...

Any volunteers?

Thomas

Well, I can just take a chainsaw to it blindly if you want to critique it.

I think it should at least be aligned with the changes that have been done to cpu-models.c (e.g. the definition for CPU_POWERPC_401B3 has been removed from the .c file, so the CPU_POWERPC_401B3 could be removed from the .h file, too.

Thomas

#7 lore raw
In reply to Paolo Bonzini
Quoted 23 lines · Paolo Bonzini
Quoted 12 lines · John Snow
Quoted 8 lines · Thomas Huth

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

Quoted 7 lines
$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76

whoa :)

Wonder if '#if 0' should be against the style guide / in checkpatch. Conditional compilations should at least be contingent on some named variable/condition.

(Probably super ideally all conditional compilations correlate directly to a configure variable...)

--js

#8 lore raw
Quoted 31 lines · John Snow
Quoted 28 lines · Paolo Bonzini
Quoted 12 lines · John Snow
Quoted 8 lines · Thomas Huth

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Quoted 8 lines

Farewell, bitrot code.

Out of curiosity, I wonder ...

jhuston@probe (foobar) ~/s/qemu> git grep '#if 0' | wc -l 320

$ git grep -c '#if 0' | sort -k2 --field-separator=: -n
...
hw/net/eepro100.c:21
target/ppc/cpu-models.h:76
Quoted 4 lines
Quoted 2 lines

whoa :)

Wonder if '#if 0' should be against the style guide / in checkpatch.

checkpatch already complains if you have a "#if 0" in your patch, so I think we should be pretty fine here already - but of course you can still add a paragraph to the CODING_STYLE if you like.

Thomas

Applied
#9 lore raw
In reply to Thomas Huth

Am 13.09.2017 um 12:21 hat Thomas Huth geschrieben:

Quoted 8 lines

Remove the unnecessary home-grown redefinition of the assert() macro here, and remove the unusable debug code at the end of the checkpoint() function. The code there uses assert() with side-effects (assignment to the "mapping" variable), which should be avoided. Looking more closely, it seems as it is apparently also only usable for one certain directory layout (with a file named USB.H in it) and thus is of no use for the rest of the world.

Thanks, applied to the block branch.

Kevin