[PATCH] x86/aepi: Fully remove dead code

Andrew Cooper posted 1 patch 1 week, 3 days ago
xen/arch/x86/cpu/mcheck/mce-apei.c |  40 ----
xen/drivers/acpi/apei/erst.c       | 286 -----------------------------
2 files changed, 326 deletions(-)
[PATCH] x86/aepi: Fully remove dead code
Posted by Andrew Cooper 1 week, 3 days ago
These were marked "currently dead" in commit e681c0408564 ("ACPI/ERST: fix
signed/unsigned type conflicts") in 2014.  They're no-less dead 12 years
later.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <jbeulich@suse.com>
CC: Roger Pau Monné <roger@xenproject.org>
CC: Teddy Astie <teddy.astie@vates.tech>
---
 xen/arch/x86/cpu/mcheck/mce-apei.c |  40 ----
 xen/drivers/acpi/apei/erst.c       | 286 -----------------------------
 2 files changed, 326 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce-apei.c b/xen/arch/x86/cpu/mcheck/mce-apei.c
index 0b1c9902c0bd..f5737aa14630 100644
--- a/xen/arch/x86/cpu/mcheck/mce-apei.c
+++ b/xen/arch/x86/cpu/mcheck/mce-apei.c
@@ -87,43 +87,3 @@ int apei_write_mce(struct mce *m)
 
 	return erst_write(&rcd.hdr);
 }
-
-#ifndef NDEBUG /* currently dead code */
-
-ssize_t apei_read_mce(struct mce *m, u64 *record_id)
-{
-	struct cper_mce_record rcd;
-	ssize_t len;
-
-	if (!m || !record_id)
-		return -EINVAL;
-
-	len = erst_read_next(&rcd.hdr, sizeof(rcd));
-	if (len <= 0)
-		return len;
-	/* Can not skip other records in storage via ERST unless clear them */
-	else if (len != sizeof(rcd) ||
-		 uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE)) {
-		printk(KERN_WARNING
-			"MCE-APEI: Can not skip the unknown record in ERST");
-		return -EIO;
-	}
-
-	memcpy(m, &rcd.mce, sizeof(*m));
-	*record_id = rcd.hdr.record_id;
-
-	return sizeof(*m);
-}
-
-/* Check whether there is record in ERST */
-bool apei_check_mce(void)
-{
-	return erst_get_record_count() > 0;
-}
-
-int apei_clear_mce(u64 record_id)
-{
-	return erst_clear(record_id);
-}
-
-#endif /* currently dead code */
diff --git a/xen/drivers/acpi/apei/erst.c b/xen/drivers/acpi/apei/erst.c
index 76f799c0ab44..195b527cfda4 100644
--- a/xen/drivers/acpi/apei/erst.c
+++ b/xen/drivers/acpi/apei/erst.c
@@ -382,74 +382,6 @@ static int erst_get_erange(struct erst_erange *range)
 	return 0;
 }
 
-#ifndef NDEBUG /* currently dead code */
-
-static ssize_t __erst_get_record_count(void)
-{
-	struct apei_exec_context ctx;
-	int rc;
-	u64 output;
-	ssize_t count;
-
-	erst_exec_ctx_init(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_GET_RECORD_COUNT);
-	if (rc)
-		return rc;
-	count = output = apei_exec_ctx_get_output(&ctx);
-	return count >= 0 && count == output ? count : -ERANGE;
-}
-
-ssize_t erst_get_record_count(void)
-{
-	ssize_t count;
-	unsigned long flags;
-
-	if (!erst_enabled)
-		return -ENODEV;
-
-	spin_lock_irqsave(&erst_lock, flags);
-	count = __erst_get_record_count();
-	spin_unlock_irqrestore(&erst_lock, flags);
-
-	return count;
-}
-
-static int __erst_get_next_record_id(u64 *record_id)
-{
-	struct apei_exec_context ctx;
-	int rc;
-
-	erst_exec_ctx_init(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_GET_RECORD_ID);
-	if (rc)
-		return rc;
-	*record_id = apei_exec_ctx_get_output(&ctx);
-
-	return 0;
-}
-
-/*
- * Get the record ID of an existing error record on the persistent
- * storage. If there is no error record on the persistent storage, the
- * returned record_id is APEI_ERST_INVALID_RECORD_ID.
- */
-int erst_get_next_record_id(u64 *record_id)
-{
-	int rc;
-	unsigned long flags;
-
-	if (!erst_enabled)
-		return -ENODEV;
-
-	spin_lock_irqsave(&erst_lock, flags);
-	rc = __erst_get_next_record_id(record_id);
-	spin_unlock_irqrestore(&erst_lock, flags);
-
-	return rc;
-}
-
-#endif /* currently dead code */
-
 static int __erst_write_to_storage(u64 offset)
 {
 	struct apei_exec_context ctx;
@@ -489,92 +421,6 @@ static int __erst_write_to_storage(u64 offset)
 	return erst_errno(val);
 }
 
