@@ -1953,6 +1953,7 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
1953
1953
struct extent_position nepos ;
1954
1954
struct kernel_lb_addr neloc ;
1955
1955
int ver , adsize ;
1956
+ int err = 0 ;
1956
1957
1957
1958
if (UDF_I (inode )-> i_alloc_type == ICBTAG_FLAG_AD_SHORT )
1958
1959
adsize = sizeof (struct short_ad );
@@ -1997,10 +1998,12 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
1997
1998
if (epos -> offset + adsize > sb -> s_blocksize ) {
1998
1999
struct kernel_lb_addr cp_loc ;
1999
2000
uint32_t cp_len ;
2000
- int cp_type ;
2001
+ int8_t cp_type ;
2001
2002
2002
2003
epos -> offset -= adsize ;
2003
- cp_type = udf_current_aext (inode , epos , & cp_loc , & cp_len , 0 );
2004
+ err = udf_current_aext (inode , epos , & cp_loc , & cp_len , & cp_type , 0 );
2005
+ if (err <= 0 )
2006
+ goto err_out ;
2004
2007
cp_len |= ((uint32_t )cp_type ) << 30 ;
2005
2008
2006
2009
__udf_add_aext (inode , & nepos , & cp_loc , cp_len , 1 );
@@ -2015,6 +2018,9 @@ int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
2015
2018
* epos = nepos ;
2016
2019
2017
2020
return 0 ;
2021
+ err_out :
2022
+ brelse (bh );
2023
+ return err ;
2018
2024
}
2019
2025
2020
2026
/*
@@ -2165,9 +2171,12 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
2165
2171
{
2166
2172
int8_t etype ;
2167
2173
unsigned int indirections = 0 ;
2174
+ int ret = 0 ;
2168
2175
2169
- while ((etype = udf_current_aext (inode , epos , eloc , elen , inc )) ==
2170
- (EXT_NEXT_EXTENT_ALLOCDESCS >> 30 )) {
2176
+ while ((ret = udf_current_aext (inode , epos , eloc , elen ,
2177
+ & etype , inc )) > 0 ) {
2178
+ if (etype != (EXT_NEXT_EXTENT_ALLOCDESCS >> 30 ))
2179
+ break ;
2171
2180
udf_pblk_t block ;
2172
2181
2173
2182
if (++ indirections > UDF_MAX_INDIR_EXTS ) {
@@ -2188,14 +2197,17 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
2188
2197
}
2189
2198
}
2190
2199
2191
- return etype ;
2200
+ return ret > 0 ? etype : -1 ;
2192
2201
}
2193
2202
2194
- int8_t udf_current_aext (struct inode * inode , struct extent_position * epos ,
2195
- struct kernel_lb_addr * eloc , uint32_t * elen , int inc )
2203
+ /*
2204
+ * Returns 1 on success, -errno on error, 0 on hit EOF.
2205
+ */
2206
+ int udf_current_aext (struct inode * inode , struct extent_position * epos ,
2207
+ struct kernel_lb_addr * eloc , uint32_t * elen , int8_t * etype ,
2208
+ int inc )
2196
2209
{
2197
2210
int alen ;
2198
- int8_t etype ;
2199
2211
uint8_t * ptr ;
2200
2212
struct short_ad * sad ;
2201
2213
struct long_ad * lad ;
@@ -2222,8 +2234,8 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
2222
2234
case ICBTAG_FLAG_AD_SHORT :
2223
2235
sad = udf_get_fileshortad (ptr , alen , & epos -> offset , inc );
2224
2236
if (!sad )
2225
- return -1 ;
2226
- etype = le32_to_cpu (sad -> extLength ) >> 30 ;
2237
+ return 0 ;
2238
+ * etype = le32_to_cpu (sad -> extLength ) >> 30 ;
2227
2239
eloc -> logicalBlockNum = le32_to_cpu (sad -> extPosition );
2228
2240
eloc -> partitionReferenceNum =
2229
2241
iinfo -> i_location .partitionReferenceNum ;
@@ -2232,17 +2244,17 @@ int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
2232
2244
case ICBTAG_FLAG_AD_LONG :
2233
2245
lad = udf_get_filelongad (ptr , alen , & epos -> offset , inc );
2234
2246
if (!lad )
2235
- return -1 ;
2236
- etype = le32_to_cpu (lad -> extLength ) >> 30 ;
2247
+ return 0 ;
2248
+ * etype = le32_to_cpu (lad -> extLength ) >> 30 ;
2237
2249
* eloc = lelb_to_cpu (lad -> extLocation );
2238
2250
* elen = le32_to_cpu (lad -> extLength ) & UDF_EXTENT_LENGTH_MASK ;
2239
2251
break ;
2240
2252
default :
2241
2253
udf_debug ("alloc_type = %u unsupported\n" , iinfo -> i_alloc_type );
2242
- return -1 ;
2254
+ return - EINVAL ;
2243
2255
}
2244
2256
2245
- return etype ;
2257
+ return 1 ;
2246
2258
}
2247
2259
2248
2260
static int udf_insert_aext (struct inode * inode , struct extent_position epos ,
0 commit comments