Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xfs: remove xfs_attr_leaf_hasname

The calling convention of xfs_attr_leaf_hasname() is problematic, because
it returns a NULL buffer when xfs_attr3_leaf_read fails, a valid buffer
when xfs_attr3_leaf_lookup_int returns -ENOATTR or -EEXIST, and a
non-NULL buffer pointer for an already released buffer when
xfs_attr3_leaf_lookup_int fails with other error values.

Fix this by simply open coding xfs_attr_leaf_hasname in the callers, so
that the buffer release code is done by each caller of
xfs_attr3_leaf_read.

Cc: stable@vger.kernel.org # v5.19+
Fixes: 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")
Reported-by: Mark Tinguely <mark.tinguely@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>

authored by

Christoph Hellwig and committed by
Carlos Maiolino
3a65ea76 f39854a3

+24 -51
+24 -51
fs/xfs/libxfs/xfs_attr.c
··· 50 50 */ 51 51 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); 52 52 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); 53 - STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); 54 53 55 54 /* 56 55 * Internal routines when attribute list is more than one block. ··· 978 979 return error; 979 980 980 981 if (xfs_attr_is_leaf(dp)) { 981 - error = xfs_attr_leaf_hasname(args, &bp); 982 - 983 - if (bp) 984 - xfs_trans_brelse(args->trans, bp); 985 - 982 + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 983 + 0, &bp); 984 + if (error) 985 + return error; 986 + error = xfs_attr3_leaf_lookup_int(bp, args); 987 + xfs_trans_brelse(args->trans, bp); 986 988 return error; 987 989 } 988 990 ··· 1223 1223 *========================================================================*/ 1224 1224 1225 1225 /* 1226 - * Return EEXIST if attr is found, or ENOATTR if not 1227 - */ 1228 - STATIC int 1229 - xfs_attr_leaf_hasname( 1230 - struct xfs_da_args *args, 1231 - struct xfs_buf **bp) 1232 - { 1233 - int error = 0; 1234 - 1235 - error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, bp); 1236 - if (error) 1237 - return error; 1238 - 1239 - error = xfs_attr3_leaf_lookup_int(*bp, args); 1240 - if (error != -ENOATTR && error != -EEXIST) 1241 - xfs_trans_brelse(args->trans, *bp); 1242 - 1243 - return error; 1244 - } 1245 - 1246 - /* 1247 1226 * Remove a name from the leaf attribute list structure 1248 1227 * 1249 1228 * This leaf block cannot have a "remote" value, we only call this routine ··· 1232 1253 xfs_attr_leaf_removename( 1233 1254 struct xfs_da_args *args) 1234 1255 { 1235 - struct xfs_inode *dp; 1236 - struct xfs_buf *bp; 1256 + struct xfs_inode *dp = args->dp; 1237 1257 int error, forkoff; 1258 + struct xfs_buf *bp; 1238 1259 1239 1260 trace_xfs_attr_leaf_removename(args); 1240 1261 1241 - /* 1242 - * Remove the attribute. 1243 - */ 1244 - dp = args->dp; 1245 - 1246 - error = xfs_attr_leaf_hasname(args, &bp); 1247 - if (error == -ENOATTR) { 1262 + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp); 1263 + if (error) 1264 + return error; 1265 + error = xfs_attr3_leaf_lookup_int(bp, args); 1266 + if (error != -EEXIST) { 1248 1267 xfs_trans_brelse(args->trans, bp); 1249 - if (args->op_flags & XFS_DA_OP_RECOVERY) 1268 + if (error == -ENOATTR && (args->op_flags & XFS_DA_OP_RECOVERY)) 1250 1269 return 0; 1251 1270 return error; 1252 - } else if (error != -EEXIST) 1253 - return error; 1271 + } 1254 1272 1255 1273 xfs_attr3_leaf_remove(bp, args); 1256 1274 ··· 1271 1295 * Returns 0 on successful retrieval, otherwise an error. 1272 1296 */ 1273 1297 STATIC int 1274 - xfs_attr_leaf_get(xfs_da_args_t *args) 1298 + xfs_attr_leaf_get( 1299 + struct xfs_da_args *args) 1275 1300 { 1276 - struct xfs_buf *bp; 1277 - int error; 1301 + struct xfs_buf *bp; 1302 + int error; 1278 1303 1279 1304 trace_xfs_attr_leaf_get(args); 1280 1305 1281 - error = xfs_attr_leaf_hasname(args, &bp); 1282 - 1283 - if (error == -ENOATTR) { 1284 - xfs_trans_brelse(args->trans, bp); 1306 + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp); 1307 + if (error) 1285 1308 return error; 1286 - } else if (error != -EEXIST) 1287 - return error; 1288 - 1289 - 1290 - error = xfs_attr3_leaf_getvalue(bp, args); 1309 + error = xfs_attr3_leaf_lookup_int(bp, args); 1310 + if (error == -EEXIST) 1311 + error = xfs_attr3_leaf_getvalue(bp, args); 1291 1312 xfs_trans_brelse(args->trans, bp); 1292 1313 return error; 1293 1314 }