-#ifndef NDEBUG /* currently dead code */
-
-static int __erst_read_from_storage(u64 record_id, u64 offset)
-{
-	struct apei_exec_context ctx;
-	u64 timeout = FIRMWARE_TIMEOUT;
-	u64 val;
-	int rc;
-
-	erst_exec_ctx_init(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_BEGIN_READ);
-	if (rc)
-		return rc;
-	apei_exec_ctx_set_input(&ctx, offset);
-	rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_OFFSET);
-	if (rc)
-		return rc;
-	apei_exec_ctx_set_input(&ctx, record_id);
-	rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_ID);
-	if (rc)
-		return rc;
-	rc = apei_exec_run(&ctx, ACPI_ERST_EXECUTE_OPERATION);
-	if (rc)
-		return rc;
-	for (;;) {
-		rc = apei_exec_run(&ctx, ACPI_ERST_CHECK_BUSY_STATUS);
-		if (rc)
-			return rc;
-		val = apei_exec_ctx_get_output(&ctx);
-		if (!val)
-			break;
-		if (erst_timedout(&timeout, SPIN_UNIT))
-			return -EIO;
-	};
-	rc = apei_exec_run(&ctx, ACPI_ERST_GET_COMMAND_STATUS);
-	if (rc)
-		return rc;
-	val = apei_exec_ctx_get_output(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_END);
-	if (rc)
-		return rc;
-
-	return erst_errno(val);
-}
-
-static int __erst_clear_from_storage(u64 record_id)
-{
-	struct apei_exec_context ctx;
-	u64 timeout = FIRMWARE_TIMEOUT;
-	u64 val;
-	int rc;
-
-	erst_exec_ctx_init(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_BEGIN_CLEAR);
-	if (rc)
-		return rc;
-	apei_exec_ctx_set_input(&ctx, record_id);
-	rc = apei_exec_run(&ctx, ACPI_ERST_SET_RECORD_ID);
-	if (rc)
-		return rc;
-	rc = apei_exec_run(&ctx, ACPI_ERST_EXECUTE_OPERATION);
-	if (rc)
-		return rc;
-	for (;;) {
-		rc = apei_exec_run(&ctx, ACPI_ERST_CHECK_BUSY_STATUS);
-		if (rc)
-			return rc;
-		val = apei_exec_ctx_get_output(&ctx);
-		if (!val)
-			break;
-		if (erst_timedout(&timeout, SPIN_UNIT))
-			return -EIO;
-	}
-	rc = apei_exec_run(&ctx, ACPI_ERST_GET_COMMAND_STATUS);
-	if (rc)
-		return rc;
-	val = apei_exec_ctx_get_output(&ctx);
-	rc = apei_exec_run(&ctx, ACPI_ERST_END);
-	if (rc)
-		return rc;
-
-	return erst_errno(val);
-}
-
-#endif /* currently dead code */
-
 /* NVRAM ERST Error Log Address Range is not supported yet */
 static int __erst_write_to_nvram(const struct cper_record_header *record)
 {
@@ -582,24 +428,6 @@ static int __erst_write_to_nvram(const struct cper_record_header *record)
 	return -ENOSYS;
 }
 
-#ifndef NDEBUG /* currently dead code */
-
-static int __erst_read_to_erange_from_nvram(u64 record_id, u64 *offset)
-{
-	printk(KERN_WARNING
-		"NVRAM ERST Log Address Range is not implemented yet\n");
-	return -ENOSYS;
-}
-
-static int __erst_clear_from_nvram(u64 record_id)
-{
-	printk(KERN_WARNING
-		"NVRAM ERST Log Address Range is not implemented yet\n");
-	return -ENOSYS;
-}
-
-#endif /* currently dead code */
-
 int erst_write(const struct cper_record_header *record)
 {
 	int rc;
@@ -639,120 +467,6 @@ int erst_write(const struct cper_record_header *record)
 	return rc;
 }
 
