* [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount
@ 2024-12-30 7:18 Pei Xiao
2025-01-06 19:51 ` Darrick J. Wong
0 siblings, 1 reply; 2+ messages in thread
From: Pei Xiao @ 2024-12-30 7:18 UTC (permalink / raw)
To: cem, djwong, linux-xfs, linux-kernel; +Cc: Pei Xiao, kernel test robot
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@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412260634.uSDUNyYS-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount
2024-12-30 7:18 [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount Pei Xiao
@ 2025-01-06 19:51 ` Darrick J. Wong
0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2025-01-06 19:51 UTC (permalink / raw)
To: Pei Xiao; +Cc: cem, linux-xfs, linux-kernel, kernel test robot
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@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412260634.uSDUNyYS-lkp@intel.com/
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.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
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-06 19:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-30 7:18 [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount Pei Xiao
2025-01-06 19:51 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox