Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Sep 2025 23:29:11 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4ab64e34911a - main - LinuxKPI: devres: divorce dem_kfree from lkpi_devm_kmalloc_release
Message-ID:  <202509052329.585NTBrH029581@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bz:

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

commit 4ab64e34911ab06e567caaf07ed18f7770a61cc8
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-04 20:28:18 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-09-05 23:24:17 +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)
    MFC after:      3 days
    Reviewed by:    dumbbell
    Differential Revision:  https://reviews.freebsd.org/D52082
---
 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 *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509052329.585NTBrH029581>