Linux ACPI
 help / color / mirror / Atom feed
* [PATCH] acpi: Incorrect ACPI tables walk in acpi_tables_sysfs_init
@ 2013-11-21 10:20 Jeremy Compostella
  2013-11-21 13:27 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Compostella @ 2013-11-21 10:20 UTC (permalink / raw)
  To: linux-acpi; +Cc: linux-kernel, Jeremy Compostella, Gross, Mark, rjw

Date: Thu, 21 Nov 2013 11:20:23 +0100
Message-ID: <87d2lu83a0.fsf@tldlab276.tl.intel.com>
MIME-Version: 1.0
Content-Type: text/plain
--text follows this line--
Hi,

When executing on a ACPI Hardware reduced hardware, all the ACPI tables are not
exposed in sysfs due to the fact that FACS is silently ignored by the kernel in
ACPI hardware reduced and, moreover, the acpi_tables_sysfs_init ACPI table walk
is buggy and stop too soon.

The acpi_tables_sysfs_init function should to rely on the appropriate
acpi_status return values to decide or not to stop the iteration.  This way,
when running on a ACPI Reduced Harware environment where the FACS table is
silently ignored by the kernel or some ACPI table are not correctly memory
mapped or have a bad checksum it would not stop the iteration.

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>

---
 drivers/acpi/sysfs.c |   52 ++++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index fcae5fa..72a3250 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -354,8 +354,9 @@ static int acpi_tables_sysfs_init(void)
 {
 	struct acpi_table_attr *table_attr;
 	struct acpi_table_header *table_header = NULL;
-	int table_index = 0;
-	int result;
+	int table_index;
+	acpi_status status;
+	int ret;
 
 	tables_kobj = kobject_create_and_add("tables", acpi_kobj);
 	if (!tables_kobj)
@@ -365,33 +366,34 @@ static int acpi_tables_sysfs_init(void)
 	if (!dynamic_tables_kobj)
 		goto err_dynamic_tables;
 
-	do {
-		result = acpi_get_table_by_index(table_index, &table_header);
-		if (!result) {
-			table_index++;
-			table_attr = NULL;
-			table_attr =
-			    kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
-			if (!table_attr)
-				return -ENOMEM;
-
-			acpi_table_attr_init(table_attr, table_header);
-			result =
-			    sysfs_create_bin_file(tables_kobj,
-						  &table_attr->attr);
-			if (result) {
-				kfree(table_attr);
-				return result;
-			} else
-				list_add_tail(&table_attr->node,
-					      &acpi_table_attr_list);
+	for (table_index = 0;; table_index++) {
+		status = acpi_get_table_by_index(table_index, &table_header);
+
+		if (status == AE_BAD_PARAMETER)
+			break;
+
+		if (ACPI_FAILURE(status))
+			continue;
+
+		table_attr = NULL;
+		table_attr = kzalloc(sizeof(*table_attr), GFP_KERNEL);
+		if (!table_attr)
+			return -ENOMEM;
+
+		acpi_table_attr_init(table_attr, table_header);
+		ret = sysfs_create_bin_file(tables_kobj, &table_attr->attr);
+		if (ret) {
+			kfree(table_attr);
+			return ret;
 		}
-	} while (!result);
+		list_add_tail(&table_attr->node, &acpi_table_attr_list);
+	}
+
 	kobject_uevent(tables_kobj, KOBJ_ADD);
 	kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
-	result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
+	status = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
 
-	return result == AE_OK ? 0 : -EINVAL;
+	return ACPI_FAILURE(status) ? -EINVAL : 0;
 err_dynamic_tables:
 	kobject_put(tables_kobj);
 err:
-- 
1.7.10.4

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


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

* Re: [PATCH] acpi: Incorrect ACPI tables walk in acpi_tables_sysfs_init
  2013-11-21 10:20 [PATCH] acpi: Incorrect ACPI tables walk in acpi_tables_sysfs_init Jeremy Compostella
@ 2013-11-21 13:27 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2013-11-21 13:27 UTC (permalink / raw)
  To: Jeremy Compostella
  Cc: linux-acpi, linux-kernel, Jeremy Compostella, Gross, Mark

On Thursday, November 21, 2013 11:20:27 AM Jeremy Compostella wrote:
> Date: Thu, 21 Nov 2013 11:20:23 +0100
> Message-ID: <87d2lu83a0.fsf@tldlab276.tl.intel.com>
> MIME-Version: 1.0
> Content-Type: text/plain
> --text follows this line--
> Hi,
> 
> When executing on a ACPI Hardware reduced hardware, all the ACPI tables are not
> exposed in sysfs due to the fact that FACS is silently ignored by the kernel in
> ACPI hardware reduced and, moreover, the acpi_tables_sysfs_init ACPI table walk
> is buggy and stop too soon.
> 
> The acpi_tables_sysfs_init function should to rely on the appropriate
> acpi_status return values to decide or not to stop the iteration.  This way,
> when running on a ACPI Reduced Harware environment where the FACS table is
> silently ignored by the kernel or some ACPI table are not correctly memory
> mapped or have a bad checksum it would not stop the iteration.
> 
> Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>

Since this is a fix, I've modified the subject and changelog slightly and
queued up the patch for the next ACPI pull request (next week).

Thanks!

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

end of thread, other threads:[~2013-11-21 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 10:20 [PATCH] acpi: Incorrect ACPI tables walk in acpi_tables_sysfs_init Jeremy Compostella
2013-11-21 13:27 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox