qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] qmp: Add error proofing for query-acpi-ospm-status


From: Kunkun Jiang
Subject: [PATCH] qmp: Add error proofing for query-acpi-ospm-status
Date: Wed, 8 Feb 2023 15:45:01 +0800

The ACPI device may not implement the ospm_status callback. Executing
qmp "query-acpi-ospm-status" will cause segmentation fault. Add error
proofing add log to avoid such serious consequences.

Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
---
 monitor/qmp-cmds.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index bf22a8c5a6..7652613635 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -229,7 +229,12 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
         AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
         AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
 
-        adevc->ospm_status(adev, &prev);
+        if (adevc->ospm_status) {
+            adevc->ospm_status(adev, &prev);
+        } else {
+            error_setg(errp, "command is not supported, "
+                             "ACPI device missing ospm_status callback");
+        }
     } else {
         error_setg(errp, "command is not supported, missing ACPI device");
     }
-- 
2.33.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]