git: 53beb6950f94 - main - LinuxKPI; factor out parts of device.h into device/devres.h
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 10 Oct 2026 18:29:00 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=53beb6950f9415eb06dc24b9addea5932e3bd0da
commit 53beb6950f9415eb06dc24b9addea5932e3bd0da
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-10-01 23:09:14 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-10-10 18:28:32 +0000
LinuxKPI; factor out parts of device.h into device/devres.h
In [1] it was pointed out that devm_kmemdup_* have moved apparently
in Linux 7.0 into their own device/devres.h header file from device.h.
Move them and other parts (some being dependencies) along.
device/devres.h gets included from device.h so all that changes is
prototype, macro, and inline function ordering.
This should prepare us in case drivers start directly including
the sub-header. It also helps to keep device.h more reasable.
Suggested by: dumbbell (in D56396) [1]
MFC after: 3 days
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D60213
---
sys/compat/linuxkpi/common/include/linux/device.h | 53 +---------------
.../linuxkpi/common/include/linux/device/devres.h | 70 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 52 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index 0d06f4df59c6..08a0d809d0a4 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -48,6 +48,7 @@
#include <linux/overflow.h>
#include <linux/ratelimit.h> /* via linux/dev_printk.h */
#include <linux/fwnode.h>
+#include <linux/device/devres.h>
#include <asm/atomic.h>
#include <sys/bus.h>
@@ -291,26 +292,8 @@ dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
#define dev_err_cast_probe(dev, err, fmt, ...) \
ERR_PTR(dev_err_probe((dev), PTR_ERR(err), fmt, ##__VA_ARGS__)
-/* Public and LinuxKPI internal devres functions. */
-void *lkpi_devres_alloc(void(*release)(struct device *, void *), size_t, gfp_t);
-void lkpi_devres_add(struct device *, void *);
-void lkpi_devres_free(void *);
-void *lkpi_devres_find(struct device *, void(*release)(struct device *, void *),
- int (*match)(struct device *, void *, void *), void *);
-int lkpi_devres_destroy(struct device *, void(*release)(struct device *, void *),
- int (*match)(struct device *, void *, void *), void *);
-#define devres_alloc(_r, _s, _g) lkpi_devres_alloc(_r, _s, _g)
-#define devres_add(_d, _p) lkpi_devres_add(_d, _p)
-#define devres_free(_p) lkpi_devres_free(_p)
-#define devres_find(_d, _rfn, _mfn, _mp) \
- lkpi_devres_find(_d, _rfn, _mfn, _mp)
-#define devres_destroy(_d, _rfn, _mfn, _mp) \
- lkpi_devres_destroy(_d, _rfn, _mfn, _mp)
void lkpi_devres_release_free_list(struct device *);
void lkpi_devres_unlink(struct device *, void *);
-void lkpi_devm_kmalloc_release(struct device *, void *);
-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)
@@ -703,40 +686,6 @@ char *lkpi_devm_kasprintf(struct device *, gfp_t, const char *, ...);
#define devm_kasprintf(_dev, _gfp, _fmt, ...) \
lkpi_devm_kasprintf(_dev, _gfp, _fmt, ##__VA_ARGS__)
-static __inline void *
-devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
-{
- void *p;
-
- p = lkpi_devres_alloc(lkpi_devm_kmalloc_release, size, gfp);
- if (p != NULL)
- lkpi_devres_add(dev, p);
-
- return (p);
-}
-
-static inline void *
-devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
-{
- void *dst;
-
- if (len == 0)
- return (NULL);
-
- dst = devm_kmalloc(dev, len, gfp);
- if (dst != NULL)
- memcpy(dst, src, len);
-
- return (dst);
-}
-
-static inline void *
-devm_kmemdup_array(struct device *dev, const void *src, size_t n, size_t len,
- gfp_t gfp)
-{
- return (devm_kmemdup(dev, src, size_mul(n, len), gfp));
-}
-
#define devm_kzalloc(_dev, _size, _gfp) \
devm_kmalloc((_dev), (_size), (_gfp) | __GFP_ZERO)
diff --git a/sys/compat/linuxkpi/common/include/linux/device/devres.h b/sys/compat/linuxkpi/common/include/linux/device/devres.h
new file mode 100644
index 000000000000..f05cdb7b065c
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/device/devres.h
@@ -0,0 +1,70 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021-2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ */
+#ifndef _LINUXKPI_LINUX_DEVICE_DEVRES_H_
+#define _LINUXKPI_LINUX_DEVICE_DEVRES_H_
+
+#include <linux/types.h>
+
+/* Public and LinuxKPI internal devres functions. */
+void *lkpi_devres_alloc(void(*release)(struct device *, void *), size_t, gfp_t);
+void lkpi_devres_add(struct device *, void *);
+void lkpi_devres_free(void *);
+void *lkpi_devres_find(struct device *, void(*release)(struct device *, void *),
+ int (*match)(struct device *, void *, void *), void *);
+int lkpi_devres_destroy(struct device *, void(*release)(struct device *, void *),
+ int (*match)(struct device *, void *, void *), void *);
+#define devres_alloc(_r, _s, _g) lkpi_devres_alloc(_r, _s, _g)
+#define devres_add(_d, _p) lkpi_devres_add(_d, _p)
+#define devres_free(_p) lkpi_devres_free(_p)
+#define devres_find(_d, _rfn, _mfn, _mp) \
+ lkpi_devres_find(_d, _rfn, _mfn, _mp)
+#define devres_destroy(_d, _rfn, _mfn, _mp) \
+ lkpi_devres_destroy(_d, _rfn, _mfn, _mp)
+
+void lkpi_devm_kfree(struct device *, const void *);
+#define devm_kfree(_d, _p) lkpi_devm_kfree(_d, _p)
+
+void lkpi_devm_kmalloc_release(struct device *, void *);
+
+static inline void *
+devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
+{
+ void *p;
+
+ p = lkpi_devres_alloc(lkpi_devm_kmalloc_release, size, gfp);
+ if (p != NULL)
+ lkpi_devres_add(dev, p);
+
+ return (p);
+}
+
+static inline void *
+devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
+{
+ void *dst;
+
+ if (len == 0)
+ return (NULL);
+
+ dst = devm_kmalloc(dev, len, gfp);
+ if (dst != NULL)
+ memcpy(dst, src, len);
+
+ return (dst);
+}
+
+static inline void *
+devm_kmemdup_array(struct device *dev, const void *src, size_t n, size_t len,
+ gfp_t gfp)
+{
+ return (devm_kmemdup(dev, src, size_mul(n, len), gfp));
+}
+
+#endif /* _LINUXKPI_LINUX_DEVICE_DEVRES_H_ */