@@ -1601,23 +1601,22 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1601
1601
int flags , BdrvCheckMode fix , bool active )
1602
1602
{
1603
1603
BDRVQcow2State * s = bs -> opaque ;
1604
- uint64_t * l2_table , l2_entry ;
1604
+ uint64_t l2_entry ;
1605
1605
uint64_t next_contiguous_offset = 0 ;
1606
- int i , l2_size , nb_csectors , ret ;
1606
+ int i , nb_csectors , ret ;
1607
+ size_t l2_size_bytes = s -> l2_size * l2_entry_size (s );
1608
+ g_autofree uint64_t * l2_table = g_malloc (l2_size_bytes );
1607
1609
1608
1610
/* Read L2 table from disk */
1609
- l2_size = s -> l2_size * l2_entry_size (s );
1610
- l2_table = g_malloc (l2_size );
1611
-
1612
- ret = bdrv_pread (bs -> file , l2_offset , l2_table , l2_size );
1611
+ ret = bdrv_pread (bs -> file , l2_offset , l2_table , l2_size_bytes );
1613
1612
if (ret < 0 ) {
1614
1613
fprintf (stderr , "ERROR: I/O error in check_refcounts_l2\n" );
1615
1614
res -> check_errors ++ ;
1616
- goto fail ;
1615
+ return ret ;
1617
1616
}
1618
1617
1619
1618
/* Do the actual checks */
1620
- for (i = 0 ; i < s -> l2_size ; i ++ ) {
1619
+ for (i = 0 ; i < s -> l2_size ; i ++ ) {
1621
1620
l2_entry = get_l2_entry (s , l2_table , i );
1622
1621
1623
1622
switch (qcow2_get_cluster_type (bs , l2_entry )) {
@@ -1647,14 +1646,15 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1647
1646
l2_entry & QCOW2_COMPRESSED_SECTOR_MASK ,
1648
1647
nb_csectors * QCOW2_COMPRESSED_SECTOR_SIZE );
1649
1648
if (ret < 0 ) {
1650
- goto fail ;
1649
+ return ret ;
1651
1650
}
1652
1651
1653
1652
if (flags & CHECK_FRAG_INFO ) {
1654
1653
res -> bfi .allocated_clusters ++ ;
1655
1654
res -> bfi .compressed_clusters ++ ;
1656
1655
1657
- /* Compressed clusters are fragmented by nature. Since they
1656
+ /*
1657
+ * Compressed clusters are fragmented by nature. Since they
1658
1658
* take up sub-sector space but we only have sector granularity
1659
1659
* I/O we need to re-read the same sectors even for adjacent
1660
1660
* compressed clusters.
@@ -1700,9 +1700,11 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1700
1700
if (ret < 0 ) {
1701
1701
fprintf (stderr , "ERROR: Overlap check failed\n" );
1702
1702
res -> check_errors ++ ;
1703
- /* Something is seriously wrong, so abort checking
1704
- * this L2 table */
1705
- goto fail ;
1703
+ /*
1704
+ * Something is seriously wrong, so abort checking
1705
+ * this L2 table.
1706
+ */
1707
+ return ret ;
1706
1708
}
1707
1709
1708
1710
ret = bdrv_pwrite_sync (bs -> file , l2e_offset ,
@@ -1712,13 +1714,17 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1712
1714
fprintf (stderr , "ERROR: Failed to overwrite L2 "
1713
1715
"table entry: %s\n" , strerror (- ret ));
1714
1716
res -> check_errors ++ ;
1715
- /* Do not abort, continue checking the rest of this
1716
- * L2 table's entries */
1717
+ /*
1718
+ * Do not abort, continue checking the rest of this
1719
+ * L2 table's entries.
1720
+ */
1717
1721
} else {
1718
1722
res -> corruptions -- ;
1719
1723
res -> corruptions_fixed ++ ;
1720
- /* Skip marking the cluster as used
1721
- * (it is unused now) */
1724
+ /*
1725
+ * Skip marking the cluster as used
1726
+ * (it is unused now).
1727
+ */
1722
1728
continue ;
1723
1729
}
1724
1730
}
@@ -1743,7 +1749,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1743
1749
refcount_table_size ,
1744
1750
offset , s -> cluster_size );
1745
1751
if (ret < 0 ) {
1746
- goto fail ;
1752
+ return ret ;
1747
1753
}
1748
1754
}
1749
1755
break ;
@@ -1758,12 +1764,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
1758
1764
}
1759
1765
}
1760
1766
1761
- g_free (l2_table );
1762
1767
return 0 ;
1763
-
1764
- fail :
1765
- g_free (l2_table );
1766
- return ret ;
1767
1768
}
1768
1769
1769
1770
/*
0 commit comments