]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage/util: replace unnecessary while loop by if
authorJiang Jiacheng <jiangjiacheng@huawei.com>
Thu, 5 Jan 2023 11:51:08 +0000 (19:51 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 Jan 2023 09:22:39 +0000 (10:22 +0100)
These while loops exit directly due to break after entering.
Use if instead of these while loops.

Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_util.c
src/util/virutil.c

index 3871718b09036ec2843d250fea7f9abed5280bcf..520fdd03d0340e09c02f55e145427bf0385d3642 100644 (file)
@@ -3784,12 +3784,10 @@ getNewStyleBlockDevice(const char *lun_path,
     if (virDirOpen(&block_dir, block_path) < 0)
         return -1;
 
-    while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
+    if ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
         *block_device = g_strdup(block_dirent->d_name);
 
         VIR_DEBUG("Block device is '%s'", *block_device);
-
-        break;
     }
 
     if (direrr < 0)
index 7e246d22d1d72487441f87ce41df347890b63a90..ddc66001cb4f97cbafdcd553ee31f057f8d5ead7 100644 (file)
@@ -1432,15 +1432,11 @@ virHostHasIOMMU(void)
 {
     g_autoptr(DIR) iommuDir = NULL;
     struct dirent *iommuGroup = NULL;
-    int direrr;
 
     if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
         return false;
 
-    while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0)
-        break;
-
-    if (direrr < 0 || !iommuGroup)
+    if (virDirRead(iommuDir, &iommuGroup, NULL) < 0 || !iommuGroup)
         return false;
 
     return true;