Skip to content

Commit 70b95cb

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: free the item in xfs_mru_cache_insert on failure
Call the provided free_func when xfs_mru_cache_insert as that's what the callers need to do anyway. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Hans Holmberg <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 1c7161e commit 70b95cb

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

fs/xfs/xfs_filestream.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,26 +304,19 @@ xfs_filestream_create_association(
304304
* for us, so all we need to do here is take another active reference to
305305
* the perag for the cached association.
306306
*
307-
* If we fail to store the association, we need to drop the fstrms
308-
* counter as well as drop the perag reference we take here for the
309-
* item. We do not need to return an error for this failure - as long as
310-
* we return a referenced AG, the allocation can still go ahead just
311-
* fine.
307+
* If we fail to store the association, we do not need to return an
308+
* error for this failure - as long as we return a referenced AG, the
309+
* allocation can still go ahead just fine.
312310
*/
313311
item = kmalloc(sizeof(*item), GFP_KERNEL | __GFP_RETRY_MAYFAIL);
314312
if (!item)
315313
goto out_put_fstrms;
316314

317315
atomic_inc(&pag_group(args->pag)->xg_active_ref);
318316
item->pag = args->pag;
319-
error = xfs_mru_cache_insert(mp->m_filestream, pino, &item->mru);
320-
if (error)
321-
goto out_free_item;
317+
xfs_mru_cache_insert(mp->m_filestream, pino, &item->mru);
322318
return 0;
323319

324-
out_free_item:
325-
xfs_perag_rele(item->pag);
326-
kfree(item);
327320
out_put_fstrms:
328321
atomic_dec(&args->pag->pagf_fstrms);
329322
return 0;

fs/xfs/xfs_mru_cache.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,24 @@ xfs_mru_cache_destroy(
414414
* To insert an element, call xfs_mru_cache_insert() with the data store, the
415415
* element's key and the client data pointer. This function returns 0 on
416416
* success or ENOMEM if memory for the data element couldn't be allocated.
417+
*
418+
* The passed in elem is freed through the per-cache free_func on failure.
417419
*/
418420
int
419421
xfs_mru_cache_insert(
420422
struct xfs_mru_cache *mru,
421423
unsigned long key,
422424
struct xfs_mru_cache_elem *elem)
423425
{
424-
int error;
426+
int error = -EINVAL;
425427

426428
ASSERT(mru && mru->lists);
427429
if (!mru || !mru->lists)
428-
return -EINVAL;
430+
goto out_free;
429431

432+
error = -ENOMEM;
430433
if (radix_tree_preload(GFP_KERNEL))
431-
return -ENOMEM;
434+
goto out_free;
432435

433436
INIT_LIST_HEAD(&elem->list_node);
434437
elem->key = key;
@@ -440,6 +443,12 @@ xfs_mru_cache_insert(
440443
_xfs_mru_cache_list_insert(mru, elem);
441444
spin_unlock(&mru->lock);
442445

446+
if (error)
447+
goto out_free;
448+
return 0;
449+
450+
out_free:
451+
mru->free_func(mru->data, elem);
443452
return error;
444453
}
445454

0 commit comments

Comments
 (0)