qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Eric Auger <eric.auger@redhat.com>,
	eric.auger.pro@gmail.com, qemu-devel@nongnu.org,
	qemu-arm@nongnu.org, peter.maydell@linaro.org, peterx@redhat.com
Subject: Re: [PATCH] hw/arm/smmu-common: a fix to smmu_find_smmu_pcibus
Date: Wed, 26 Feb 2020 18:42:35 +0100	[thread overview]
Message-ID: <039d7268-9884-8a29-890b-8e06dd2a0994@redhat.com> (raw)
In-Reply-To: <6f82ec7a-fb74-a47a-100b-325d5de36a7d@redhat.com>

On 2/26/20 6:37 PM, Philippe Mathieu-Daudé wrote:
> Hi Eric,
> 
> On 2/26/20 6:26 PM, Eric Auger wrote:
>> Make sure a null SMMUPciBus is returned in case we were
>> not able to identify a pci bus matching the @bus_num.
>>
>> This matches the fix done on intel iommu in commit:
>> a2e1cd41ccfe796529abfd1b6aeb1dd4393762a2
>>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>> ---
>>   hw/arm/smmu-common.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
>> index 0f2573f004..67d7b2d0fd 100644
>> --- a/hw/arm/smmu-common.c
>> +++ b/hw/arm/smmu-common.c
>> @@ -301,6 +301,7 @@ SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, 
>> uint8_t bus_num)
>>                   return smmu_pci_bus;
>>               }
>>           }
>> +        smmu_pci_bus = NULL;
>>       }
>>       return smmu_pci_bus;
>>   }
>>
> 
> Patch is easy to review but code not. By inverting the if() statement I 
> find the code easier to review. The patch isn't however:

I used 'git-diff -W' instead of 'git-diff -w'. -w works better:

-- >8 --
@@ -290,10 +290,12 @@ inline int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t 
iova, IOMMUAccessFlags perm,
  SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num)
  {
      SMMUPciBus *smmu_pci_bus = s->smmu_pcibus_by_bus_num[bus_num];
-
-    if (!smmu_pci_bus) {
      GHashTableIter iter;

+    if (smmu_pci_bus) {
+        return smmu_pci_bus;
+    }
+
      g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr);
      while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)) {
          if (pci_bus_num(smmu_pci_bus->bus) == bus_num) {
@@ -301,8 +303,8 @@ SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, 
uint8_t bus_num)
              return smmu_pci_bus;
          }
      }
-    }
-    return smmu_pci_bus;
+
+    return NULL;
  }

---

> 
> The code is easier although:
> 
> SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num)
> {
>      SMMUPciBus *smmu_pci_bus = s->smmu_pcibus_by_bus_num[bus_num];
>      GHashTableIter iter;
> 
>      if (smmu_pci_bus) {
>          return smmu_pci_bus;
>      }
> 
>      g_hash_table_iter_init(&iter, s->smmu_pcibus_by_busptr);
>      while (g_hash_table_iter_next(&iter, NULL, (void **)&smmu_pci_bus)) {
>          if (pci_bus_num(smmu_pci_bus->bus) == bus_num) {
>              s->smmu_pcibus_by_bus_num[bus_num] = smmu_pci_bus;
>              return smmu_pci_bus;
>          }
>      }
> 
>      return NULL;
> }
> 
> What do you think?



  reply	other threads:[~2020-02-26 17:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 17:26 [PATCH] hw/arm/smmu-common: a fix to smmu_find_smmu_pcibus Eric Auger
2020-02-26 17:37 ` Philippe Mathieu-Daudé
2020-02-26 17:42   ` Philippe Mathieu-Daudé [this message]
2020-03-02 11:02   ` Peter Maydell
2020-03-02 11:34     ` Peter Maydell
2020-02-26 17:57 ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=039d7268-9884-8a29-890b-8e06dd2a0994@redhat.com \
    --to=philmd@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=eric.auger@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).