Skip to contentSkip to conversation

acpi: fix apei related table size checking

PATCH In review Yinghai Lu 4 participants 4 messages Jul 23, 2010 – Jul 26, 2010

Subsystems (3)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 acpi: fix apei related table size checking

also check if we can find right action in apei.

---
 drivers/acpi/apei/apei-base.c |    5 +++++
 drivers/acpi/apei/einj.c      |    3 ++-
 drivers/acpi/apei/erst.c      |    3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)
drivers/acpi/apei/einj.c +2 -1
Index: linux-2.6/drivers/acpi/apei/einj.c
===================================================================
@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fop
 
 static int einj_check_table(struct acpi_table_einj *einj_tab)
 {
-	if (einj_tab->header_length != sizeof(struct acpi_table_einj))
+	if (einj_tab->header_length !=
+	    (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header)))
 		return -EINVAL;
 	if (einj_tab->header.length < sizeof(struct acpi_table_einj))
 		return -EINVAL;
drivers/acpi/apei/erst.c +2 -1
Index: linux-2.6/drivers/acpi/apei/erst.c
===================================================================
@@ -749,7 +749,8 @@ __setup("erst_disable", setup_erst_disab
 
 static int erst_check_table(struct acpi_table_erst *erst_tab)
 {
-	if (erst_tab->header_length != sizeof(struct acpi_table_erst))
+	if (erst_tab->header_length !=
+	    (sizeof(struct acpi_table_erst) - sizeof(erst_tab->header)))
 		return -EINVAL;
 	if (erst_tab->header.length < sizeof(struct acpi_table_erst))
 		return -EINVAL;
drivers/acpi/apei/apei-base.c +5 -0
Index: linux-2.6/drivers/acpi/apei/apei-base.c
===================================================================
@@ -163,6 +163,7 @@ int apei_exec_run(struct apei_exec_conte
 	u32 i, ip;
 	struct acpi_whea_header *entry;
 	apei_exec_ins_func_t run;
+	bool found_action = false;
 
 	ctx->ip = 0;
 
@@ -178,6 +179,7 @@ rewind:
 		entry = &ctx->action_table[i];
 		if (entry->action != action)
 			continue;
+		found_action = true;
 		if (ip == ctx->ip) {
 			if (entry->instruction >= ctx->instructions ||
 			    !ctx->ins_table[entry->instruction].run) {
@@ -198,6 +200,9 @@ rewind:
 			goto rewind;
 	}
 
+	if (!found_action)
+		return -ENODEV;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(apei_exec_run);
#1 lore raw
Quoted 4 lines · Yinghai Lu

also check if we can find right action in apei.

This should be split into two patches that each fix one thing.

Quoted 69 lines
---
 drivers/acpi/apei/apei-base.c |    5 +++++
 drivers/acpi/apei/einj.c      |    3 ++-
 drivers/acpi/apei/erst.c      |    3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/acpi/apei/einj.c
===================================================================

drivers/acpi/apei/einj.c +2 -1
@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fop
 
 static int einj_check_table(struct acpi_table_einj *einj_tab)
 {
-	if (einj_tab->header_length != sizeof(struct acpi_table_einj))
+	if (einj_tab->header_length !=
+	    (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header)))
 		return -EINVAL;
 	if (einj_tab->header.length < sizeof(struct acpi_table_einj))
 		return -EINVAL;

Index: linux-2.6/drivers/acpi/apei/erst.c
===================================================================

drivers/acpi/apei/erst.c +2 -1
@@ -749,7 +749,8 @@ __setup("erst_disable", setup_erst_disab
 
 static int erst_check_table(struct acpi_table_erst *erst_tab)
 {
-	if (erst_tab->header_length != sizeof(struct acpi_table_erst))
+	if (erst_tab->header_length !=
+	    (sizeof(struct acpi_table_erst) - sizeof(erst_tab->header)))
 		return -EINVAL;
 	if (erst_tab->header.length < sizeof(struct acpi_table_erst))
 		return -EINVAL;

Index: linux-2.6/drivers/acpi/apei/apei-base.c
===================================================================

drivers/acpi/apei/apei-base.c +5 -1
@@ -163,6 +163,7 @@ int apei_exec_run(struct apei_exec_conte
 	u32 i, ip;
 	struct acpi_whea_header *entry;
 	apei_exec_ins_func_t run;
+	bool found_action = false;
 
 	ctx->ip = 0;
 
@@ -178,6 +179,7 @@ rewind:
 		entry = &ctx->action_table[i];
 		if (entry->action != action)
 			continue;
+		found_action = true;
 		if (ip == ctx->ip) {
 			if (entry->instruction >= ctx->instructions ||
 			    !ctx->ins_table[entry->instruction].run) {
@@ -198,6 +200,9 @@ rewind:
 			goto rewind;
 	}
 
+	if (!found_action)
+		return -ENODEV;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(apei_exec_run);
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 5 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu

also check if we can find right action in apei.

This should be split into two patches that each fix one thing.

... and the description actually describe what it is supposed to fix.

-Andi

#3 lore raw
In reply to Yinghai Lu
Quoted 15 lines · Yinghai Lu

also check if we can find right action in apei.

---
 drivers/acpi/apei/apei-base.c |    5 +++++
 drivers/acpi/apei/einj.c      |    3 ++-
 drivers/acpi/apei/erst.c      |    3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/acpi/apei/einj.c
===================================================================

drivers/acpi/apei/einj.c DEFINE_SIMPLE_ATTRIBUTE(error_inject_fop · line 431

Quoted 7 lines
drivers/acpi/apei/einj.c +2 -1
@@ -426,7 +426,8 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fop
 
 static int einj_check_table(struct acpi_table_einj *einj_tab)
 {
-	if (einj_tab->header_length != sizeof(struct acpi_table_einj))
+	if (einj_tab->header_length !=
+	    (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header)))
 		return -EINVAL;

It seems that the header_length field is not set properly by BIOS on my testing machine which I used to develop the original code. Will try to contact BIOS guys to make sure.

Quoted 21 lines

Index: linux-2.6/drivers/acpi/apei/apei-base.c
===================================================================

drivers/acpi/apei/apei-base.c +2 -0
@@ -163,6 +163,7 @@ int apei_exec_run(struct apei_exec_conte
 	u32 i, ip;
 	struct acpi_whea_header *entry;
 	apei_exec_ins_func_t run;
+	bool found_action = false;
 
 	ctx->ip = 0;
 
@@ -178,6 +179,7 @@ rewind:
 		entry = &ctx->action_table[i];
 		if (entry->action != action)
 			continue;
+		found_action = true;
 		if (ip == ctx->ip) {
 			if (entry->instruction >= ctx->instructions ||
 			    !ctx->ins_table[entry->instruction].run) {

drivers/acpi/apei/apei-base.c rewind: · line 204

Quoted 5 lines
drivers/acpi/apei/apei-base.c +2 -0
@@ -198,6 +200,9 @@ rewind:
 			goto rewind;
 	}
 
+	if (!found_action)
+		return -ENODEV;

-ENOENT is better here?

Best Regards,
Huang Ying