lkml.org 
[lkml]   [2021]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] misc: sgi-gru: Convert from atomic_t to refcount_t on gru_thread_state->ts_refcnt
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(&gts->ts_refcnt) == 0) {
> + if (gts && refcount_dec_and_test(&gts->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

\
 
 \ /
  Last update: 2021-07-21 13:58    [W:0.356 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site