perf dso: Convert dso.refcnt from atomic_t to refcount_t

The refcount_t type and corresponding API should be used instead of atomic_t
when the variable is used as a reference counter.

This allows to avoid accidental refcounter overflows that might lead to
use-after-free situations.

Signed-off-by: Elena Reshetova <[email protected]>
Signed-off-by: David Windsor <[email protected]>
Signed-off-by: Hans Liljestrand <[email protected]>
Signed-off-by: Kees Kook <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: David Windsor <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Hans Liljestrand <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kees Kook <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Matija Glavinic Pecotic <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
This commit is contained in:
Elena Reshetova 2017-02-21 17:34:58 +02:00 • committed by Arnaldo Carvalho de Melo
commit 7100810a75
2 changed files with 5 additions and 5 deletions

View file

@ -1109,7 +1109,7 @@ struct dso *dso__new(const char *name)
INIT_LIST_HEAD(&dso->node);
INIT_LIST_HEAD(&dso->data.open_entry);
pthread_mutex_init(&dso->lock, NULL);
atomic_set(&dso->refcnt, 1);
refcount_set(&dso->refcnt, 1);
}
return dso;
@ -1147,13 +1147,13 @@ void dso__delete(struct dso *dso)
struct dso *dso__get(struct dso *dso)
{
if (dso)
atomic_inc(&dso->refcnt);
refcount_inc(&dso->refcnt);
return dso;
}
void dso__put(struct dso *dso)
{
if (dso && atomic_dec_and_test(&dso->refcnt))
if (dso && refcount_dec_and_test(&dso->refcnt))
dso__delete(dso);
}

View file

@ -1,7 +1,7 @@
#ifndef __PERF_DSO
#define __PERF_DSO
#include <linux/atomic.h>
#include <linux/refcount.h>
#include <linux/types.h>
#include <linux/rbtree.h>
#include <sys/types.h>
@ -187,7 +187,7 @@ struct dso {
void *priv;
u64 db_id;
};
atomic_t refcnt;
refcount_t refcnt;
char name[0];
};