linux_xa: Delete and replace collision in xa_store as intended.
Don't free the colliding node that's still in the tree. Noted by rjs@.
This commit is contained in:
parent
48e3cda1b4
commit
4efeea51c6
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: linux_xa.c,v 1.3 2021/12/19 12:05:25 riastradh Exp $ */
|
/* $NetBSD: linux_xa.c,v 1.4 2024/05/22 15:59:25 riastradh Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2021 The NetBSD Foundation, Inc.
|
* Copyright (c) 2021 The NetBSD Foundation, Inc.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: linux_xa.c,v 1.3 2021/12/19 12:05:25 riastradh Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: linux_xa.c,v 1.4 2024/05/22 15:59:25 riastradh Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a lame-o implementation of the Linux xarray data type, which
|
* This is a lame-o implementation of the Linux xarray data type, which
|
||||||
|
@ -124,7 +124,7 @@ xa_load(struct xarray *xa, unsigned long key)
|
||||||
void *
|
void *
|
||||||
xa_store(struct xarray *xa, unsigned long key, void *datum, gfp_t gfp)
|
xa_store(struct xarray *xa, unsigned long key, void *datum, gfp_t gfp)
|
||||||
{
|
{
|
||||||
struct node *n, *collision;
|
struct node *n, *collision, *recollision;
|
||||||
|
|
||||||
KASSERT(datum != NULL);
|
KASSERT(datum != NULL);
|
||||||
KASSERT(((uintptr_t)datum & 0x3) == 0);
|
KASSERT(((uintptr_t)datum & 0x3) == 0);
|
||||||
|
@ -137,6 +137,11 @@ xa_store(struct xarray *xa, unsigned long key, void *datum, gfp_t gfp)
|
||||||
|
|
||||||
mutex_enter(&xa->xa_lock);
|
mutex_enter(&xa->xa_lock);
|
||||||
collision = rb_tree_insert_node(&xa->xa_tree, n);
|
collision = rb_tree_insert_node(&xa->xa_tree, n);
|
||||||
|
if (collision != n) {
|
||||||
|
rb_tree_remove_node(&xa->xa_tree, n);
|
||||||
|
recollision = rb_tree_insert_node(&xa->xa_tree, n);
|
||||||
|
KASSERT(recollision == n);
|
||||||
|
}
|
||||||
mutex_exit(&xa->xa_lock);
|
mutex_exit(&xa->xa_lock);
|
||||||
|
|
||||||
if (collision != n) {
|
if (collision != n) {
|
||||||
|
|
Loading…
Reference in New Issue