[RFC PATCH-for-5.2] exec: Remove dead code (CID 1432876)

Philippe Mathieu-Daudé posted 1 patch 3 years, 6 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201030153752.1557776-1-philmd@redhat.com
softmmu/physmem.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
[RFC PATCH-for-5.2] exec: Remove dead code (CID 1432876)
Posted by Philippe Mathieu-Daudé 3 years, 6 months ago
We removed the global_locking field in commit 4174495408a,
leaving dead code around the 'unlocked' variable. Remove it
to fix the DEADCODE issue reported by Coverity (CID 1432876).

Fixes: 4174495408a ("exec: Remove MemoryRegion::global_locking field")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 softmmu/physmem.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index a9adedb9f82..0b31be29282 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -2723,22 +2723,14 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
 
 static bool prepare_mmio_access(MemoryRegion *mr)
 {
-    bool unlocked = !qemu_mutex_iothread_locked();
     bool release_lock = false;
 
-    if (unlocked) {
+    if (!qemu_mutex_iothread_locked()) {
         qemu_mutex_lock_iothread();
-        unlocked = false;
         release_lock = true;
     }
     if (mr->flush_coalesced_mmio) {
-        if (unlocked) {
-            qemu_mutex_lock_iothread();
-        }
         qemu_flush_coalesced_mmio_buffer();
-        if (unlocked) {
-            qemu_mutex_unlock_iothread();
-        }
     }
 
     return release_lock;
-- 
2.26.2

Re: [RFC PATCH-for-5.2] exec: Remove dead code (CID 1432876)
Posted by Paolo Bonzini 3 years, 6 months ago
On 30/10/20 16:37, Philippe Mathieu-Daudé wrote:
> We removed the global_locking field in commit 4174495408a,
> leaving dead code around the 'unlocked' variable. Remove it
> to fix the DEADCODE issue reported by Coverity (CID 1432876).
> 
> Fixes: 4174495408a ("exec: Remove MemoryRegion::global_locking field")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  softmmu/physmem.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index a9adedb9f82..0b31be29282 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -2723,22 +2723,14 @@ static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr)
>  
>  static bool prepare_mmio_access(MemoryRegion *mr)
>  {
> -    bool unlocked = !qemu_mutex_iothread_locked();
>      bool release_lock = false;
>  
> -    if (unlocked) {
> +    if (!qemu_mutex_iothread_locked()) {
>          qemu_mutex_lock_iothread();
> -        unlocked = false;
>          release_lock = true;
>      }
>      if (mr->flush_coalesced_mmio) {
> -        if (unlocked) {
> -            qemu_mutex_lock_iothread();
> -        }
>          qemu_flush_coalesced_mmio_buffer();
> -        if (unlocked) {
> -            qemu_mutex_unlock_iothread();
> -        }
>      }
>  
>      return release_lock;
> 

Queued, thanks.

Paolo