git: e999fbf07762 - main - LinuxKPI: device.h add devm_kmemdup()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 22 Sep 2022 16:16:22 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=e999fbf0776208f9ecbc2926fd088427d766b014
commit e999fbf0776208f9ecbc2926fd088427d766b014
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-09-21 19:33:30 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-09-22 15:09:26 +0000
LinuxKPI: device.h add devm_kmemdup()
Add devm_kmemdup() as needed by a networking driver.
Sponsored by: The FreeBSD Foundation
MFC after: 7 days
eviewed by: hselasky, emaste
Differential Revision: https://reviews.freebsd.org/D36652
---
sys/compat/linuxkpi/common/include/linux/device.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index 757060cb2863..32195ad5b0a6 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -4,6 +4,10 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2021-2022 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -600,6 +604,21 @@ devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
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);
+}
+
#define devm_kzalloc(_dev, _size, _gfp) \
devm_kmalloc((_dev), (_size), (_gfp) | __GFP_ZERO)