iothread: Simplify expression in qemu_in_iothread()
PATCH 1/1 iothread: Simplify expression in qemu_in_iothread()
'a == b ? false : true' is a rather convoluted way of writing 'a != b'. Use the more obvious way to write it.
--- iothread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
iothread.c +1 -2
@@ -404,6 +404,5 @@ IOThread *iothread_by_id(const char *id)bool qemu_in_iothread (void ) { -return qemu_get_current_aio_context () ==qemu_get_aio_context () ? - false : true; +return qemu_get_current_aio_context () !=qemu_get_aio_context (); }
Signature · 1 line
2.43.0
Le 08/02/2024 à 11:16, Kevin Wolf a écrit :
Quoted 13 lines
'a == b ? false : true' is a rather convoluted way of writing 'a != b'. Use the more obvious way to write it.
Signed-off-by Kevin Wolf <[email protected]>--- iothread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)iothread.c +0
-0
iothread.c IOThread *iothread_by_id(const char *id) · line 408
Quoted 7 lines
iothread.c +1
-2@@ -404,6 +404,5 @@ IOThread *iothread_by_id(const char *id)bool qemu_in_iothread (void ) { -return qemu_get_current_aio_context () ==qemu_get_aio_context () ? - false : true; +return qemu_get_current_aio_context () !=qemu_get_aio_context (); }
Quoted 13 lines · Kevin Wolf
'a == b ? false : true' is a rather convoluted way of writing 'a != b'. Use the more obvious way to write it.
Signed-off-by Kevin Wolf <[email protected]>--- iothread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)iothread.c +0
-0
iothread.c IOThread *iothread_by_id(const char *id) · line 408
Quoted 7 lines
iothread.c +1
-2@@ -404,6 +404,5 @@ IOThread *iothread_by_id(const char *id)bool qemu_in_iothread (void ) { -return qemu_get_current_aio_context () ==qemu_get_aio_context () ? - false : true; +return qemu_get_current_aio_context () !=qemu_get_aio_context (); }
BTW using the same pattern:
-- >8 --
hw/nvram/xlnx-zynqmp-efuse.c +1 -1
@@ -582,7 +582,7 @@ static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg,static uint64_t zynqmp_efuse_wr_lock_prew (RegisterInfo *reg,uint64_t val) { -return val ==0xDF0D ?0 :1 ; +return val !=0xDF0D ; }
tests/tcg/aarch64/sysregs.c +1 -1
@@ -183,5 +183,5 @@ int main(void)return 1 ; } -return should_fail_count ==6 ?0 :1 ; +return should_fail_count !=6 ; }
---
Am 08.02.2024 um 11:48 hat Philippe Mathieu-Daudé geschrieben:
Quoted 31 lines · Kevin Wolf
Quoted 13 lines
'a == b ? false : true' is a rather convoluted way of writing 'a != b'. Use the more obvious way to write it.
Signed-off-by Kevin Wolf <[email protected]>--- iothread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)iothread.c +0
-0iothread.c IOThread *iothread_by_id(const char *id) · line 407
Quoted 6 lines
iothread.c +1
-2@@ -404,6 +404,5 @@ IOThread *iothread_by_id(const char *id)bool qemu_in_iothread (void ) { -return qemu_get_current_aio_context () ==qemu_get_aio_context () ? - false : true; +return qemu_get_current_aio_context () !=qemu_get_aio_context (); }Reviewed-by Philippe Mathieu-Daudé <[email protected]>BTW using the same pattern:
-- >8 --
hw/nvram/xlnx-zynqmp-efuse.c +0
-0
hw/nvram/xlnx-zynqmp-efuse.c static uint64_t · line 587
Quoted 7 lines
hw/nvram/xlnx-zynqmp-efuse.c +1
-1@@ -582,7 +582,7 @@ static uint64_tzynqmp_efuse_cache_load_prew (RegisterInfo *reg, static uint64_t zynqmp_efuse_wr_lock_prew(RegisterInfo *reg, uint64_t val) { -return val ==0xDF0D ?0 :1 ; +return val !=0xDF0D ; }
Maybe. I would have to know that device to tell if this is really meant as boolean. Or maybe it should be written 0x0 and 0x1 to signify that it's a register value or something.
tests/tcg/aarch64/sysregs.c int main(void) · line 187
Quoted 11 lines
tests/tcg/aarch64/sysregs.c +1
-1@@ -183,5 +183,5 @@ int main(void)return 1 ; } -return should_fail_count ==6 ?0 :1 ; +return should_fail_count !=6 ; }
This one isn't unclear to me, though. This is EXIT_SUCCESS and EXIT_FAILURE, just open-coded. I think making your change would make it only more confusing.
Kevin
Quoted 12 lines · Kevin Wolf
Am 08.02.2024 um 11:48 hat Philippe Mathieu-Daudé geschrieben:
Quoted 10 lines
BTW using the same pattern:
-- >8 --
hw/nvram/xlnx-zynqmp-efuse.c +0
-0@@ -582,7 +582,7 @@ static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg,
Quoted 9 lines
hw/nvram/xlnx-zynqmp-efuse.c static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg, · line 586
Quoted 5 lines
hw/nvram/xlnx-zynqmp-efuse.c +1
-1static uint64_t zynqmp_efuse_wr_lock_prew (RegisterInfo *reg,uint64_t val) { -return val ==0xDF0D ?0 :1 ; +return val !=0xDF0D ; }Maybe. I would have to know that device to tell if this is really meant as boolean. Or maybe it should be written
0x0and0x1to signify that it's a register value or something.
This is a RegisterAccessinfo pre_write hook. The docs say:
* @pre_write: Pre write callback. Passed the value that's to be written,
* immediately before the actual write. The returned value is what is written,
* giving the handler a chance to modify the written value.
So it is indeed returning a register value, not a boolean flag masquerading as a uint64_t.
Quoted 8 lines
Quoted 8 lines
tests/tcg/aarch64/sysregs.c +0
-0@@ -183,5 +183,5 @@ int main(void)return 1 ; }
Quoted 7 lines
tests/tcg/aarch64/sysregs.c int main(void) · line 187
Quoted 3 lines
tests/tcg/aarch64/sysregs.c +1
-1-return should_fail_count ==6 ?0 :1 ; +return should_fail_count !=6 ; }This one isn't unclear to me, though. This is
EXIT_SUCCESSandEXIT_FAILURE, just open-coded. I think making your change would make it only more confusing.
I agree on this one.
-- PMM
Quoted 47 lines · Peter Maydell
Quoted 12 lines · Kevin Wolf
Am 08.02.2024 um 11:48 hat Philippe Mathieu-Daudé geschrieben:
Quoted 10 lines
BTW using the same pattern:
-- >8 --
hw/nvram/xlnx-zynqmp-efuse.c +0
-0@@ -582,7 +582,7 @@ static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg,Quoted 9 lines
hw/nvram/xlnx-zynqmp-efuse.c static uint64_t zynqmp_efuse_cache_load_prew(RegisterInfo *reg, · line 586
Quoted 5 lines
hw/nvram/xlnx-zynqmp-efuse.c +1
-1static uint64_t zynqmp_efuse_wr_lock_prew (RegisterInfo *reg,uint64_t val) { -return val ==0xDF0D ?0 :1 ; +return val !=0xDF0D ; }Maybe. I would have to know that device to tell if this is really meant as boolean. Or maybe it should be written
0x0and0x1to signify that it's a register value or something.This is a RegisterAccessinfo
pre_writehook. The docs say:
* @pre_write: Pre write callback. Passed the value that's to be written,
* immediately before the actual write. The returned value is what is written,
* giving the handler a chance to modify the written value.So it is indeed returning a register value, not a boolean flag masquerading as a
uint64_t.Quoted 8 lines
Quoted 8 lines
tests/tcg/aarch64/sysregs.c +0
-0@@ -183,5 +183,5 @@ int main(void)return 1 ; }Quoted 7 lines
tests/tcg/aarch64/sysregs.c int main(void) · line 187
Quoted 3 lines
tests/tcg/aarch64/sysregs.c +1
-1-return should_fail_count ==6 ?0 :1 ; +return should_fail_count !=6 ; }This one isn't unclear to me, though. This is
EXIT_SUCCESSandEXIT_FAILURE, just open-coded. I think making your change would make it only more confusing.
Quoted 1 line
I agree on this one.
Thanks for both analysis and sorry for my confusion, I was just looking at the pattern without interpreting each proper use case.