-#ifndef NDEBUG /* currently dead code */
-
-static int __erst_read_to_erange(u64 record_id, u64 *offset)
-{
-	int rc;
-
-	if (erst_erange.attr & ERST_RANGE_NVRAM)
-		return __erst_read_to_erange_from_nvram(
-			record_id, offset);
-
-	rc = __erst_read_from_storage(record_id, 0);
-	if (rc)
-		return rc;
-	*offset = 0;
-
-	return 0;
-}
-
-static ssize_t __erst_read(u64 record_id, struct cper_record_header *record,
-			   size_t buflen)
-{
-	int rc;
-	u64 offset;
-	ssize_t len;
-	struct cper_record_header *rcd_tmp;
-
-	rc = __erst_read_to_erange(record_id, &offset);
-	if (rc)
-		return rc;
-	rcd_tmp = erst_erange.vaddr + offset;
-	if (rcd_tmp->record_length > buflen)
-		return -ENOBUFS;
-	len = rcd_tmp->record_length;
-	if (len < 0)
-		return -ERANGE;
-	memcpy(record, rcd_tmp, len);
-
-	return len;
-}
-
-/*
- * If return value > buflen, the buffer size is not big enough,
- * else if return value < 0, something goes wrong,
- * else everything is OK, and return value is record length
- */
-ssize_t erst_read(u64 record_id, struct cper_record_header *record,
-		  size_t buflen)
-{
-	ssize_t len;
-	unsigned long flags;
-
-	if (!erst_enabled)
-		return -ENODEV;
-
-	spin_lock_irqsave(&erst_lock, flags);
-	len = __erst_read(record_id, record, buflen);
-	spin_unlock_irqrestore(&erst_lock, flags);
-	return len;
-}
-
-/*
- * If return value > buflen, the buffer size is not big enough,
- * else if return value = 0, there is no more record to read,
- * else if return value < 0, something goes wrong,
- * else everything is OK, and return value is record length
- */
-ssize_t erst_read_next(struct cper_record_header *record, size_t buflen)
-{
-	int rc;
-	ssize_t len;
-	unsigned long flags;
-	u64 record_id;
-
-	if (!erst_enabled)
-		return -ENODEV;
-
-	spin_lock_irqsave(&erst_lock, flags);
-	rc = __erst_get_next_record_id(&record_id);
-	if (rc) {
-		spin_unlock_irqrestore(&erst_lock, flags);
-		return rc;
-	}
-	/* no more record */
-	if (record_id == APEI_ERST_INVALID_RECORD_ID) {
-		spin_unlock_irqrestore(&erst_lock, flags);
-		return 0;
-	}
-
-	len = __erst_read(record_id, record, buflen);
-	spin_unlock_irqrestore(&erst_lock, flags);
-
-	return len;
-}
-
-int erst_clear(u64 record_id)
-{
-	int rc;
-	unsigned long flags;
-
-	if (!erst_enabled)
-		return -ENODEV;
-
-	spin_lock_irqsave(&erst_lock, flags);
-	if (erst_erange.attr & ERST_RANGE_NVRAM)
-		rc = __erst_clear_from_nvram(record_id);
-	else
-		rc = __erst_clear_from_storage(record_id);
-	spin_unlock_irqrestore(&erst_lock, flags);
-
-	return rc;
-}
-
-#endif /* currently dead code */
-
 static int __init erst_check_table(struct acpi_table_erst *erst_tab)
 {
 	if (erst_tab->header.length < sizeof(*erst_tab))
-- 
2.39.5


Re: [PATCH] x86/aepi: Fully remove dead code
Posted by Jan Beulich 1 week ago
On 13.11.2026 13:18, Andrew Cooper wrote:
> These were marked "currently dead" in commit e681c0408564 ("ACPI/ERST: fix
> signed/unsigned type conflicts") in 2014.  They're no-less dead 12 years
> later.
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
Re: [PATCH] x86/aepi: Fully remove dead code
Posted by Jan Beulich 1 week ago
On 16.11.2026 09:34, Jan Beulich wrote:
> On 13.11.2026 13:18, Andrew Cooper wrote:
>> These were marked "currently dead" in commit e681c0408564 ("ACPI/ERST: fix
>> signed/unsigned type conflicts") in 2014.  They're no-less dead 12 years
>> later.
>>
>> No functional change.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>

With (nit) s/aepi/apei/ in the subject, that is.

Jan