Skip to contentSkip to conversation

backports: copy linux/overflow.h

PATCH New Felix Fietkau 1 participant 6 messages Sep 6, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 backports: copy linux/overflow.h

Overflow macros are useful for further backports

---
 copy-list | 1 +
 1 file changed, 1 insertion(+)
copy-list +1 -0
index 5c64b6d4..21ca8070 100644
@@ -19,6 +19,7 @@ include/linux/fixp-arith.h
 # This just defines some macros, simply take it
 include/linux/bitfield.h
 include/linux/average.h
+include/linux/overflow.h
 
 # crypto_memneq
 crypto/memneq.c -> compat/memneq.c
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#1 lore raw

PATCH 2/6 backport-include: backport kvmalloc and kvmalloc_array

---
 backport/backport-include/linux/mm.h | 35 ++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
backport/backport-include/linux/mm.h +35 -0
index 3234b37d..6ee5c7d8 100644
@@ -3,6 +3,9 @@
 #include_next <linux/mm.h>
 #include <linux/page_ref.h>
 #include <linux/sched.h>
+#include <linux/overflow.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
 
 #ifndef VM_NODUMP
 /*
@@ -123,4 +126,36 @@ static inline bool page_is_pfmemalloc(struct page *page)
 }
 #endif /* < 4.2 */
 
+#if LINUX_VERSION_IS_LESS(4,12,0)
+#define kvmalloc LINUX_BACKPORT(kvmalloc)
+static inline void *kvmalloc(size_t size, gfp_t flags)
+{
+	gfp_t kmalloc_flags = flags;
+	void *ret;
+
+	if ((flags & GFP_KERNEL) != GFP_KERNEL)
+		return kmalloc(size, flags);
+
+	if (size > PAGE_SIZE)
+		kmalloc_flags |= __GFP_NOWARN | __GFP_NORETRY;
+
+	ret = kmalloc(size, flags);
+	if (ret || size < PAGE_SIZE)
+		return ret;
+
+	return vmalloc(size);
+}
+
+#define kvmalloc_array LINUX_BACKPORT(kvmalloc_array)
+static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(n, size, &bytes)))
+		return NULL;
+
+	return kvmalloc(bytes, flags);
+}
+#endif
+
 #endif /* __BACKPORT_MM_H */
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#2 lore raw

PATCH 3/6 patches: remove lib-bucket_locks.patch

In reply to Felix Fietkau

Obsoleted by kvmalloc/kvmalloc_array backport

---
 patches/lib-bucket_locks.patch | 29 -----------------------------
 1 file changed, 29 deletions(-)
 delete mode 100644 patches/lib-bucket_locks.patch
patches/lib-bucket_locks.patch deleted +0 -29
deleted file mode 100644
index 15eeda11..00000000
@@ -1,29 +0,0 @@
-diff --git a/compat/lib-bucket_locks.c b/compat/lib-bucket_locks.c
-index 266a97c5708b..405b52ca5708 100644
---- a/compat/lib-bucket_locks.c
-+++ b/compat/lib-bucket_locks.c
-@@ -30,10 +30,24 @@ int alloc_bucket_spinlocks(spinlock_t **
- 	}
- 
- 	if (sizeof(spinlock_t) != 0) {
-+#if LINUX_VERSION_IS_LESS(4,12,0)
-+#ifdef CONFIG_NUMA
-+		if (size * sizeof(spinlock_t) > PAGE_SIZE &&
-+		    gfp == GFP_KERNEL)
-+			tlocks = vmalloc(size * sizeof(spinlock_t));
-+#endif
-+		if (gfp != GFP_KERNEL)
-+			gfp |= __GFP_NOWARN | __GFP_NORETRY;
-+
-+		if (!tlocks)
-+			tlocks = kmalloc_array(size, sizeof(spinlock_t),
-+						   gfp);
-+#else
- 		if (gfpflags_allow_blocking(gfp))
- 			tlocks = kvmalloc(size * sizeof(spinlock_t), gfp);
- 		else
- 			tlocks = kmalloc_array(size, sizeof(spinlock_t), gfp);
-+#endif
- 		if (!tlocks)
- 			return -ENOMEM;
- 		for (i = 0; i < size; i++)
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#3 lore raw

PATCH 4/6 backport-include: backport ktime_get_boottime_seconds

In reply to Felix Fietkau
---
 backport/backport-include/linux/timekeeping.h | 7 +++++++
 1 file changed, 7 insertions(+)
backport/backport-include/linux/timekeeping.h +7 -0
index 30f9b7a9..56c3deec 100644
@@ -24,6 +24,13 @@ static inline u64 ktime_get_boot_ns(void)
 }
 #endif /* < 3.17 */
 
+#if LINUX_VERSION_IS_LESS(4,18,0)
+static inline time64_t ktime_get_boottime_seconds(void)
+{
+	return ktime_divns(ktime_get_boottime(), NSEC_PER_SEC);
+}
+#endif /* < 4.18 */
+
 #if LINUX_VERSION_IS_LESS(3,19,0)
 static inline time64_t ktime_get_seconds(void)
 {
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#4 lore raw

PATCH 5/6 backport: copy net/rsi_91x.h

In reply to Felix Fietkau
---
 copy-list | 1 +
 1 file changed, 1 insertion(+)
copy-list +1 -0
index 21ca8070..f9f9396c 100644
@@ -49,6 +49,7 @@ include/linux/spi/libertas_spi.h
 include/linux/platform_data/brcmfmac.h
 include/linux/platform_data/net-cw1200.h
 include/uapi/linux/nl80211.h
+include/net/rsi_91x.h
 
 include/net/cfg80211.h
 include/net/cfg80211-wext.h
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in
#5 lore raw

PATCH 6/6 backport: add firmware_request_nowarn and firmware_request_cache

In reply to Felix Fietkau
---
 backport/backport-include/linux/firmware.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
backport/backport-include/linux/firmware.h +11 -0
index 186eec3e..b5bc16be 100644
@@ -5,5 +5,16 @@
 #if LINUX_VERSION_IS_LESS(3,14,0)
 #define request_firmware_direct(fw, name, device) request_firmware(fw, name, device)
 #endif
+#if LINUX_VERSION_IS_LESS(4,18,0)
+#define firmware_request_nowarn(fw, name, device) request_firmware(fw, name, device)
+#endif
+
+#if LINUX_VERSION_IS_LESS(4,17,0)
+#define firmware_request_cache LINUX_BACKPORT(firmware_request_cache)
+static inline int firmware_request_cache(struct device *device, const char *name)
+{
+	return 0;
+}
+#endif
 
 #endif /* __BACKPORT_LINUX_FIRMWARE_H */
Signature · 4 lines
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe backports" in