acpi_table_add(): report fatal errors through an internal Error object
The upcoming changes will need a cleanup section at the end of the function, plus OptsVisitor reports errors via Error. For now keep channeling any Errors to stderr. Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Message-id: 1363821803-3380-4-git-send-email-lersek@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
cb88a4ea79
commit
445d9cae37
29
hw/acpi.c
29
hw/acpi.c
@ -64,6 +64,7 @@ static int acpi_checksum(const uint8_t *data, int len)
|
|||||||
/* XXX fixme: this function uses obsolete argument parsing interface */
|
/* XXX fixme: this function uses obsolete argument parsing interface */
|
||||||
int acpi_table_add(const char *t)
|
int acpi_table_add(const char *t)
|
||||||
{
|
{
|
||||||
|
Error *err = NULL;
|
||||||
char buf[1024], *p, *f;
|
char buf[1024], *p, *f;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
size_t len, start, allen;
|
size_t len, start, allen;
|
||||||
@ -87,8 +88,8 @@ int acpi_table_add(const char *t)
|
|||||||
has_header = true;
|
has_header = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "acpitable: both data and file are specified\n");
|
error_setg(&err, "acpitable: both data and file are specified");
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!acpi_tables) {
|
if (!acpi_tables) {
|
||||||
@ -108,8 +109,8 @@ int acpi_table_add(const char *t)
|
|||||||
int fd = open(f, O_RDONLY | O_BINARY);
|
int fd = open(f, O_RDONLY | O_BINARY);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, "can't open file %s: %s\n", f, strerror(errno));
|
error_setg(&err, "can't open file %s: %s", f, strerror(errno));
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -122,10 +123,10 @@ int acpi_table_add(const char *t)
|
|||||||
memcpy(acpi_tables + allen, data, r);
|
memcpy(acpi_tables + allen, data, r);
|
||||||
allen += r;
|
allen += r;
|
||||||
} else if (errno != EINTR) {
|
} else if (errno != EINTR) {
|
||||||
fprintf(stderr, "can't read file %s: %s\n",
|
error_setg(&err, "can't read file %s: %s",
|
||||||
f, strerror(errno));
|
f, strerror(errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,8 +170,8 @@ int acpi_table_add(const char *t)
|
|||||||
if (get_param_value(buf, sizeof(buf), "rev", t)) {
|
if (get_param_value(buf, sizeof(buf), "rev", t)) {
|
||||||
val = strtoul(buf, &p, 0);
|
val = strtoul(buf, &p, 0);
|
||||||
if (val > 255 || *p) {
|
if (val > 255 || *p) {
|
||||||
fprintf(stderr, "acpitable: \"rev=%s\" is invalid\n", buf);
|
error_setg(&err, "acpitable: \"rev=%s\" is invalid", buf);
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
hdr.revision = (uint8_t)val;
|
hdr.revision = (uint8_t)val;
|
||||||
++changed;
|
++changed;
|
||||||
@ -191,8 +192,8 @@ int acpi_table_add(const char *t)
|
|||||||
if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
|
if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
|
||||||
val = strtol(buf, &p, 0);
|
val = strtol(buf, &p, 0);
|
||||||
if (*p) {
|
if (*p) {
|
||||||
fprintf(stderr, "acpitable: \"oem_rev=%s\" is invalid\n", buf);
|
error_setg(&err, "acpitable: \"oem_rev=%s\" is invalid", buf);
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
hdr.oem_revision = cpu_to_le32(val);
|
hdr.oem_revision = cpu_to_le32(val);
|
||||||
++changed;
|
++changed;
|
||||||
@ -207,9 +208,9 @@ int acpi_table_add(const char *t)
|
|||||||
if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
|
if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
|
||||||
val = strtol(buf, &p, 0);
|
val = strtol(buf, &p, 0);
|
||||||
if (*p) {
|
if (*p) {
|
||||||
fprintf(stderr, "acpitable: \"%s=%s\" is invalid\n",
|
error_setg(&err, "acpitable: \"%s=%s\" is invalid",
|
||||||
"asl_compiler_rev", buf);
|
"asl_compiler_rev", buf);
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
hdr.asl_compiler_revision = cpu_to_le32(val);
|
hdr.asl_compiler_revision = cpu_to_le32(val);
|
||||||
++changed;
|
++changed;
|
||||||
@ -240,6 +241,10 @@ int acpi_table_add(const char *t)
|
|||||||
acpi_tables_len = allen;
|
acpi_tables_len = allen;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
fprintf(stderr, "%s\n", error_get_pretty(err));
|
||||||
|
error_free(err);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void acpi_notify_wakeup(Notifier *notifier, void *data)
|
static void acpi_notify_wakeup(Notifier *notifier, void *data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user