Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1595672
| From | Magnus Damm <magnus.damm@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v3 02/09] iommu/ipmmu-vmsa: Add optional root device feature |
| Date | 2017-03-09 05:40 +0100 |
| Message-ID | <tiY1P-8jM-1@gated-at.bofh.it> (permalink) |
| References | <tiHDH-5Js-3@gated-at.bofh.it> <tiHDH-5Js-1@gated-at.bofh.it> <tiKie-7jK-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Hi Geert,
On Wed, Mar 8, 2017 at 10:47 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Hi Magnus,
>
> On Wed, Mar 8, 2017 at 12:01 PM, Magnus Damm <magnus.damm@gmail.com> wrote:
>> From: Magnus Damm <damm+renesas@opensource.se>
>>
>> Add root device handling to the IPMMU driver by allowing certain
>> DT compat strings to enable has_cache_leaf_nodes that in turn will
>> support both root devices with interrupts and leaf devices that
>> face the actual IPMMU consumer devices.
>>
>> Signed-off-by: Magnus Damm <damm+renesas@opensource.se>
>
>> --- 0011/drivers/iommu/ipmmu-vmsa.c
>> +++ work/drivers/iommu/ipmmu-vmsa.c 2017-03-08 17:56:51.770607110 +0900
>
>> @@ -216,6 +219,44 @@ static void set_archdata(struct device *
>> #define IMUASID_ASID0_SHIFT 0
>>
>> /* -----------------------------------------------------------------------------
>> + * Root device handling
>> + */
>> +
>> +static bool ipmmu_is_root(struct ipmmu_vmsa_device *mmu)
>> +{
>> + if (mmu->features->has_cache_leaf_nodes)
>> + return mmu->is_leaf ? false : true;
>
> Expressions using the ternary operator are sometimes hard to read.
> In this case, you want negation, so why not use that?
>
> return !mmu->is_leaf;
>
>> + else
>
> I'd drop the else.
Yeah, your suggestion makes the code easier to read. Will fix.
>> + return true; /* older IPMMU hardware treated as single root */
>> +}
>> +
>> +static struct ipmmu_vmsa_device *__ipmmu_find_root(void)
>> +{
>> + struct ipmmu_vmsa_device *mmu;
>> + bool found = false;
>
> struct ipmmu_vmsa_device *root = NULL;
I used to have it initialized to NULL and not use any found variable
and only return the variable. But then I ran into the error case when
devices exist on the ipmmu_devices list however none of them are root.
I returned the last one on the list regardless if they were root or
not. So I updated the code to use the found variable, and because of
that I thought I could simply drop the NULL assignment.
>> +
>> + spin_lock(&ipmmu_devices_lock);
>> +
>> + list_for_each_entry(mmu, &ipmmu_devices, list) {
>> + if (ipmmu_is_root(mmu)) {
>> + found = true;
>
> root = mmu;
>
>> + break;
>> + }
>> + }
>> +
>> + spin_unlock(&ipmmu_devices_lock);
>> + return found ? mmu : NULL;
>
> return root;
I agree it makes sense to use root as variable name, will fix. Not
sure about the NULL assignment though, can you enlighten me?
Cheers,
/ magnus
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH v3 02/09] iommu/ipmmu-vmsa: Add optional root device feature Magnus Damm <magnus.damm@gmail.com> - 2017-03-08 12:10 +0100
Re: [PATCH v3 02/09] iommu/ipmmu-vmsa: Add optional root device feature Geert Uytterhoeven <geert@linux-m68k.org> - 2017-03-08 15:00 +0100
Re: [PATCH v3 02/09] iommu/ipmmu-vmsa: Add optional root device feature Magnus Damm <magnus.damm@gmail.com> - 2017-03-09 05:40 +0100
csiph-web