virtio-gpu: fix error handling and improve consistency
v6 cover virtio-gpu: fix error handling and improve consistency
This series addresses error handling issues in virtio-gpu and improves code consistency across the virtio-gpu subsystem.
The first patch fixes a critical bug in virgl_cmd_resource_create_blob() where an inverted error check causes the function to fail when it should succeed. This is a standalone bug fix that should be backported.
The second patch improves code consistency by unifying the error checking style for virtio_gpu_create_mapping_iov() in if-statement contexts across virtio-gpu files, following the preferred QEMU coding convention.
Changes since v5:
- Reverted changes to virtio-gpu-rutabaga.c to keep CHECK macro usage consistent with other error checks in the same file
- Updated patch 2 commit message to clarify that CHECK macro patterns in rutabaga.c are intentionally left unchanged
Changes since v4:
- Split the single patch into two separate patches for better clarity
- Separated the critical bug fix from the style consistency improvements
- The bug fix (patch 1) can now be easily identified and backported
- The consistency improvements (patch 2) are clearly marked as cleanup
Changes since v3:
- Extended consistency improvements to virtio-gpu-rutabaga.c
- Changed CHECK(!ret) to CHECK(ret >= 0) and CHECK(!result) to CHECK(result >= 0) in rutabaga functions for consistency
- Now covers all virtio-gpu files that use virtio_gpu_create_mapping_iov()
Changes since v2:
- Use 'if (ret < 0)' instead of 'if (ret != 0)' following maintainer's feedback on preferred QEMU coding style for error checking functions that return 0 on success and negative on error
- Updated all similar usages across virtio-gpu files for consistency
- Expanded scope from single function fix to codebase-wide style consistency
Honglei Huang (2):
virtio-gpu: fix error handling in virgl_cmd_resource_create_blob
virtio-gpu: use consistent error checking for
virtio_gpu_create_mapping_iov
hw/display/virtio-gpu-virgl.c | 4 ++-- hw/display/virtio-gpu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH v6 1/2 virtio-gpu: fix error handling in virgl_cmd_resource_create_blob
Fix inverted error check in virgl_cmd_resource_create_blob() that causes the function to return error when virtio_gpu_create_mapping_iov() succeeds.
virtio_gpu_create_mapping_iov() returns 0 on success and negative values on error. The check 'if (!ret)' incorrectly treats success (ret=0) as an error condition, causing the function to fail when it should succeed.
Change the condition to 'if (ret != 0)' to properly detect errors.
--- hw/display/virtio-gpu-virgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +1 -1
@@ -701,7 +701,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->base.addrs, &res->base.iov, &res->base.iov_cnt); -if (!ret) { +if (ret !=0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }
Signature · 1 line
2.34.1
Re: [v6 1/2] virtio-gpu: fix error handling in virgl_cmd_resource_create_blob
Quoted 9 lines · Honglei Huang
Fix inverted error check in
virgl_cmd_resource_create_blob()that causes the function to return error whenvirtio_gpu_create_mapping_iov()succeeds.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The check 'if (!ret)' incorrectly treats success (ret=0) as an error condition, causing the function to fail when it should succeed.Change the condition to 'if (ret != 0)' to properly detect errors.
Quoted 7 lines
Fixes 7c092f17ccee ("virtio-gpu: Handle resource blob commands")Signed-off-by Honglei Huang <[email protected]>Reviewed-by Akihiko Odaki <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>--- hw/display/virtio-gpu-virgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v6 2/2 virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
In reply to Honglei HuangUnify error checking style for virtio_gpu_create_mapping_iov() across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov() returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' in virtio-gpu-virgl.c and virtio-gpu.c
- Some used 'CHECK(!ret, cmd)' in virtio-gpu-rutabaga.c
For if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.
Updated locations:
- hw/display/virtio-gpu-virgl.c: virgl_resource_attach_backing()
- hw/display/virtio-gpu-virgl.c: virgl_cmd_resource_create_blob()
- hw/display/virtio-gpu.c: virtio_gpu_resource_create_blob()
- hw/display/virtio-gpu.c: virtio_gpu_resource_attach_backing()
--- hw/display/virtio-gpu-virgl.c | 4 ++-- hw/display/virtio-gpu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
hw/display/virtio-gpu-virgl.c +2 -2
@@ -557,7 +557,7 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, att_rb.nr_entries,sizeof (att_rb), cmd,NULL , &res_iovs, &res_niov); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }
@@ -701,7 +701,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->base.addrs, &res->base.iov, &res->base.iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }
hw/display/virtio-gpu.c +2 -2
@@ -352,7 +352,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;g_free (res);return ;
@@ -931,7 +931,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, ab.nr_entries,sizeof (ab), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }
Signature · 1 line
2.34.1
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
Quoted 17 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.
Quoted 8 lines
Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
In reply to Honglei HuangQuoted 66 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>--- hw/display/virtio-gpu-virgl.c | 4 ++-- hw/display/virtio-gpu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)hw/display/virtio-gpu-virgl.c +2
-2@@ -557,7 +557,7 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, att_rb.nr_entries,sizeof (att_rb), cmd,NULL , &res_iovs, &res_niov); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }@@ -701,7 +701,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->base.addrs, &res->base.iov, &res->base.iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }hw/display/virtio-gpu.c +1
-1@@ -352,7 +352,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;g_free (res);return ;
hw/display/virtio-gpu.c virtio_gpu_resource_attach_backing(VirtIOGPU *g, · line 937
Quoted 8 lines
hw/display/virtio-gpu.c +1
-1@@ -931,7 +931,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, ab.nr_entries,sizeof (ab), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }
Signature · 2 lines
Best regards, Dmitry
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
Quoted 68 lines · Dmitry Osipenko
Quoted 67 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>--- hw/display/virtio-gpu-virgl.c | 4 ++-- hw/display/virtio-gpu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)hw/display/virtio-gpu-virgl.c +2
-2@@ -557,7 +557,7 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, att_rb.nr_entries,sizeof (att_rb), cmd,NULL , &res_iovs, &res_niov); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }@@ -701,7 +701,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->base.addrs, &res->base.iov, &res->base.iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }hw/display/virtio-gpu.c +1
-1@@ -352,7 +352,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *g, ret =virtio_gpu_create_mapping_iov (g, cblob.nr_entries,sizeof (cblob), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;g_free (res);return ;@@ -931,7 +931,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g,
Quoted 10 lines
hw/display/virtio-gpu.c virtio_gpu_resource_attach_backing(VirtIOGPU *g, · line 937
Quoted 7 lines
hw/display/virtio-gpu.c +1
-1ret =virtio_gpu_create_mapping_iov (g, ab.nr_entries,sizeof (ab), cmd, &res->addrs, &res->iov, &res->iov_cnt); -if (ret !=0 ) { +if (ret <0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ; }Reviewed-by Dmitry Osipenko <[email protected]>
Really thanks for the review and patience.
Regards,
Honglei
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
Quoted 96 lines · Honglei Huang
Quoted 83 lines · Dmitry Osipenko
Quoted 82 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the
codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative
on error. This makes the return value convention immediately clear to code
readers.For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other
error checks in the same file.Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>---
hw/display/virtio-gpu-virgl.c| 4 ++--
hw/display/virtio-gpu.c | 4 ++--2 files changed, 4 insertions(+), 4 deletions(-)hw/display/virtio-gpu- renamed from hw/display/virtio-gpu-virgl.c +0
-0
virgl.c
indexe60e1059df..6ebd9293e5100644hw/display/virtio-gpu-virgl.c +1
-1@@ -557,7 +557,7 @@ static voidvirgl_resource_attach_backing (VirtIOGPU *g, ret = virtio_gpu_create_mapping_iov(g, att_rb.nr_entries, sizeof(att_rb), cmd, NULL, &res_iovs, &res_niov); - if (ret != 0) { + if (ret < 0) { cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;return;
}hw/display/virtio-gpu-virgl.c +0
-0@@ -701,7 +701,7 @@ static voidvirgl_cmd_resource_create_blob (VirtIOGPU *g, ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), cmd, &res->base.addrs,
&res->base.iov, &res-Quoted 1 line
base.iov_cnt);
- if (ret != 0) {
+ if (ret < 0) {
cmd->error=VIRTIO_GPU_RESP_ERR_UNSPEC; return;
}hw/display/virtio-gpu.c +1
-1@@ -352,7 +352,7 @@ static voidvirtio_gpu_resource_create_blob (VirtIOGPU *g, ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), cmd, &res->addrs, &res->iov, &res->iov_cnt); - if (ret != 0) { + if (ret < 0) { cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
g_free(res);
return;hw/display/virtio-gpu.c +0
-0@@ -931,7 +931,7 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, ret = virtio_gpu_create_mapping_iov(g, ab.nr_entries, sizeof(ab), cmd, &res->addrs, &res->iov,Quoted 9 lines
Quoted 6 lines
hw/display/virtio-gpu.c +1
-1&res->iov_cnt); - if (ret != 0) { + if (ret < 0) { cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC; return;}
Reviewed-by Dmitry Osipenko <[email protected]>
Quoted 1 line
Really thanks for the review and patience.
There is a last word from Alex here, though likely the current version will be good to him, Thanks for the contribution.
Signature · 2 lines
Best regards, Dmitry
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
In reply to Honglei HuangQuoted 23 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()
Quoted 6 lines
Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>--- hw/display/virtio-gpu-virgl.c | 4 ++-- hw/display/virtio-gpu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Re: [v6 2/2] virtio-gpu: use consistent error checking for virtio_gpu_create_mapping_iov
Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Honglei Huang
Unify error checking style for
virtio_gpu_create_mapping_iov()across the codebase to improve consistency and readability.
virtio_gpu_create_mapping_iov()returns 0 on success and negative values on error. The original code used inconsistent patterns for checking errors:
- Some used 'if (ret != 0)' invirtio-gpu-virgl.candvirtio-gpu.c
- Some used 'CHECK(!ret, cmd)' invirtio-gpu-rutabaga.cFor if-statement checks, change to 'if (ret < 0)' which is the preferred QEMU coding convention for functions that return 0 on success and negative on error. This makes the return value convention immediately clear to code readers.
For CHECK macro usage in
virtio-gpu-rutabaga.c, keep the original 'CHECK(!ret, cmd)' pattern as it is more concise and consistent with other error checks in the same file.Updated locations:
-hw/display/virtio-gpu-virgl.c:virgl_resource_attach_backing()
-hw/display/virtio-gpu-virgl.c:virgl_cmd_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_create_blob()
-hw/display/virtio-gpu.c:virtio_gpu_resource_attach_backing()
Quoted 9 lines
Quoted 6 lines
Signed-off-by Honglei Huang <[email protected]>Reviewed-by Markus Armbruster <[email protected]>---
hw/display/virtio-gpu-virgl.c| 4 ++--
hw/display/virtio-gpu.c | 4 ++--2 files changed, 4 insertions(+), 4 deletions(-)Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Really thanks for the review.
Regards,
Honglei