Skip to contentSkip to conversation

backports: add GENMASK and GENMASK_ULL

PATCH Superseded Felix Fietkau 2 participants 5 messages Nov 13, 2014 – Nov 16, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 backports: add GENMASK and GENMASK_ULL

I intend to use this for a new driver

---
 backport/backport-include/linux/bitops.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 backport/backport-include/linux/bitops.h
backport/backport-include/linux/bitops.h new file +19 -0
new file mode 100644
index 0000000..d8aec05
@@ -0,0 +1,19 @@
+#ifndef __BACKPORT_BITOPS_H
+#define __BACKPORT_BITOPS_H
+#include_next <linux/bitops.h>
+#include <linux/version.h>
+#include <generated/utsrelease.h>
+
+#ifndef GENMASK
+
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l)          (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
+#define GENMASK_ULL(h, l)      (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
+
+#endif
+
+#endif /* __BACKPORT_BITOPS_H */
Signature · 1 line
2.1.2
#1 lore raw

PATCH 2/3 backports: add include/uapi/linux/pci_regs.h to copy-list

Fixes a recent iwlwifi build error

---
 copy-list | 1 +
 1 file changed, 1 insertion(+)
copy-list +1 -0
index 75ef52f..6a6cb01 100644
@@ -23,6 +23,7 @@ include/linux/wireless.h
 include/uapi/linux/wireless.h
 include/linux/ieee80211.h
 include/linux/pci_ids.h
+include/uapi/linux/pci_regs.h
 include/linux/mmc/sdio_ids.h
 include/linux/ath9k_platform.h
 include/uapi/linux/wil6210_uapi.h
Signature · 1 line
2.1.2
#2 lore raw

PATCH 3/3 backports: backport devm_kmemdup

In reply to Felix Fietkau
---
 backport/backport-include/linux/device.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
backport/backport-include/linux/device.h +16 -0
index 41f06c3..429df37 100644
@@ -177,4 +177,20 @@ static inline void *devm_kmalloc_array(struct device *dev,
 }
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
+#define devm_kmemdup LINUX_BACKPORT(devm_kmemdup)
+static inline void *devm_kmemdup(struct device *dev, const void *src,
+				 size_t len, gfp_t gfp)
+{
+	void *p;
+
+	p = devm_kmalloc(dev, len, gfp);
+	if (p)
+		memcpy(p, src, len);
+
+	return p;
+}
+#endif
+
+
 #endif /* __BACKPORT_DEVICE_H */
Signature · 1 line
2.1.2
#3 lore raw

Re: [PATCH 3/3] backports: backport devm_kmemdup

Quoted 10 lines · Felix Fietkau
---
 backport/backport-include/linux/device.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
backport/backport-include/linux/device.h +0 -0
index 41f06c3..429df37 100644

backport/backport-include/linux/device.h static inline void *devm_kmalloc_array(struct device *dev, · line 180

Quoted 4 lines
backport/backport-include/linux/device.h +1 -0
@@ -177,4 +177,20 @@ static inline void *devm_kmalloc_array(struct device *dev,
 }
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)

devm_kmemdup() is not available in kernel 3.15, you should use #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)

Quoted 17 lines
backport/backport-include/linux/device.h +15 -0
+#define devm_kmemdup LINUX_BACKPORT(devm_kmemdup)
+static inline void *devm_kmemdup(struct device *dev, const void *src,
+				 size_t len, gfp_t gfp)
+{
+	void *p;
+
+	p = devm_kmalloc(dev, len, gfp);
+	if (p)
+		memcpy(p, src, len);
+
+	return p;
+}
+#endif
+
+
 #endif /* __BACKPORT_DEVICE_H */
#4 lore raw
In reply to Felix Fietkau
Quoted 14 lines · Felix Fietkau

I intend to use this for a new driver

---
 backport/backport-include/linux/bitops.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 backport/backport-include/linux/bitops.h
backport/backport-include/linux/bitops.h new file +0 -0
new file mode 100644
index 0000000..d8aec05

backport/backport-include/linux/bitops.h line 5

Quoted 5 lines
backport/backport-include/linux/bitops.h new file +5 -0
@@ -0,0 +1,19 @@
+#ifndef __BACKPORT_BITOPS_H
+#define __BACKPORT_BITOPS_H
+#include_next <linux/bitops.h>
+#include <linux/version.h>
+#include <generated/utsrelease.h>

These two includes are not needed.

backport/backport-include/linux/bitops.h line 15

Quoted 10 lines
backport/backport-include/linux/bitops.h new file +10 -0
+
+#ifndef GENMASK
+
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l)          (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
+#define GENMASK_ULL(h, l)      (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))

You should use tabs here and not spaces.

Quoted 5 lines
backport/backport-include/linux/bitops.h new file +4 -0
+
+#endif
+
+#endif /* __BACKPORT_BITOPS_H */