linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/resctrl: fix a NULL vs IS_ERR() static checker warning
@ 2020-06-02 19:36 Dan Carpenter
  2020-06-02 22:17 ` Fenghua Yu
  2020-06-17 10:25 ` [tip: x86/urgent] x86/resctrl: Fix a NULL vs IS_ERR() static checker warning in rdt_cdp_peer_get() tip-bot2 for Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-06-02 19:36 UTC (permalink / raw)
  To: Fenghua Yu
  Cc: Reinette Chatre, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	x86, H. Peter Anvin, linux-kernel, kernel-janitors

The callers don't expect *d_cdp to be set to an error pointer, they only
check for NULL.  This leads to a static checker warning:

    arch/x86/kernel/cpu/resctrl/rdtgroup.c:2648 __init_one_rdt_domain()
    warn: 'd_cdp' could be an error pointer

This would not trigger a bug in this specific case because
__init_one_rdt_domain() calls it with a valid domain that would not have
a negative id and thus not trigger the return of the ERR_PTR(). If this
was a negative domain id then the call to rdt_find_domain() in
domain_add_cpu() would have returned the ERR_PTR() much earlier and the
creation of the domain with an invalid id would have been prevented.

Even though a bug is not triggered currently the right and safe thing to
do is to set the pointer to NULL because that is what can be checked for
when the caller is handling the CDP and non-CDP cases.

Fixes: 52eb74339a62 ("x86/resctrl: Fix rdt_find_domain() return value and checks")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
---
v2: improve commit message with extra information from the maintainer

 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 23b4b61319d3f..3f844f14fc0a6 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1117,6 +1117,7 @@ static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
 	_d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
 	if (WARN_ON(IS_ERR_OR_NULL(_d_cdp))) {
 		_r_cdp = NULL;
+		_d_cdp = NULL;
 		ret = -EINVAL;
 	}
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/resctrl: fix a NULL vs IS_ERR() static checker warning
  2020-06-02 19:36 [PATCH v2] x86/resctrl: fix a NULL vs IS_ERR() static checker warning Dan Carpenter
@ 2020-06-02 22:17 ` Fenghua Yu
  2020-06-17 10:25 ` [tip: x86/urgent] x86/resctrl: Fix a NULL vs IS_ERR() static checker warning in rdt_cdp_peer_get() tip-bot2 for Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Fenghua Yu @ 2020-06-02 22:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Reinette Chatre, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	x86, H. Peter Anvin, linux-kernel, kernel-janitors

On Tue, Jun 02, 2020 at 10:36:11PM +0300, Dan Carpenter wrote:
> The callers don't expect *d_cdp to be set to an error pointer, they only
> check for NULL.  This leads to a static checker warning:
> 
>     arch/x86/kernel/cpu/resctrl/rdtgroup.c:2648 __init_one_rdt_domain()
>     warn: 'd_cdp' could be an error pointer
> 
> This would not trigger a bug in this specific case because
> __init_one_rdt_domain() calls it with a valid domain that would not have
> a negative id and thus not trigger the return of the ERR_PTR(). If this
> was a negative domain id then the call to rdt_find_domain() in
> domain_add_cpu() would have returned the ERR_PTR() much earlier and the
> creation of the domain with an invalid id would have been prevented.
> 
> Even though a bug is not triggered currently the right and safe thing to
> do is to set the pointer to NULL because that is what can be checked for
> when the caller is handling the CDP and non-CDP cases.
> 
> Fixes: 52eb74339a62 ("x86/resctrl: Fix rdt_find_domain() return value and checks")

Acked-by: Fenghua Yu <fenghua.yu@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/urgent] x86/resctrl: Fix a NULL vs IS_ERR() static checker warning in rdt_cdp_peer_get()
  2020-06-02 19:36 [PATCH v2] x86/resctrl: fix a NULL vs IS_ERR() static checker warning Dan Carpenter
  2020-06-02 22:17 ` Fenghua Yu
@ 2020-06-17 10:25 ` tip-bot2 for Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Dan Carpenter @ 2020-06-17 10:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Dan Carpenter, Borislav Petkov, Reinette Chatre, Fenghua Yu, x86, LKML

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     cc5277fe66cf3ad68f41f1c539b2ef0d5e432974
Gitweb:        https://git.kernel.org/tip/cc5277fe66cf3ad68f41f1c539b2ef0d5e432974
Author:        Dan Carpenter <dan.carpenter@oracle.com>
AuthorDate:    Tue, 02 Jun 2020 22:36:11 +03:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Wed, 17 Jun 2020 12:18:34 +02:00

x86/resctrl: Fix a NULL vs IS_ERR() static checker warning in rdt_cdp_peer_get()

The callers don't expect *d_cdp to be set to an error pointer, they only
check for NULL.  This leads to a static checker warning:

  arch/x86/kernel/cpu/resctrl/rdtgroup.c:2648 __init_one_rdt_domain()
  warn: 'd_cdp' could be an error pointer

This would not trigger a bug in this specific case because
__init_one_rdt_domain() calls it with a valid domain that would not have
a negative id and thus not trigger the return of the ERR_PTR(). If this
was a negative domain id then the call to rdt_find_domain() in
domain_add_cpu() would have returned the ERR_PTR() much earlier and the
creation of the domain with an invalid id would have been prevented.

Even though a bug is not triggered currently the right and safe thing to
do is to set the pointer to NULL because that is what can be checked for
when the caller is handling the CDP and non-CDP cases.

Fixes: 52eb74339a62 ("x86/resctrl: Fix rdt_find_domain() return value and checks")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Reinette Chatre <reinette.chatre@intel.com>
Acked-by: Fenghua Yu <fenghua.yu@intel.com>
Link: https://lkml.kernel.org/r/20200602193611.GA190851@mwanda
---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 23b4b61..3f844f1 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -1117,6 +1117,7 @@ static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
 	_d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
 	if (WARN_ON(IS_ERR_OR_NULL(_d_cdp))) {
 		_r_cdp = NULL;
+		_d_cdp = NULL;
 		ret = -EINVAL;
 	}
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-17 10:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 19:36 [PATCH v2] x86/resctrl: fix a NULL vs IS_ERR() static checker warning Dan Carpenter
2020-06-02 22:17 ` Fenghua Yu
2020-06-17 10:25 ` [tip: x86/urgent] x86/resctrl: Fix a NULL vs IS_ERR() static checker warning in rdt_cdp_peer_get() tip-bot2 for Dan Carpenter

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).