linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaofei Tan <tanxiaofei@huawei.com>
To: <mchehab@kernel.org>, <linux-edac@vger.kernel.org>
Cc: Xiaofei Tan <tanxiaofei@huawei.com>, <linuxarm@huawei.com>,
	<shiju.jose@huawei.com>, <jonathan.cameron@huawei.com>
Subject: [PATCH 8/9] rasdaemon: fix magic number issues reported by static code analysis for hip08
Date: Tue, 12 Nov 2019 20:27:13 +0800	[thread overview]
Message-ID: <1573561634-225173-9-git-send-email-tanxiaofei@huawei.com> (raw)
In-Reply-To: <1573561634-225173-1-git-send-email-tanxiaofei@huawei.com>

Fix magic number issues reported by static code analysis for hip08.

Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
---
 non-standard-hisi_hip08.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/non-standard-hisi_hip08.c b/non-standard-hisi_hip08.c
index fcc7a0e..976345d 100644
--- a/non-standard-hisi_hip08.c
+++ b/non-standard-hisi_hip08.c
@@ -78,6 +78,14 @@
 #define HISI_PCIE_LOCAL_VALID_ERR_SEVERITY	BIT(8)
 #define HISI_PCIE_LOCAL_VALID_ERR_MISC		9
 
+#define HISI_PCIE_LOCAL_ERR_MISC_MAX	33
+#define HISI_BUF_LEN	1024
+
+#define HISI_ERR_SEVERITY_NFE	0
+#define HISI_ERR_SEVERITY_FE	1
+#define HISI_ERR_SEVERITY_CE	2
+#define HISI_ERR_SEVERITY_NONE	3
+
 struct hisi_oem_type1_err_sec {
 	uint32_t   val_bits;
 	uint8_t    version;
@@ -132,7 +140,7 @@ struct hisi_pcie_local_err_sec {
 	uint8_t    err_severity;
 	uint16_t   err_type;
 	uint8_t    reserv[2];
-	uint32_t   err_misc[33];
+	uint32_t   err_misc[HISI_PCIE_LOCAL_ERR_MISC_MAX];
 };
 
 enum hisi_oem_data_type {
@@ -193,10 +201,10 @@ struct hisi_module_info {
 static char *err_severity(uint8_t err_sev)
 {
 	switch (err_sev) {
-	case 0: return "recoverable";
-	case 1: return "fatal";
-	case 2: return "corrected";
-	case 3: return "none";
+	case HISI_ERR_SEVERITY_NFE: return "recoverable";
+	case HISI_ERR_SEVERITY_FE: return "fatal";
+	case HISI_ERR_SEVERITY_CE: return "corrected";
+	case HISI_ERR_SEVERITY_NONE: return "none";
 	}
 	return "unknown";
 }
@@ -565,7 +573,7 @@ static void decode_oem_type1_err_hdr(struct ras_ns_dec_tab *dec_tab,
 				     struct trace_seq *s,
 				     const struct hisi_oem_type1_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 
 	p += sprintf(p, "[ ");
@@ -631,7 +639,7 @@ static void decode_oem_type1_err_regs(struct ras_ns_dec_tab *dec_tab,
 				      struct trace_seq *s,
 				      const struct hisi_oem_type1_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 
 	trace_seq_printf(s, "Reg Dump:\n");
@@ -713,7 +721,7 @@ static void decode_oem_type2_err_hdr(struct ras_ns_dec_tab *dec_tab,
 				     struct trace_seq *s,
 				     const struct hisi_oem_type2_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 
 	p += sprintf(p, "[ ");
@@ -779,7 +787,7 @@ static void decode_oem_type2_err_regs(struct ras_ns_dec_tab *dec_tab,
 				      struct trace_seq *s,
 				      const struct hisi_oem_type2_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 
 	trace_seq_printf(s, "Reg Dump:\n");
@@ -872,7 +880,7 @@ static void decode_pcie_local_err_hdr(struct ras_ns_dec_tab *dec_tab,
 				      struct trace_seq *s,
 				      const struct hisi_pcie_local_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 
 	p += sprintf(p, "[ ");
@@ -945,12 +953,12 @@ static void decode_pcie_local_err_regs(struct ras_ns_dec_tab *dec_tab,
 				       struct trace_seq *s,
 				       const struct hisi_pcie_local_err_sec *err)
 {
-	char buf[1024];
+	char buf[HISI_BUF_LEN];
 	char *p = buf;
 	uint32_t i;
 
 	trace_seq_printf(s, "Reg Dump:\n");
-	for (i = 0; i < 33; i++) {
+	for (i = 0; i < HISI_PCIE_LOCAL_ERR_MISC_MAX; i++) {
 		if (err->val_bits & BIT(HISI_PCIE_LOCAL_VALID_ERR_MISC + i)) {
 			trace_seq_printf(s, "ERR_MISC_%d=0x%x\n", i,
 					 err->err_misc[i]);
-- 
2.8.1


  parent reply	other threads:[~2019-11-12 12:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-12 12:27 [PATCH 0/9] rasdaemon: fix some issues reported by static code analysis Xiaofei Tan
2019-11-12 12:27 ` [PATCH 1/9] rasdaemon: fix the wrong declaring of 'sruct ras_events' in ras-record.h Xiaofei Tan
2019-11-12 12:27 ` [PATCH 2/9] rasdaemon: fix an warning reported by PC-Lint Xiaofei Tan
2019-11-12 12:27 ` [PATCH 3/9] rasdaemon: decode submodule of OEM type1 for hip08 Xiaofei Tan
2019-11-26  6:07   ` Mauro Carvalho Chehab
2019-11-26  8:28     ` Xiaofei Tan
2019-11-12 12:27 ` [PATCH 4/9] rasdaemon: fix sub module name of HHA and DDRC " Xiaofei Tan
2019-11-12 12:27 ` [PATCH 5/9] rasdaemon: split OEM type1 table decode function to reduce length Xiaofei Tan
2019-11-12 12:27 ` [PATCH 6/9] rasdaemon: split OEM type2 " Xiaofei Tan
2019-11-12 12:27 ` [PATCH 7/9] rasdaemon: split PCIe local " Xiaofei Tan
2019-11-12 12:27 ` Xiaofei Tan [this message]
2019-11-12 12:27 ` [PATCH 9/9] rasdaemon: replace sprintf with snprintf for hip08 Xiaofei Tan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1573561634-225173-9-git-send-email-tanxiaofei@huawei.com \
    --to=tanxiaofei@huawei.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mchehab@kernel.org \
    --cc=shiju.jose@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).