public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Pei Xiao <xiaopei01@kylinos.cn>
Cc: cem@kernel.org, linux-xfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel test robot <lkp@intel.com>
Subject: Re: [PATCH] xfs: Use refcount_t instead of atomic_t for xmi_refcount
Date: Mon, 6 Jan 2025 11:51:51 -0800	[thread overview]
Message-ID: <20250106195151.GJ6174@frogsfrogsfrogs> (raw)
In-Reply-To: <4236d961cf3dd2413cebd56619d0f5927c8e749a.1735542858.git.xiaopei01@kylinos.cn>

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
> 
> 

      reply	other threads:[~2025-01-06 19:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250106195151.GJ6174@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=cem@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=xiaopei01@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox