@@ -82,29 +82,26 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
82
82
}
83
83
84
84
static unsigned int decode_compactedbits (unsigned int lobits ,
85
- unsigned int lomask ,
86
85
u8 * in , unsigned int pos , u8 * type )
87
86
{
88
87
const unsigned int v = get_unaligned_le32 (in + pos / 8 ) >> (pos & 7 );
89
- const unsigned int lo = v & lomask ;
88
+ const unsigned int lo = v & (( 1 << lobits ) - 1 ) ;
90
89
91
90
* type = (v >> lobits ) & 3 ;
92
91
return lo ;
93
92
}
94
93
95
- static int get_compacted_la_distance (unsigned int lclusterbits ,
94
+ static int get_compacted_la_distance (unsigned int lobits ,
96
95
unsigned int encodebits ,
97
96
unsigned int vcnt , u8 * in , int i )
98
97
{
99
- const unsigned int lomask = (1 << lclusterbits ) - 1 ;
100
98
unsigned int lo , d1 = 0 ;
101
99
u8 type ;
102
100
103
101
DBG_BUGON (i >= vcnt );
104
102
105
103
do {
106
- lo = decode_compactedbits (lclusterbits , lomask ,
107
- in , encodebits * i , & type );
104
+ lo = decode_compactedbits (lobits , in , encodebits * i , & type );
108
105
109
106
if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD )
110
107
return d1 ;
@@ -123,15 +120,14 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
123
120
{
124
121
struct erofs_inode * const vi = EROFS_I (m -> inode );
125
122
const unsigned int lclusterbits = vi -> z_logical_clusterbits ;
126
- const unsigned int lomask = (1 << lclusterbits ) - 1 ;
127
- unsigned int vcnt , base , lo , encodebits , nblk , eofs ;
123
+ unsigned int vcnt , base , lo , lobits , encodebits , nblk , eofs ;
128
124
int i ;
129
125
u8 * in , type ;
130
126
bool big_pcluster ;
131
127
132
128
if (1 << amortizedshift == 4 && lclusterbits <= 14 )
133
129
vcnt = 2 ;
134
- else if (1 << amortizedshift == 2 && lclusterbits = = 12 )
130
+ else if (1 << amortizedshift == 2 && lclusterbits < = 12 )
135
131
vcnt = 16 ;
136
132
else
137
133
return - EOPNOTSUPP ;
@@ -140,22 +136,22 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
140
136
m -> nextpackoff = round_down (pos , vcnt << amortizedshift ) +
141
137
(vcnt << amortizedshift );
142
138
big_pcluster = vi -> z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1 ;
139
+ lobits = max (lclusterbits , ilog2 (Z_EROFS_LI_D0_CBLKCNT ) + 1U );
143
140
encodebits = ((vcnt << amortizedshift ) - sizeof (__le32 )) * 8 / vcnt ;
144
141
eofs = erofs_blkoff (m -> inode -> i_sb , pos );
145
142
base = round_down (eofs , vcnt << amortizedshift );
146
143
in = m -> kaddr + base ;
147
144
148
145
i = (eofs - base ) >> amortizedshift ;
149
146
150
- lo = decode_compactedbits (lclusterbits , lomask ,
151
- in , encodebits * i , & type );
147
+ lo = decode_compactedbits (lobits , in , encodebits * i , & type );
152
148
m -> type = type ;
153
149
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD ) {
154
150
m -> clusterofs = 1 << lclusterbits ;
155
151
156
152
/* figure out lookahead_distance: delta[1] if needed */
157
153
if (lookahead )
158
- m -> delta [1 ] = get_compacted_la_distance (lclusterbits ,
154
+ m -> delta [1 ] = get_compacted_la_distance (lobits ,
159
155
encodebits , vcnt , in , i );
160
156
if (lo & Z_EROFS_LI_D0_CBLKCNT ) {
161
157
if (!big_pcluster ) {
@@ -174,8 +170,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
174
170
* of which lo saves delta[1] rather than delta[0].
175
171
* Hence, get delta[0] by the previous lcluster indirectly.
176
172
*/
177
- lo = decode_compactedbits (lclusterbits , lomask ,
178
- in , encodebits * (i - 1 ), & type );
173
+ lo = decode_compactedbits (lobits , in ,
174
+ encodebits * (i - 1 ), & type );
179
175
if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD )
180
176
lo = 0 ;
181
177
else if (lo & Z_EROFS_LI_D0_CBLKCNT )
@@ -190,8 +186,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
190
186
nblk = 1 ;
191
187
while (i > 0 ) {
192
188
-- i ;
193
- lo = decode_compactedbits (lclusterbits , lomask ,
194
- in , encodebits * i , & type );
189
+ lo = decode_compactedbits (lobits , in ,
190
+ encodebits * i , & type );
195
191
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD )
196
192
i -= lo ;
197
193
@@ -202,8 +198,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
202
198
nblk = 0 ;
203
199
while (i > 0 ) {
204
200
-- i ;
205
- lo = decode_compactedbits (lclusterbits , lomask ,
206
- in , encodebits * i , & type );
201
+ lo = decode_compactedbits (lobits , in ,
202
+ encodebits * i , & type );
207
203
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD ) {
208
204
if (lo & Z_EROFS_LI_D0_CBLKCNT ) {
209
205
-- i ;
0 commit comments