From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, yuanxzhang@fudan.edu.cn,
Xin Tan <tanxin.ctf@gmail.com>
Subject: Re: [PATCH] misc: sgi-gru: Convert from atomic_t to refcount_t on gru_thread_state->ts_refcnt
Date: Wed, 21 Jul 2021 13:51:56 +0200 [thread overview]
Message-ID: <YPgKXBTjgO6ko0qQ@kroah.com> (raw)
In-Reply-To: <1626517043-42696-1-git-send-email-xiyuyang19@fudan.edu.cn>
On Sat, Jul 17, 2021 at 06:17:22PM +0800, Xiyu Yang wrote:
> refcount_t type and corresponding API can protect refcounters from
> accidental underflow and overflow and further use-after-free situations.
>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
> drivers/misc/sgi-gru/grumain.c | 6 +++---
> drivers/misc/sgi-gru/grutables.h | 3 ++-
> 2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c
> index 40ac59dd018c..9afda47efbf2 100644
> --- a/drivers/misc/sgi-gru/grumain.c
> +++ b/drivers/misc/sgi-gru/grumain.c
> @@ -282,7 +282,7 @@ static void gru_unload_mm_tracker(struct gru_state *gru,
> */
> void gts_drop(struct gru_thread_state *gts)
> {
> - if (gts && atomic_dec_return(>s->ts_refcnt) == 0) {
> + if (gts && refcount_dec_and_test(>s->ts_refcnt)) {
> if (gts->ts_gms)
> gru_drop_mmu_notifier(gts->ts_gms);
> kfree(gts);
Related to this, shouldn't this really be a 'struct kref' instead of
hand-creating the exact same logic?
Want to make that change on top of this one?
thanks,
greg k-h
prev parent reply other threads:[~2021-07-21 11:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-17 10:17 [PATCH] misc: sgi-gru: Convert from atomic_t to refcount_t on gru_thread_state->ts_refcnt Xiyu Yang
2021-07-19 14:51 ` Dimitri Sivanich
2021-07-21 11:51 ` Greg Kroah-Hartman [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=YPgKXBTjgO6ko0qQ@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=arnd@arndb.de \
--cc=dimitri.sivanich@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tanxin.ctf@gmail.com \
--cc=xiyuyang19@fudan.edu.cn \
--cc=yuanxzhang@fudan.edu.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;
as well as URLs for NNTP newsgroup(s).