vhost-scsi: fix usage of error_reportf_err()

It is required to use error_report() instead of error_reportf_err(), if the
prior function does not take local_err as the argument. As a result, the
local_err is always NULL and segment fault may happen.

vhost_scsi_start()
-> vhost_scsi_set_endpoint(s) --> does not allocate local_err
-> error_reportf_err()
   -> error_vprepend()
      -> g_string_append(newmsg, (*errp)->msg) --> (*errp) is NULL

In addition, add ": " at the end of other error_reportf_err() logs.

Fixes: 7962e432b4 ("vhost-user-scsi: support reconnect to backend")
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Message-Id: <20231214003117.43960-1-dongli.zhang@oracle.com>
Reviewed-by: Feng Li <fengli@smartx.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Dongli Zhang 2023-12-13 16:31:17 -08:00 committed by Michael S. Tsirkin
parent 45e48809d3
commit 551bf7b4c1
2 changed files with 4 additions and 3 deletions

View File

@ -91,13 +91,13 @@ static int vhost_scsi_start(VHostSCSI *s)
ret = vhost_scsi_common_start(vsc, &local_err); ret = vhost_scsi_common_start(vsc, &local_err);
if (ret < 0) { if (ret < 0) {
error_reportf_err(local_err, "Error starting vhost-scsi"); error_reportf_err(local_err, "Error starting vhost-scsi: ");
return ret; return ret;
} }
ret = vhost_scsi_set_endpoint(s); ret = vhost_scsi_set_endpoint(s);
if (ret < 0) { if (ret < 0) {
error_reportf_err(local_err, "Error setting vhost-scsi endpoint"); error_report("Error setting vhost-scsi endpoint");
vhost_scsi_common_stop(vsc); vhost_scsi_common_stop(vsc);
} }

View File

@ -83,7 +83,8 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
if (should_start) { if (should_start) {
ret = vhost_user_scsi_start(s, &local_err); ret = vhost_user_scsi_start(s, &local_err);
if (ret < 0) { if (ret < 0) {
error_reportf_err(local_err, "unable to start vhost-user-scsi: %s", error_reportf_err(local_err,
"unable to start vhost-user-scsi: %s: ",
strerror(-ret)); strerror(-ret));
qemu_chr_fe_disconnect(&vs->conf.chardev); qemu_chr_fe_disconnect(&vs->conf.chardev);
} }