Re: [PATCH] x86/resctrl: Fix rdt_find_domain() return value checks
From: Reinette Chatre
Date: Mon Dec 10 2018 - 15:42:18 EST
Hi Boris,
On 12/10/2018 11:13 AM, Borislav Petkov wrote:
> On Wed, Nov 28, 2018 at 10:20:27AM -0800, Reinette Chatre wrote:
>> rdt_find_domain() may return an ERR_PTR(), NULL, or a pointer to struct
>> rdt_domain. It is thus required that the return value be checked for the
>> possibility of an ERR_PTR as well as NULL.
>
> Well, it returns ERR_PTR(id) but code which uses ERR_PTR passes in an -E
> value, for example ERR_PTR(-EINVAL) or so, and not an id.
>
> And that might work now if id fits within that MAX_ERRNO range - I'm
> looking at include/linux/err.h - but that's still fragile.
>
Thank you for catching this.
It does seem as though things work at this time since rdt_find_domain()
contains:
if (id < 0)
return ERR_PTR(id);
and from what I can tell the only possible negative value of id is -1.
As you note, this is fragile. Additionally the error, if intending to
use -E values, does not reflect the error (since -1 would mean EPERM).
Would you be ok if the above is changed to
if (id < 0)
return ERR_PTR(-ENOENT);
as part of this patch?
Looking at rdtgroup_mondata_show() is does seem as though ENOENT is the
actual intended error value, although ENODEV could perhaps also be
considered since such a result reflects that a particular cache instance
could not be found.
Thank you!
Reinette