RE: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> >+static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)
> >+{
> >+    switch (scope) {
> >+    case RESCTRL_L3_CACHE:
> >+            return get_cpu_cacheinfo_id(cpu, 3);
> >+    case RESCTRL_L2_CACHE:
> >+            return get_cpu_cacheinfo_id(cpu, 2);
> >+    default:
> >+            WARN_ON_ONCE(1);
> >+            break;
> >+    }
> >+
> >+    return -1;
> >+}
>
> Is there some reason the "return -1" is outside of the default switch
> case?
>
> Other switch statements in this patch do have returns inside the default
> case, is this one different in some way?

I've sometimes had compilers complain about code written:

static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)
{
        switch (scope) {
        case RESCTRL_L3_CACHE:
                return get_cpu_cacheinfo_id(cpu, 3);
        case RESCTRL_L2_CACHE:
                return get_cpu_cacheinfo_id(cpu, 2);
        default:
                WARN_ON_ONCE(1);
                return -1;
        }
}

because they failed to notice that every path in the switch does a "return and they
issue a warning that the function has no return value because they don't realize
that the end of the function can't be reached.

So it's defensive programming against possible complier issues.

-Tony










[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux