linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] x86/resctrl: Remove unnecessary check for cbm_validate
@ 2018-11-28 22:42 Moger, Babu
  2018-11-29  7:48 ` [tip:x86/cache] x86/resctrl: Remove unnecessary check for cbm_validate() tip-bot for Babu Moger
  0 siblings, 1 reply; 2+ messages in thread
From: Moger, Babu @ 2018-11-28 22:42 UTC (permalink / raw)
  To: tglx, mingo, bp
  Cc: hpa, x86, fenghua.yu, reinette.chatre, Moger, Babu,
	dan.carpenter, linux-kernel

The static checker(smatch) reports the following error after the
commit a36c5ff560fb ("x86/resctrl: Bring cbm_validate() into the
resource structure").

arch/x86/kernel/cpu/resctrl//ctrlmondata.c:227 parse_cbm()
error: uninitialized symbol 'cbm_val'.
arch/x86/kernel/cpu/resctrl//ctrlmondata.c:236 parse_cbm()
error: uninitialized symbol 'cbm_val'.

This could happen from the following condition if r->cbm_validate is
NULL which could leave cbm_val uninitialized.

if (r->cbm_validate && !r->cbm_validate(data->buf, &cbm_val, r))

Looking at the code again, there is no case where r->cbm_validate can be
NULL. cbm_validate is initialized based on the vendor check. It is either
Intel or AMD. In both the cases it is initialized properly. Remove the
first check completely.

Verified the fix running Smatch.

Fixes: a36c5ff560fb ("x86/resctrl: Bring cbm_validate() into the resource structure")

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v2->v3:
 Removed the unnecessary and added detailed explaination.

v1->v2:
 Added more details.

 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 03ee13235a45..ba11f54f5ab8 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -219,7 +219,7 @@ int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
 		return -EINVAL;
 	}
 
-	if (r->cbm_validate && !r->cbm_validate(data->buf, &cbm_val, r))
+	if (!r->cbm_validate(data->buf, &cbm_val, r))
 		return -EINVAL;
 
 	if ((rdtgrp->mode == RDT_MODE_EXCLUSIVE ||
-- 
2.17.1


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

* [tip:x86/cache] x86/resctrl: Remove unnecessary check for cbm_validate()
  2018-11-28 22:42 [PATCH v3] x86/resctrl: Remove unnecessary check for cbm_validate Moger, Babu
@ 2018-11-29  7:48 ` tip-bot for Babu Moger
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Babu Moger @ 2018-11-29  7:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, fenghua.yu, babu.moger, dan.carpenter,
	reinette.chatre, hpa, bp, Babu.Moger, mingo, tglx, x86, mingo

Commit-ID:  cb74635faa17cfa2991ddbe027596270af525c6d
Gitweb:     https://git.kernel.org/tip/cb74635faa17cfa2991ddbe027596270af525c6d
Author:     Babu Moger <Babu.Moger@amd.com>
AuthorDate: Wed, 28 Nov 2018 22:42:47 +0000
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Thu, 29 Nov 2018 08:36:12 +0100

x86/resctrl: Remove unnecessary check for cbm_validate()

The Smatch static checker reports the following error after commit:

  a36c5ff560fb ("x86/resctrl: Bring cbm_validate() into the resource structure"):

  arch/x86/kernel/cpu/resctrl/ctrlmondata.c:227 parse_cbm()
  error: uninitialized symbol 'cbm_val'.
  arch/x86/kernel/cpu/resctrl/ctrlmondata.c:236 parse_cbm()
  error: uninitialized symbol 'cbm_val'.

This could happen if ->cbm_validate() is NULL which could leave cbm_val
uninitialized.

However, there is no case where ->cbm_validate() can be NULL as it is
initialized based on a vendor check. So it is either an Intel or an AMD
version it points to. And in both the cases it is initialized properly.
Thus, remove the first check.

Verified the fix running Smatch.

 [ bp: massage commit message. ]

Fixes: a36c5ff560fb ("x86/resctrl: Bring cbm_validate() into the resource structure")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20181128224234.22998-1-babu.moger@amd.com
---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 03ee13235a45..ba11f54f5ab8 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -219,7 +219,7 @@ int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
 		return -EINVAL;
 	}
 
-	if (r->cbm_validate && !r->cbm_validate(data->buf, &cbm_val, r))
+	if (!r->cbm_validate(data->buf, &cbm_val, r))
 		return -EINVAL;
 
 	if ((rdtgrp->mode == RDT_MODE_EXCLUSIVE ||

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

end of thread, other threads:[~2018-11-29  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 22:42 [PATCH v3] x86/resctrl: Remove unnecessary check for cbm_validate Moger, Babu
2018-11-29  7:48 ` [tip:x86/cache] x86/resctrl: Remove unnecessary check for cbm_validate() tip-bot for Babu Moger

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