The branch stable/15 has been updated by bz:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f20a09e161f07874c3a01b1579e8a5d2356df8ce

commit f20a09e161f07874c3a01b1579e8a5d2356df8ce
Author:     Bjoern A. Zeeb <b...@freebsd.org>
AuthorDate: 2025-09-04 20:28:18 +0000
Commit:     Bjoern A. Zeeb <b...@freebsd.org>
CommitDate: 2025-09-15 14:53:01 +0000

    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)
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52082
    
    (cherry picked from commit 4ab64e34911ab06e567caaf07ed18f7770a61cc8)
---
 sys/compat/linuxkpi/common/include/linux/device.h |  5 +++--
 sys/compat/linuxkpi/common/src/linux_devres.c     | 26 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/device.h 
b/sys/compat/linuxkpi/common/include/linux/device.h
index 2556b0c45e49..7dd6340746d2 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -4,7 +4,7 @@
  * Copyright (c) 2010 Panasas, Inc.
  * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
  * All rights reserved.
- * Copyright (c) 2021-2022 The FreeBSD Foundation
+ * Copyright (c) 2021-2025 The FreeBSD Foundation
  *
  * Portions of this software were developed by Björn Zeeb
  * under sponsorship from the FreeBSD Foundation.
@@ -284,7 +284,8 @@ int lkpi_devres_destroy(struct device *, 
void(*release)(struct device *, void *)
 void lkpi_devres_release_free_list(struct device *);
 void lkpi_devres_unlink(struct device *, void *);
 void lkpi_devm_kmalloc_release(struct device *, void *);
-#define        devm_kfree(_d, _p)              lkpi_devm_kmalloc_release(_d, 
_p)
+void lkpi_devm_kfree(struct device *, const void *);
+#define        devm_kfree(_d, _p)              lkpi_devm_kfree(_d, _p)
 
 static inline const char *
 dev_driver_string(const struct device *dev)
diff --git a/sys/compat/linuxkpi/common/src/linux_devres.c 
b/sys/compat/linuxkpi/common/src/linux_devres.c
index 84f03ba0dd7d..23c91cb5ab2f 100644
--- a/sys/compat/linuxkpi/common/src/linux_devres.c
+++ b/sys/compat/linuxkpi/common/src/linux_devres.c
@@ -1,7 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
  *
  * This software was developed by Bj\xc3\xb6rn Zeeb under sponsorship from
  * the FreeBSD Foundation.
@@ -223,6 +223,30 @@ lkpi_devm_kmalloc_release(struct device *dev __unused, 
void *p __unused)
        /* Nothing to do.  Freed with the devres. */
 }
 
+static int
+lkpi_devm_kmalloc_match(struct device *dev __unused, void *p, void *mp)
+{
+       return (p == mp);
+}
+
+void
+lkpi_devm_kfree(struct device *dev, const void *p)
+{
+       void *mp;
+       int error;
+
+       if (p == NULL)
+               return;
+
+       /* I assume Linux simply casts the const away... */
+       mp = __DECONST(void *, p);
+       error = lkpi_devres_destroy(dev, lkpi_devm_kmalloc_release,
+           lkpi_devm_kmalloc_match, mp);
+       if (error != 0)
+               dev_warn(dev, "%s: lkpi_devres_destroy failed with %d\n",
+                   __func__, error);
+}
+
 struct devres_action {
        void *data;
        void (*action)(void *);

Reply via email to