char: Use return values instead of error_is_set(errp)
Using error_is_set(errp) to check whether a function call failed is fragile: it breaks when errp is null. Check perfectly suitable return values instead when possible. As far as I can tell, errp can't be null there, but this is more robust and more obviously correct Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
3f9286b721
commit
5f758366c0
18
qemu-char.c
18
qemu-char.c
|
@ -3251,7 +3251,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = qmp_chardev_add(bid ? bid : id, backend, errp);
|
ret = qmp_chardev_add(bid ? bid : id, backend, errp);
|
||||||
if (error_is_set(errp)) {
|
if (!ret) {
|
||||||
goto qapi_out;
|
goto qapi_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3263,7 +3263,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
|
||||||
backend->kind = CHARDEV_BACKEND_KIND_MUX;
|
backend->kind = CHARDEV_BACKEND_KIND_MUX;
|
||||||
backend->mux->chardev = g_strdup(bid);
|
backend->mux->chardev = g_strdup(bid);
|
||||||
ret = qmp_chardev_add(id, backend, errp);
|
ret = qmp_chardev_add(id, backend, errp);
|
||||||
if (error_is_set(errp)) {
|
if (!ret) {
|
||||||
chr = qemu_chr_find(bid);
|
chr = qemu_chr_find(bid);
|
||||||
qemu_chr_delete(chr);
|
qemu_chr_delete(chr);
|
||||||
chr = NULL;
|
chr = NULL;
|
||||||
|
@ -3620,18 +3620,18 @@ static int qmp_chardev_open_file_source(char *src, int flags,
|
||||||
|
|
||||||
static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)
|
static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)
|
||||||
{
|
{
|
||||||
int flags, in = -1, out = -1;
|
int flags, in = -1, out;
|
||||||
|
|
||||||
flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY;
|
flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY;
|
||||||
out = qmp_chardev_open_file_source(file->out, flags, errp);
|
out = qmp_chardev_open_file_source(file->out, flags, errp);
|
||||||
if (error_is_set(errp)) {
|
if (out < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file->has_in) {
|
if (file->has_in) {
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
in = qmp_chardev_open_file_source(file->in, flags, errp);
|
in = qmp_chardev_open_file_source(file->in, flags, errp);
|
||||||
if (error_is_set(errp)) {
|
if (in < 0) {
|
||||||
qemu_close(out);
|
qemu_close(out);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3647,7 +3647,7 @@ static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial,
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
|
fd = qmp_chardev_open_file_source(serial->device, O_RDWR, errp);
|
||||||
if (error_is_set(errp)) {
|
if (fd < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
qemu_set_nonblock(fd);
|
qemu_set_nonblock(fd);
|
||||||
|
@ -3665,7 +3665,7 @@ static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel,
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = qmp_chardev_open_file_source(parallel->device, O_RDWR, errp);
|
fd = qmp_chardev_open_file_source(parallel->device, O_RDWR, errp);
|
||||||
if (error_is_set(errp)) {
|
if (fd < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return qemu_chr_open_pp_fd(fd);
|
return qemu_chr_open_pp_fd(fd);
|
||||||
|
@ -3692,7 +3692,7 @@ static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock,
|
||||||
} else {
|
} else {
|
||||||
fd = socket_connect(addr, errp, NULL, NULL);
|
fd = socket_connect(addr, errp, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (error_is_set(errp)) {
|
if (fd < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return qemu_chr_open_socket_fd(fd, do_nodelay, is_listen,
|
return qemu_chr_open_socket_fd(fd, do_nodelay, is_listen,
|
||||||
|
@ -3705,7 +3705,7 @@ static CharDriverState *qmp_chardev_open_udp(ChardevUdp *udp,
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = socket_dgram(udp->remote, udp->local, errp);
|
fd = socket_dgram(udp->remote, udp->local, errp);
|
||||||
if (error_is_set(errp)) {
|
if (fd < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return qemu_chr_open_udp_fd(fd);
|
return qemu_chr_open_udp_fd(fd);
|
||||||
|
|
Loading…
Reference in a new issue