Skip to content

Commit 4ab64e3

Browse files
Bjoern A. ZeebBjoern A. Zeeb
authored andcommitted
LinuxKPI: devres: divorce dem_kfree from lkpi_devm_kmalloc_release
dem_kfree() is called from all over the place and should actually do something; contrary to lkpi_devm_kmalloc_release() it can also take a const void *. We have to __DECONST() that though as the entire devres framework does otherwise not take a const argument. This was discovered during the rtw89 upadte to 6.16. Sponsored by: The FreeBSD Foundation (initially) MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52082
1 parent 2a44e10 commit 4ab64e3

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

sys/compat/linuxkpi/common/include/linux/device.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2010 Panasas, Inc.
55
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
66
* All rights reserved.
7-
* Copyright (c) 2021-2022 The FreeBSD Foundation
7+
* Copyright (c) 2021-2025 The FreeBSD Foundation
88
*
99
* Portions of this software were developed by Björn Zeeb
1010
* under sponsorship from the FreeBSD Foundation.
@@ -284,7 +284,8 @@ int lkpi_devres_destroy(struct device *, void(*release)(struct device *, void *)
284284
void lkpi_devres_release_free_list(struct device *);
285285
void lkpi_devres_unlink(struct device *, void *);
286286
void lkpi_devm_kmalloc_release(struct device *, void *);
287-
#define devm_kfree(_d, _p) lkpi_devm_kmalloc_release(_d, _p)
287+
void lkpi_devm_kfree(struct device *, const void *);
288+
#define devm_kfree(_d, _p) lkpi_devm_kfree(_d, _p)
288289

289290
static inline const char *
290291
dev_driver_string(const struct device *dev)

sys/compat/linuxkpi/common/src/linux_devres.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-
22
* SPDX-License-Identifier: BSD-2-Clause
33
*
4-
* Copyright (c) 2020-2021 The FreeBSD Foundation
4+
* Copyright (c) 2020-2025 The FreeBSD Foundation
55
*
66
* This software was developed by Bj\xc3\xb6rn Zeeb under sponsorship from
77
* the FreeBSD Foundation.
@@ -223,6 +223,30 @@ lkpi_devm_kmalloc_release(struct device *dev __unused, void *p __unused)
223223
/* Nothing to do. Freed with the devres. */
224224
}
225225

226+
static int
227+
lkpi_devm_kmalloc_match(struct device *dev __unused, void *p, void *mp)
228+
{
229+
return (p == mp);
230+
}
231+
232+
void
233+
lkpi_devm_kfree(struct device *dev, const void *p)
234+
{
235+
void *mp;
236+
int error;
237+
238+
if (p == NULL)
239+
return;
240+
241+
/* I assume Linux simply casts the const away... */
242+
mp = __DECONST(void *, p);
243+
error = lkpi_devres_destroy(dev, lkpi_devm_kmalloc_release,
244+
lkpi_devm_kmalloc_match, mp);
245+
if (error != 0)
246+
dev_warn(dev, "%s: lkpi_devres_destroy failed with %d\n",
247+
__func__, error);
248+
}
249+
226250
struct devres_action {
227251
void *data;
228252
void (*action)(void *);

0 commit comments

Comments
 (0)