[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250106195151.GJ6174@frogsfrogsfrogs>
Date: Mon, 6 Jan 2025 11:51:51 -0800
From: "Darrick J. Wong" <djwong@...nel.org>
To: Pei Xiao <xiaopei01@...inos.cn>
Cc: cem@...nel.org, linux-xfs@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel test robot <lkp@...el.com>
Subject: Re: [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount
On Mon, Dec 30, 2024 at 03:18:16PM +0800, Pei Xiao wrote:
> Use an API that resembles more the actual use of xmi_refcount.
>
> Found by cocci:
> fs/xfs/xfs_exchmaps_item.c:57:5-24: WARNING: atomic_dec_and_test
> variation before object free at line 58.
>
> Fixes: 6c08f434bd33 ("xfs: introduce a file mapping exchange log intent item")
> Reported-by: kernel test robot <lkp@...el.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412260634.uSDUNyYS-lkp@intel.com/
> Signed-off-by: Pei Xiao <xiaopei01@...inos.cn>
What has changed since
https://lore.kernel.org/linux-xfs/1508497678-10508-1-git-send-email-elena.reshetova@intel.com/
and if something has, why wouldn't you apply atomic_t -> refcount_t for
/all/ the log intent item types?
--D
> ---
> fs/xfs/xfs_exchmaps_item.c | 6 +++---
> fs/xfs/xfs_exchmaps_item.h | 2 +-
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_exchmaps_item.c b/fs/xfs/xfs_exchmaps_item.c
> index 264a121c5e16..5975a16c54e3 100644
> --- a/fs/xfs/xfs_exchmaps_item.c
> +++ b/fs/xfs/xfs_exchmaps_item.c
> @@ -57,8 +57,8 @@ STATIC void
> xfs_xmi_release(
> struct xfs_xmi_log_item *xmi_lip)
> {
> - ASSERT(atomic_read(&xmi_lip->xmi_refcount) > 0);
> - if (atomic_dec_and_test(&xmi_lip->xmi_refcount)) {
> + ASSERT(refcount_read(&xmi_lip->xmi_refcount) > 0);
> + if (refcount_dec_and_test(&xmi_lip->xmi_refcount)) {
> xfs_trans_ail_delete(&xmi_lip->xmi_item, 0);
> xfs_xmi_item_free(xmi_lip);
> }
> @@ -138,7 +138,7 @@ xfs_xmi_init(
>
> xfs_log_item_init(mp, &xmi_lip->xmi_item, XFS_LI_XMI, &xfs_xmi_item_ops);
> xmi_lip->xmi_format.xmi_id = (uintptr_t)(void *)xmi_lip;
> - atomic_set(&xmi_lip->xmi_refcount, 2);
> + refcount_set(&xmi_lip->xmi_refcount, 2);
>
> return xmi_lip;
> }
> diff --git a/fs/xfs/xfs_exchmaps_item.h b/fs/xfs/xfs_exchmaps_item.h
> index efa368d25d09..b8be3bca3155 100644
> --- a/fs/xfs/xfs_exchmaps_item.h
> +++ b/fs/xfs/xfs_exchmaps_item.h
> @@ -38,7 +38,7 @@ struct kmem_cache;
> */
> struct xfs_xmi_log_item {
> struct xfs_log_item xmi_item;
> - atomic_t xmi_refcount;
> + refcount_t xmi_refcount;
> struct xfs_xmi_log_format xmi_format;
> };
>
> --
> 2.25.1
>
>
Powered by blists - more mailing lists