From: Jamie Nguyen <jamien@nvidia.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>, Tony Luck <tony.luck@intel.com>,
"Punit Agrawal" <punitagrawal@gmail.com>,
<linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 1/2] ACPI: sysfs: Fix data_attr leak when creating a data file fails
Date: Mon, 12 Oct 2026 16:06:31 -0700 [thread overview]
Message-ID: <20261012230632.3574987-2-jamien@nvidia.com> (raw)
In-Reply-To: <20261012230632.3574987-1-jamien@nvidia.com>
acpi_table_data_init() allocates the data_attr for a table's data file
and passes it to the table's init callback. The BERT and CCEL callbacks
free data_attr when the table is invalid, but return the result of
sysfs_create_bin_file() directly, so data_attr is leaked if creating the
file fails.
Create the file and free data_attr on failure in acpi_table_data_init()
instead, so that the callbacks only check the table and set the address
and size of the data.
Fixes: 7dae6326ed76 ("ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region")
Assisted-by: LLM
Signed-off-by: Jamie Nguyen <jamien@nvidia.com>
---
drivers/acpi/sysfs.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index dd4a99f09efea65..ae3b3ee0552d198 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -448,14 +448,13 @@ static int acpi_bert_data_init(void *th, struct acpi_data_attr *data_attr)
struct acpi_table_bert *bert = th;
if (bert->header.length < sizeof(struct acpi_table_bert) ||
- bert->region_length < sizeof(struct acpi_bert_region)) {
- kfree(data_attr);
+ bert->region_length < sizeof(struct acpi_bert_region))
return -EINVAL;
- }
+
data_attr->addr = bert->address;
data_attr->attr.size = bert->region_length;
- return sysfs_create_bin_file(tables_data_kobj, &data_attr->attr);
+ return 0;
}
static int acpi_ccel_data_init(void *th, struct acpi_data_attr *data_attr)
@@ -463,14 +462,13 @@ static int acpi_ccel_data_init(void *th, struct acpi_data_attr *data_attr)
struct acpi_table_ccel *ccel = th;
if (ccel->header.length < sizeof(struct acpi_table_ccel) ||
- !ccel->log_area_start_address || !ccel->log_area_minimum_length) {
- kfree(data_attr);
+ !ccel->log_area_start_address || !ccel->log_area_minimum_length)
return -EINVAL;
- }
+
data_attr->addr = ccel->log_area_start_address;
data_attr->attr.size = ccel->log_area_minimum_length;
- return sysfs_create_bin_file(tables_data_kobj, &data_attr->attr);
+ return 0;
}
static struct acpi_data_obj {
@@ -486,7 +484,7 @@ static struct acpi_data_obj {
static int acpi_table_data_init(struct acpi_table_header *th, struct acpi_table_attr *table_attr)
{
struct acpi_data_attr *data_attr;
- int i;
+ int i, ret;
for (i = 0; i < NUM_ACPI_DATA_OBJS; i++) {
if (ACPI_COMPARE_NAMESEG(th->signature, acpi_data_objs[i].name)) {
@@ -498,7 +496,13 @@ static int acpi_table_data_init(struct acpi_table_header *th, struct acpi_table_
data_attr->attr.attr.mode = 0400;
strscpy(data_attr->filename, table_attr->filename);
data_attr->attr.attr.name = data_attr->filename;
- return acpi_data_objs[i].fn(th, data_attr);
+ ret = acpi_data_objs[i].fn(th, data_attr);
+ if (!ret)
+ ret = sysfs_create_bin_file(tables_data_kobj,
+ &data_attr->attr);
+ if (ret)
+ kfree(data_attr);
+ return ret;
}
}
return 0;
--
2.43.0
next prev parent reply other threads:[~2026-10-12 23:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 23:06 [PATCH v2 0/2] ACPI: sysfs: Expose BDAT data region Jamie Nguyen
2026-10-12 23:06 ` Jamie Nguyen [this message]
2026-10-12 23:06 ` [PATCH v2 2/2] " Jamie Nguyen
2026-10-13 2:12 ` Jamie Nguyen
2026-10-13 10:53 ` Rafael J. Wysocki (Intel)
2026-10-13 18:11 ` Jamie Nguyen
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=20261012230632.3574987-2-jamien@nvidia.com \
--to=jamien@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=punitagrawal@gmail.com \
--cc=rafael@kernel.org \
--cc=tony.luck@intel.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