Skip to content

Commit 52eb743

Browse files
rchatresuryasaimadhu
authored andcommitted
x86/resctrl: Fix rdt_find_domain() return value and checks
rdt_find_domain() returns an ERR_PTR() that is generated from a provided domain id when the value is negative. Care needs to be taken when creating an ERR_PTR() from this value because a subsequent check using IS_ERR() expects the error to be within the MAX_ERRNO range. Using an invalid domain id as an ERR_PTR() does work at this time since this is currently always -1. Using this undocumented assumption is fragile since future users of rdt_find_domain() may not be aware of thus assumption. Two related issues are addressed: - Ensure that rdt_find_domain() always returns a valid error value by forcing the error to be -ENODEV when a negative domain id is provided. - In a few instances the return value of rdt_find_domain() is just checked for NULL - fix these to include a check of ERR_PTR. Fixes: d89b737 ("x86/intel_rdt/cqm: Add mon_data") Fixes: 521348b ("x86/intel_rdt: Introduce utility to obtain CDP peer") Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: fenghua.yu@intel.com Cc: gavin.hindman@intel.com Cc: jithu.joseph@intel.com Cc: x86-ml <x86@kernel.org> Link: https://lkml.kernel.org/r/b88cd4ff6a75995bf8db9b0ea546908fe50f69f3.1544479852.git.reinette.chatre@intel.com
1 parent cb74635 commit 52eb743

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
454454
struct list_head *l;
455455

456456
if (id < 0)
457-
return ERR_PTR(id);
457+
return ERR_PTR(-ENODEV);
458458

459459
list_for_each(l, &r->domains) {
460460
d = list_entry(l, struct rdt_domain, list);

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
534534

535535
r = &rdt_resources_all[resid];
536536
d = rdt_find_domain(r, domid, NULL);
537-
if (!d) {
537+
if (IS_ERR_OR_NULL(d)) {
538538
ret = -ENOENT;
539539
goto out;
540540
}

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
10291029
* peer RDT CDP resource. Hence the WARN.
10301030
*/
10311031
_d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
1032-
if (WARN_ON(!_d_cdp)) {
1032+
if (WARN_ON(IS_ERR_OR_NULL(_d_cdp))) {
10331033
_r_cdp = NULL;
10341034
ret = -EINVAL;
10351035
}

0 commit comments

Comments
 (0)