[PATCH] storage_util: Fix the false condition in virStorageBackendDeviceIsEmpty

In virStorageBackendDeviceIsEmpty, the return value for virStorageBackendPARTEDValidLabel is -1 or 0. That makes the later condition 'ret == -2' make always false. Remove the always false condition. Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE. Fixes: https://gitlab.com/libvirt/libvirt/-/issues/576 Signed-off-by: Han Han <hhan@redhat.com> --- src/storage/storage_util.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7bf815d978..82bcfa5838 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3352,15 +3352,9 @@ virStorageBackendDeviceIsEmpty(const char *devpath, writelabel)) == -2) ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel); - if (ret == -2 && !writelabel) + if (!writelabel) ret = 0; - if (ret == -2) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("Unable to probe '%1$s' for existing data, forced overwrite is necessary"), - devpath); - } - return ret == 0; } -- 2.43.0

On a Wednesday in 2023, Han Han wrote:
In virStorageBackendDeviceIsEmpty, the return value for virStorageBackendPARTEDValidLabel is -1 or 0. That makes the later condition 'ret == -2' make always false. Remove the always false condition.
Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
As Michal pointed out in the linked issue, the functions return -2 if the functionality was not compiled in. Jano
Signed-off-by: Han Han <hhan@redhat.com> --- src/storage/storage_util.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
participants (2)
-
Han Han
-
Ján Tomko