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.
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Yazen Ghannam <Yazen.Ghannam@amd.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Link: http://lkml.kernel.org/r/1492695536-5947-1-git-send-email-elena.reshetova@intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <linux/pci.h>
+#include <linux/refcount.h>
struct amd_nb_bus_dev_range {
u8 bus;
struct amd_nb_bus_dev_range {
u8 bus;
struct threshold_block *blocks;
/* initialized to the number of CPUs on the node sharing this bank */
struct threshold_block *blocks;
/* initialized to the number of CPUs on the node sharing this bank */
};
struct amd_northbridge {
};
struct amd_northbridge {
goto out;
per_cpu(threshold_banks, cpu)[bank] = b;
goto out;
per_cpu(threshold_banks, cpu)[bank] = b;
+ refcount_inc(&b->cpus);
err = __threshold_add_blocks(b);
err = __threshold_add_blocks(b);
per_cpu(threshold_banks, cpu)[bank] = b;
if (is_shared_bank(bank)) {
per_cpu(threshold_banks, cpu)[bank] = b;
if (is_shared_bank(bank)) {
- atomic_set(&b->cpus, 1);
+ refcount_set(&b->cpus, 1);
/* nb is already initialized, see above */
if (nb) {
/* nb is already initialized, see above */
if (nb) {
goto free_out;
if (is_shared_bank(bank)) {
goto free_out;
if (is_shared_bank(bank)) {
- if (!atomic_dec_and_test(&b->cpus)) {
+ if (!refcount_dec_and_test(&b->cpus)) {
__threshold_remove_blocks(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
return;
__threshold_remove_blocks(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
return;