Skip to contentSkip to conversation

backports: add missing backport-include header definitions

PATCH In review Yi Cong 1 participant 22 messages Jun 24 – Aug 13

lore
Share & tools
lore

Yi Cong

author
#0 lore raw

cover backports: add missing backport-include header definitions

From: Yi Cong <[email protected]>

This series adds a number of backport-include header definitions that are currently missing from the backports tree. These are the small compatibility shims needed so that backported drivers can reference kernel APIs that were added in newer kernels.

The patches only add new definitions (new headers, or new wrappers appended to existing ones); none of them modify or remove existing backport code. Each definition is guarded with the usual LINUX_VERSION_IS_LESS()/LINUX_VERSION_IN_RANGE() checks so it takes effect only on kernels where the native definition is absent, and the wrappers follow the upstream calling convention.

This is the first batch of a larger set of changes; the remaining patches (which modify existing backport code and patches) will be sent separately once this batch is reviewed.

Yi Cong (20):
headers: Add timer_shutdown_sync()
headers: include linux/module.h from backport.h
headers: add kstrtox.h backport
headers: add get_random_u32_inclusive() for kernels < 6.2
headers: add genl_split_ops compat for kernels < 6.2
headers: add thermal_zone_device_register_with_trips backport
headers: add trace_sk_data_ready no-op for kernels < 6.0
headers: add dropreason-core.h backport for kernels < 5.17
headers: add dropreason.h backport for kernels < 6.0
headers: add kfree_skb_reason() backport for kernels < 5.17
headers: add thermal_zone_device_priv() backport for kernels < 6.4
headers: add genl_small_ops backport for kernels < 5.10
headers: add class_create() single-argument backport for kernels < 6.4
headers: add list_count_nodes() backport for kernels < 6.5
headers: add net/gso.h backport for kernels < 6.5
headers: add vcalloc() backport for kernels < 5.18
headers: add __counted_by macro for kernels < 6.6
headers: add crypto/utils.h redirect for kernels < 6.6
headers: add led_trigger_blink/oneshot value-to-pointer backport for

    kernels < 6.5

headers: add of_property_present backport for kernels < 5.18

 backport/backport-include/backport/backport.h |  1 +
 backport/backport-include/crypto/utils.h      | 16 +++++++
 .../linux/compiler_attributes.h               |  8 ++++
 backport/backport-include/linux/device.h      | 14 ++++++
 backport/backport-include/linux/kstrtox.h     | 17 ++++++++
 backport/backport-include/linux/leds.h        | 39 +++++++++++++++++
 backport/backport-include/linux/list.h        | 25 +++++++++++
 backport/backport-include/linux/of.h          | 14 ++++++
 backport/backport-include/linux/random.h      |  7 +++
 backport/backport-include/linux/skbuff.h      | 17 ++++++++
 backport/backport-include/linux/thermal.h     | 25 +++++++++++
 backport/backport-include/linux/timer.h       | 14 ++++++
 backport/backport-include/linux/vmalloc.h     | 25 +++++++++++
 .../backport-include/net/dropreason-core.h    | 34 +++++++++++++++
 backport/backport-include/net/dropreason.h    | 43 +++++++++++++++++++
 backport/backport-include/net/genetlink.h     | 16 +++++++
 backport/backport-include/net/gso.h           | 16 +++++++
 backport/backport-include/trace/events/sock.h | 16 +++++++
 18 files changed, 347 insertions(+)
 create mode 100644 backport/backport-include/crypto/utils.h
 create mode 100644 backport/backport-include/linux/kstrtox.h
 create mode 100644 backport/backport-include/linux/leds.h
 create mode 100644 backport/backport-include/linux/list.h
 create mode 100644 backport/backport-include/linux/of.h
 create mode 100644 backport/backport-include/linux/vmalloc.h
 create mode 100644 backport/backport-include/net/dropreason-core.h
 create mode 100644 backport/backport-include/net/dropreason.h
 create mode 100644 backport/backport-include/net/gso.h
 create mode 100644 backport/backport-include/trace/events/sock.h
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/20 headers: Add timer_shutdown_sync()

From: Yi Cong <[email protected]>

timer_shutdown_sync() was introduced in v6.2. On older kernels it needs to delete the timer and set its function callback to NULL to emulate the shutdown semantics (prevent the timer from being rearmed).

---
 backport/backport-include/linux/timer.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
backport/backport-include/linux/timer.h +14 -0
index 14467fb6..36e15340 100644
@@ -79,4 +79,18 @@ static inline int timer_delete_sync(struct timer_list *timer)
 }
 #endif /* < 6.1.84 */
 
+#if LINUX_VERSION_IS_LESS(6,2,0)
+static inline int timer_shutdown_sync(struct timer_list *timer)
+{
+    int ret = del_timer_sync(timer);
+    /*
+     * Emulate shutdown semantics: mark as dead to prevent accidental reuse.
+     * Safe to do after del_timer_sync() because timer is no longer
+     * referenced by the timer subsystem.
+     */
+    timer->function = NULL;
+    return ret;
+}
+#endif
+
 #endif /* _BACKPORT_TIMER_H */
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/20 headers: include linux/module.h from backport.h

In reply to Yi Cong

From: Yi Cong <[email protected]>

In v6.2, include/linux/device/driver.h includes linux/module.h, so files using module_param() get it transitively. In v5.4 there is no separate device/driver.h and the include chain does not reach module.h, causing implicit-declaration errors for module_param() and related macros.

Include <linux/module.h> from backport.h, which is force-included via -include on every compilation unit, ensuring module_param and friends are always available.

---
 backport/backport-include/backport/backport.h | 1 +
 1 file changed, 1 insertion(+)
backport/backport-include/backport/backport.h +1 -0
index d1d3b102..be8668eb 100644
@@ -8,6 +8,7 @@
 
 #ifndef __ASSEMBLY__
 #define LINUX_BACKPORT(__sym) backport_ ##__sym
+#include <linux/module.h>
 #ifndef CONFIG_BACKPORT_INTEGRATE
 #include <backport/checks.h>
 #endif
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH 3/20 headers: add kstrtox.h backport

In reply to Yi Cong

From: Yi Cong <[email protected]>

The separate <linux/kstrtox.h> header was introduced in v5.14 (commit 29b25d81ef62). Before that, kstrto*() declarations live in <linux/kernel.h>.

Provide a compatibility wrapper that includes <linux/kernel.h> on kernels older than v5.14.

---
 backport/backport-include/linux/kstrtox.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 backport/backport-include/linux/kstrtox.h
backport/backport-include/linux/kstrtox.h new file +17 -0
new file mode 100644
index 00000000..a17d072b
@@ -0,0 +1,17 @@
+#ifndef __BACKPORT_KSTRTOX_H
+#define __BACKPORT_KSTRTOX_H
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_LESS(5,14,0)
+/*
+ * Before Linux 5.14, kstrto* functions were declared in linux/kernel.h.
+ * The separate linux/kstrtox.h header was introduced in commit
+ * 29b25d81ef62 ("lib/kstrtox: move kstrto*() from lib/cmdline.c to
+ * lib/kstrtox.c, add tests").
+ */
+#include <linux/kernel.h>
+#else
+#include_next <linux/kstrtox.h>
+#endif
+
+#endif /* __BACKPORT_KSTRTOX_H */
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 4/20 headers: add get_random_u32_inclusive() for kernels < 6.2

In reply to Yi Cong

From: Yi Cong <[email protected]>

get_random_u32_inclusive() was introduced in v6.2. Provide it as a static inline backed by the older prandom_u32_max() helper.

---
 backport/backport-include/linux/random.h | 7 +++++++
 1 file changed, 7 insertions(+)
backport/backport-include/linux/random.h +7 -0
index f4fd47dc..6437d55e 100644
@@ -15,4 +15,11 @@ static inline u16 get_random_u16(void)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(6,2,0)
+static inline u32 get_random_u32_inclusive(u32 floor, u32 ceiling)
+{
+	return prandom_u32_max(ceiling - floor + 1) + floor;
+}
+#endif
+
 #endif /* __BACKPORT_RANDOM_H */
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 5/20 headers: add genl_split_ops compat for kernels < 6.2

In reply to Yi Cong

From: Yi Cong <[email protected]>

genl_split_ops was introduced in v6.2; for older kernels, define it as an alias for genl_ops so that pre_doit / post_doit callbacks in nl80211.c compile without changes.

---
 backport/backport-include/net/genetlink.h | 4 ++++
 1 file changed, 4 insertions(+)
backport/backport-include/net/genetlink.h +4 -0
index c3f05fc0..b98d7110 100644
@@ -3,6 +3,10 @@
 #include_next <net/genetlink.h>
 #include <linux/version.h>
 
+#if LINUX_VERSION_IS_LESS(6,2,0)
+#define genl_split_ops genl_ops
+#endif
+
 /* this is for patches we apply */
 static inline struct netlink_ext_ack *genl_callback_extack(struct netlink_callback *cb)
 {
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH 6/20 headers: add thermal_zone_device_register_with_trips backport

In reply to Yi Cong

From: Yi Cong <[email protected]>

v6.3 mt76 and other drivers use thermal_zone_device_register_with_trips() which was introduced in v6.0. Map it to thermal_zone_device_register() for older kernels, passing 0 as num_trips and NULL as trips.

---
 backport/backport-include/linux/thermal.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
backport/backport-include/linux/thermal.h +18 -0
index f1663eff..af3c114f 100644
@@ -25,4 +25,22 @@ static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
 { return 0; }
 #endif /* < 5.9 */
 
+#if LINUX_VERSION_IS_LESS(6,0,0)
+#define thermal_zone_device_register_with_trips LINUX_BACKPORT(thermal_zone_device_register_with_trips)
+static inline struct thermal_zone_device *
+thermal_zone_device_register_with_trips(const char *type,
+					 struct thermal_trip *trips,
+					 int num_trips, int mask,
+					 void *devdata,
+					 struct thermal_zone_device_ops *ops,
+					 struct thermal_zone_params *tzp,
+					 int passive_delay,
+					 int polling_delay)
+{
+	return thermal_zone_device_register(type, num_trips, mask, devdata,
+					    ops, tzp, passive_delay,
+					    polling_delay);
+}
+#endif /* < 6.0 */
+
 #endif /* __BACKPORT_LINUX_THERMAL_H */
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH 7/20 headers: add trace_sk_data_ready no-op for kernels < 6.0

In reply to Yi Cong

From: Yi Cong <[email protected]>

v6.3 qrtr/ns.c calls trace_sk_data_ready() which was added in v6.0. Provide a no-op macro stub for older kernels.

---
 backport/backport-include/trace/events/sock.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 backport/backport-include/trace/events/sock.h
backport/backport-include/trace/events/sock.h new file +16 -0
new file mode 100644
index 00000000..7b068aa8
@@ -0,0 +1,16 @@
+#ifndef __BACKPORT_TRACE_SOCK_H
+#define __BACKPORT_TRACE_SOCK_H
+#include_next <trace/events/sock.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_LESS(6,0,0)
+/*
+ * trace_sk_data_ready() was added in v6.0.  On older kernels, provide
+ * a no-op stub so that callers compile cleanly.
+ */
+#ifndef trace_sk_data_ready
+#define trace_sk_data_ready(sk) do {} while (0)
+#endif
+#endif
+
+#endif /* __BACKPORT_TRACE_SOCK_H */
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH 8/20 headers: add dropreason-core.h backport for kernels < 5.17

In reply to Yi Cong

From: Yi Cong <[email protected]>

The skb drop reason infrastructure was introduced in v5.17. Provide minimal enum skb_drop_reason definitions (SKB_NOT_DROPPED_YET, SKB_CONSUMED) and SKB_DROP_REASON_SUBSYS_SHIFT/MASK constants so that mac80211 drop.h compiles on older kernels.

---
 .../backport-include/net/dropreason-core.h    | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 backport/backport-include/net/dropreason-core.h
backport/backport-include/net/dropreason-core.h new file +34 -0
new file mode 100644
index 00000000..2b02a8f1
@@ -0,0 +1,34 @@
+#ifndef __BACKPORT_NET_DROPREASON_CORE_H
+#define __BACKPORT_NET_DROPREASON_CORE_H
+#include <linux/version.h>
+
+/*
+ * On kernels >= 5.17, enum skb_drop_reason and the related helpers exist
+ * in the kernel's own skbuff.h / dropreason-core.h.  For older kernels we
+ * provide minimal definitions so that backported wireless drivers compile.
+ */
+#if LINUX_VERSION_IS_LESS(5,17,0)
+
+/**
+ * enum skb_drop_reason - reasons an sk_buff was dropped
+ *
+ * This is a minimal backport that only defines the few values used by
+ * the mac80211 subsystem.  The full upstream enum is much larger.
+ */
+enum skb_drop_reason {
+	SKB_NOT_DROPPED_YET = 0,
+	SKB_CONSUMED,
+	SKB_DROP_REASON_NOT_SPECIFIED,
+};
+
+/*
+ * Subsystem support was added in 6.0.  For kernels between 5.17 and 6.0
+ * the subsys fields do not exist; for kernels < 5.17 we define them here
+ * so that the mac80211 drop.h header compiles.
+ */
+#define SKB_DROP_REASON_SUBSYS_SHIFT		16
+#define SKB_DROP_REASON_SUBSYS_MASK		0xffff0000
+
+#endif /* < 5.17 */
+
+#endif /* __BACKPORT_NET_DROPREASON_CORE_H */
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH 9/20 headers: add dropreason.h backport for kernels < 6.0

In reply to Yi Cong

From: Yi Cong <[email protected]>

The subsystem-based drop reason infrastructure was introduced in v6.0 and extended in v6.4. Provide enum skb_drop_reason_subsys, struct drop_reason_list, and no-op stubs for drop_reasons_register_subsys() and drop_reasons_unregister_subsys() so that mac80211 compiles on older kernels.

---
 backport/backport-include/net/dropreason.h | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 backport/backport-include/net/dropreason.h
backport/backport-include/net/dropreason.h new file +43 -0
new file mode 100644
index 00000000..55b11c13
@@ -0,0 +1,43 @@
+#ifndef __BACKPORT_NET_DROPREASON_H
+#define __BACKPORT_NET_DROPREASON_H
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_GEQ(6,0,0)
+/* On new kernels, the real header is already available. */
+#include_next <net/dropreason.h>
+#else
+
+#include <net/dropreason-core.h>
+
+/*
+ * Minimal backport of the subsystem-based drop reason infrastructure
+ * that was introduced in kernel 6.0 and extended in 6.4.
+ */
+
+enum skb_drop_reason_subsys {
+	SKB_DROP_REASON_SUBSYS_CORE,
+	SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE,
+	SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR,
+	SKB_DROP_REASON_SUBSYS_NUM
+};
+
+struct drop_reason_list {
+	const char * const *reasons;
+	size_t n_reasons;
+};
+
+/* No-op stubs for registration */
+static inline void
+drop_reasons_register_subsys(enum skb_drop_reason_subsys subsys,
+			     const struct drop_reason_list *list)
+{
+}
+
+static inline void
+drop_reasons_unregister_subsys(enum skb_drop_reason_subsys subsys)
+{
+}
+
+#endif /* < 6.0 */
+
+#endif /* __BACKPORT_NET_DROPREASON_H */
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH 10/20 headers: add kfree_skb_reason() backport for kernels < 5.17

In reply to Yi Cong

From: Yi Cong <[email protected]>

kfree_skb_reason() was introduced in v5.17 along with enum skb_drop_reason. Provide an inline wrapper that discards the reason and calls kfree_skb() on older kernels.

---
 backport/backport-include/linux/skbuff.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
backport/backport-include/linux/skbuff.h +17 -0
index 36b83fdf..8193448d 100644
@@ -103,4 +103,21 @@ static inline bool skb_queue_empty_lockless(const struct sk_buff_head *list)
 }
 #endif /* < 5.4 */
 
+#if LINUX_VERSION_IS_LESS(5,17,0)
+/*
+ * kfree_skb_reason() was introduced in kernel 5.17 along with
+ * enum skb_drop_reason. For older kernels provide a simple wrapper
+ * that discards the reason and calls kfree_skb().
+ *
+ * The enum is provided in our backport dropreason-core.h header.
+ */
+#include <net/dropreason-core.h>
+
+static inline void kfree_skb_reason(struct sk_buff *skb,
+				    enum skb_drop_reason reason)
+{
+	kfree_skb(skb);
+}
+#endif
+
 #endif /* __BACKPORT_SKBUFF_H */
Signature · 1 line
2.43.0
author
#11 lore raw

PATCH 11/20 headers: add thermal_zone_device_priv() backport for kernels < 6.4

In reply to Yi Cong

From: Yi Cong <[email protected]>

thermal_zone_device_priv() was introduced in v6.4 to replace direct access to tz->devdata. Provide an inline wrapper for older kernels.

---
 backport/backport-include/linux/thermal.h | 7 +++++++
 1 file changed, 7 insertions(+)
backport/backport-include/linux/thermal.h +7 -0
index af3c114f..ea6568d0 100644
@@ -43,4 +43,11 @@ thermal_zone_device_register_with_trips(const char *type,
 }
 #endif /* < 6.0 */
 
+#if LINUX_VERSION_IS_LESS(6,4,0)
+static inline void *thermal_zone_device_priv(struct thermal_zone_device *tz)
+{
+	return tz->devdata;
+}
+#endif /* < 6.4 */
+
 #endif /* __BACKPORT_LINUX_THERMAL_H */
Signature · 1 line
2.43.0
author
#12 lore raw

PATCH 12/20 headers: add genl_small_ops backport for kernels < 5.10

In reply to Yi Cong

From: Yi Cong <[email protected]>

genl_small_ops was introduced in v5.10 as a more compact representation of genl_ops. For older kernels, alias genl_small_ops to genl_ops and map small_ops/n_small_ops struct fields to ops/n_ops.

---
 backport/backport-include/net/genetlink.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
backport/backport-include/net/genetlink.h +12 -0
index b98d7110..a57cd200 100644
@@ -7,6 +7,18 @@
 #define genl_split_ops genl_ops
 #endif
 
+#if LINUX_VERSION_IS_LESS(5,10,0)
+/*
+ * genl_small_ops was introduced in v5.10 to allow a more compact
+ * representation of genl_ops.  For older kernels, just alias it to
+ * genl_ops and map the struct genl_family small_ops/n_small_ops
+ * fields to ops/n_ops.
+ */
+#define genl_small_ops genl_ops
+#define small_ops ops
+#define n_small_ops n_ops
+#endif
+
 /* this is for patches we apply */
 static inline struct netlink_ext_ack *genl_callback_extack(struct netlink_callback *cb)
 {
Signature · 1 line
2.43.0
author
#13 lore raw

PATCH 13/20 headers: add class_create() single-argument backport for kernels < 6.4

In reply to Yi Cong

From: Yi Cong <[email protected]>

In v6.4 class_create() was simplified to take only the name argument, using THIS_MODULE implicitly. For older kernels, provide a wrapper that forwards to the two-argument __class_create() macro.

---
 backport/backport-include/linux/device.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
backport/backport-include/linux/device.h +14 -0
index 06595285..069337b7 100644
@@ -12,4 +12,18 @@
 	struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400)
 #endif
 
+#if LINUX_VERSION_IS_LESS(6,4,0)
+/*
+ * class_create() in v6.4+ takes only the name argument and uses
+ * THIS_MODULE implicitly.  For older kernels, provide a wrapper
+ * that forwards to the 2-argument macro version.
+ */
+#undef class_create
+#define class_create(name) \
+({ \
+	static struct lock_class_key __key; \
+	__class_create(THIS_MODULE, (name), &__key); \
+})
+#endif
+
 #endif /* __BACKPORT_DEVICE_H_ */
Signature · 1 line
2.43.0
author
#14 lore raw

PATCH 14/20 headers: add list_count_nodes() backport for kernels < 6.5

In reply to Yi Cong

From: Yi Cong <[email protected]>

list_count_nodes() was introduced in v6.5 to count the number of nodes in a struct list_head. Provide an inline backport using list_for_each() for older kernels.

---
 backport/backport-include/linux/list.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 backport/backport-include/linux/list.h
backport/backport-include/linux/list.h new file +25 -0
new file mode 100644
index 00000000..47d8d24f
@@ -0,0 +1,25 @@
+#ifndef __BACKPORT_LINUX_LIST_H
+#define __BACKPORT_LINUX_LIST_H
+#include_next <linux/list.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_LESS(6,5,0)
+/**
+ * list_count_nodes - count nodes in the list
+ * @head:	the head for your list.
+ *
+ * Introduced in v6.5. Provide a backport for older kernels.
+ */
+static inline size_t list_count_nodes(struct list_head *head)
+{
+	struct list_head *pos;
+	size_t count = 0;
+
+	list_for_each(pos, head)
+		count++;
+
+	return count;
+}
+#endif
+
+#endif /* __BACKPORT_LINUX_LIST_H */
Signature · 1 line
2.43.0
author
#15 lore raw

PATCH 15/20 headers: add net/gso.h backport for kernels < 6.5

In reply to Yi Cong

From: Yi Cong <[email protected]>

In v6.5 GSO helpers (skb_gso_segment, etc.) were extracted from linux/netdevice.h into a new net/gso.h header. For older kernels, this backport simply includes the existing headers where these functions are already defined.

---
 backport/backport-include/net/gso.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 backport/backport-include/net/gso.h
backport/backport-include/net/gso.h new file +16 -0
new file mode 100644
index 00000000..ccc1e3d4
@@ -0,0 +1,16 @@
+#ifndef __BACKPORT_NET_GSO_H
+#define __BACKPORT_NET_GSO_H
+#include <linux/version.h>
+
+/*
+ * net/gso.h was introduced in v6.5 by extracting GSO helpers from
+ * linux/netdevice.h and linux/skbuff.h.  On older kernels these
+ * functions are already available through the existing headers, so
+ * this backport simply pulls in the relevant includes.
+ */
+#if LINUX_VERSION_IS_LESS(6,5,0)
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#endif
+
+#endif /* __BACKPORT_NET_GSO_H */
Signature · 1 line
2.43.0
author
#16 lore raw

PATCH 16/20 headers: add vcalloc() backport for kernels < 5.18

In reply to Yi Cong

From: Yi Cong <[email protected]>

vcalloc() was introduced in v5.18 to allocate and zero virtually contiguous memory with overflow-checked multiplication. Provide a wrapper using vzalloc() for older kernels.

---
 backport/backport-include/linux/vmalloc.h | 25 +++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 backport/backport-include/linux/vmalloc.h
backport/backport-include/linux/vmalloc.h new file +25 -0
new file mode 100644
index 00000000..233c8608
@@ -0,0 +1,25 @@
+#ifndef __BACKPORT_LINUX_VMALLOC_H
+#define __BACKPORT_LINUX_VMALLOC_H
+#include_next <linux/vmalloc.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_LESS(5,18,0)
+/**
+ * vcalloc - allocate virtually contiguous memory and zero it
+ * @n:		number of elements
+ * @size:	size of each element
+ *
+ * Introduced in v5.18. On older kernels, fall back to vzalloc()
+ * with overflow-checked multiplication.
+ */
+static inline void *vcalloc(size_t n, size_t size)
+{
+	size_t bytes;
+	if (size && n > SIZE_MAX / size)
+		return NULL;
+	bytes = n * size;
+	return vzalloc(bytes);
+}
+#endif
+
+#endif /* __BACKPORT_LINUX_VMALLOC_H */
Signature · 1 line
2.43.0
author
#17 lore raw

PATCH 17/20 headers: add __counted_by macro for kernels < 6.6

In reply to Yi Cong

From: Yi Cong <[email protected]>

__counted_by() was introduced in v6.6 as a compiler attribute for flexible array member bounds checking. Add a definition that expands to the attribute when supported by the compiler, or to nothing otherwise.

---
 backport/backport-include/linux/compiler_attributes.h | 8 ++++++++
 1 file changed, 8 insertions(+)
backport/backport-include/linux/compiler_attributes.h +8 -0
index 31ddc163..b39b66b5 100644
@@ -31,4 +31,12 @@
 #endif
 #endif /* fallthrough */
 
+#ifndef __counted_by
+#if __has_attribute(__counted_by__)
+# define __counted_by(member)		__attribute__((__counted_by__(member)))
+#else
+# define __counted_by(member)
+#endif
+#endif /* __counted_by */
+
 #endif /* _BACKPORTS_LINUX_COMPILER_ATTRIBUTES_H */
Signature · 1 line
2.43.0
author
#18 lore raw

PATCH 18/20 headers: add crypto/utils.h redirect for kernels < 6.6

In reply to Yi Cong

From: Yi Cong <[email protected]>

In v6.6 crypto_xor(), crypto_xor_cpy(), and crypto_memneq() were moved from crypto/algapi.h to a new crypto/utils.h header. For older kernels, redirect to the original location.

---
 backport/backport-include/crypto/utils.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 backport/backport-include/crypto/utils.h
backport/backport-include/crypto/utils.h new file +16 -0
new file mode 100644
index 00000000..7722b44a
@@ -0,0 +1,16 @@
+#ifndef __BACKPORT_CRYPTO_UTILS_H
+#define __BACKPORT_CRYPTO_UTILS_H
+#include <linux/version.h>
+
+/*
+ * In v6.6 crypto_xor(), crypto_xor_cpy(), and crypto_memneq() were
+ * moved from crypto/algapi.h to a new crypto/utils.h header.
+ * For older kernels, redirect to the original location.
+ */
+#if LINUX_VERSION_IS_LESS(6,6,0)
+#include <crypto/algapi.h>
+#else
+#include_next <crypto/utils.h>
+#endif
+
+#endif /* __BACKPORT_CRYPTO_UTILS_H */
Signature · 1 line
2.43.0
author
#19 lore raw

PATCH 19/20 headers: add led_trigger_blink/oneshot value-to-pointer backport for kernels < 6.5

In reply to Yi Cong

From: Yi Cong <[email protected]>

In v6.5 led_trigger_blink() and led_trigger_blink_oneshot() changed their delay_on/delay_off parameters from 'unsigned long *' to 'unsigned long'. mac80211/led.h and led.c call these with value arguments (v6.5 style). For older kernels that still expect pointers, provide wrappers that accept values and forward them via pointers to the original functions.

---
 backport/backport-include/linux/leds.h | 39 ++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 backport/backport-include/linux/leds.h
backport/backport-include/linux/leds.h new file +39 -0
new file mode 100644
index 00000000..c922c5df
@@ -0,0 +1,39 @@
+#ifndef __BACKPORT_LINUX_LEDS_H
+#define __BACKPORT_LINUX_LEDS_H
+#include_next <linux/leds.h>
+#include <linux/version.h>
+
+/*
+ * In v6.5 led_trigger_blink() and led_trigger_blink_oneshot() changed
+ * their delay_on/delay_off parameters from pointer to value:
+ *   v5.4: led_trigger_blink(trigger, unsigned long *delay_on, ...)
+ *   v6.5: led_trigger_blink(trigger, unsigned long delay_on, ...)
+ *
+ * mac80211/led.h and mac80211/led.c call these with value arguments
+ * (v6.5 style).  For older kernels that still expect pointers, provide
+ * wrappers that accept values and forward them via pointers.
+ */
+#if LINUX_VERSION_IS_LESS(6,5,0)
+#undef led_trigger_blink
+static inline void LINUX_BACKPORT(led_trigger_blink)(
+	struct led_trigger *trigger,
+	unsigned long delay_on,
+	unsigned long delay_off)
+{
+	led_trigger_blink(trigger, &delay_on, &delay_off);
+}
+#define led_trigger_blink LINUX_BACKPORT(led_trigger_blink)
+
+#undef led_trigger_blink_oneshot
+static inline void LINUX_BACKPORT(led_trigger_blink_oneshot)(
+	struct led_trigger *trigger,
+	unsigned long delay_on,
+	unsigned long delay_off,
+	int invert)
+{
+	led_trigger_blink_oneshot(trigger, &delay_on, &delay_off, invert);
+}
+#define led_trigger_blink_oneshot LINUX_BACKPORT(led_trigger_blink_oneshot)
+#endif
+
+#endif /* __BACKPORT_LINUX_LEDS_H */
Signature · 1 line
2.43.0
author
#20 lore raw

PATCH 20/20 headers: add of_property_present backport for kernels < 5.18

In reply to Yi Cong

From: Yi Cong <[email protected]>

of_property_present() was introduced in v5.18 as a wrapper around of_property_read_bool(). This is needed when CONFIG_OF is enabled (e.g. arm64, loongarch defconfigs) as brcmfmac/of.c uses it.

---
 backport/backport-include/linux/of.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 backport/backport-include/linux/of.h
backport/backport-include/linux/of.h new file +14 -0
new file mode 100644
index 00000000..7dc83e1f
@@ -0,0 +1,14 @@
+#ifndef __BACKPORT_LINUX_OF_H
+#define __BACKPORT_LINUX_OF_H
+#include_next <linux/of.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_IS_LESS(5,18,0)
+static inline bool of_property_present(const struct device_node *np,
+				       const char *propname)
+{
+	return of_property_read_bool(np, propname);
+}
+#endif
+
+#endif /* __BACKPORT_LINUX_OF_H */
Signature · 1 line
2.43.0
author
#21 lore raw
In reply to Yi Cong
Quoted 63 lines · Yi Cong

From: Yi Cong <[email protected]>

This series adds a number of backport-include header definitions that are currently missing from the backports tree. These are the small compatibility shims needed so that backported drivers can reference kernel APIs that were added in newer kernels.

The patches only add new definitions (new headers, or new wrappers appended to existing ones); none of them modify or remove existing backport code. Each definition is guarded with the usual LINUX_VERSION_IS_LESS()/LINUX_VERSION_IN_RANGE() checks so it takes effect only on kernels where the native definition is absent, and the wrappers follow the upstream calling convention.

This is the first batch of a larger set of changes; the remaining patches (which modify existing backport code and patches) will be sent separately once this batch is reviewed.

Yi Cong (20):
headers: Add timer_shutdown_sync()
headers: include linux/module.h from backport.h
headers: add kstrtox.h backport
headers: add get_random_u32_inclusive() for kernels < 6.2
headers: add genl_split_ops compat for kernels < 6.2
headers: add thermal_zone_device_register_with_trips backport
headers: add trace_sk_data_ready no-op for kernels < 6.0
headers: add dropreason-core.h backport for kernels < 5.17
headers: add dropreason.h backport for kernels < 6.0
headers: add kfree_skb_reason() backport for kernels < 5.17
headers: add thermal_zone_device_priv() backport for kernels < 6.4
headers: add genl_small_ops backport for kernels < 5.10
headers: add class_create() single-argument backport for kernels < 6.4
headers: add list_count_nodes() backport for kernels < 6.5
headers: add net/gso.h backport for kernels < 6.5
headers: add vcalloc() backport for kernels < 5.18
headers: add __counted_by macro for kernels < 6.6
headers: add crypto/utils.h redirect for kernels < 6.6
headers: add led_trigger_blink/oneshot value-to-pointer backport for

    kernels < 6.5

headers: add of_property_present backport for kernels < 5.18

 backport/backport-include/backport/backport.h |  1 +
 backport/backport-include/crypto/utils.h      | 16 +++++++
 .../linux/compiler_attributes.h               |  8 ++++
 backport/backport-include/linux/device.h      | 14 ++++++
 backport/backport-include/linux/kstrtox.h     | 17 ++++++++
 backport/backport-include/linux/leds.h        | 39 +++++++++++++++++
 backport/backport-include/linux/list.h        | 25 +++++++++++
 backport/backport-include/linux/of.h          | 14 ++++++
 backport/backport-include/linux/random.h      |  7 +++
 backport/backport-include/linux/skbuff.h      | 17 ++++++++
 backport/backport-include/linux/thermal.h     | 25 +++++++++++
 backport/backport-include/linux/timer.h       | 14 ++++++
 backport/backport-include/linux/vmalloc.h     | 25 +++++++++++
 .../backport-include/net/dropreason-core.h    | 34 +++++++++++++++
 backport/backport-include/net/dropreason.h    | 43 +++++++++++++++++++
 backport/backport-include/net/genetlink.h     | 16 +++++++
 backport/backport-include/net/gso.h           | 16 +++++++
 backport/backport-include/trace/events/sock.h | 16 +++++++
 18 files changed, 347 insertions(+)
 create mode 100644 backport/backport-include/crypto/utils.h
 create mode 100644 backport/backport-include/linux/kstrtox.h
Quoted 8 lines
 create mode 100644 backport/backport-include/linux/leds.h
 create mode 100644 backport/backport-include/linux/list.h
 create mode 100644 backport/backport-include/linux/of.h
 create mode 100644 backport/backport-include/linux/vmalloc.h
 create mode 100644 backport/backport-include/net/dropreason-core.h
 create mode 100644 backport/backport-include/net/dropreason.h
 create mode 100644 backport/backport-include/net/gso.h
 create mode 100644 backport/backport-include/trace/events/sock.h

Dear Maintainer:

I would like to know if this series of patches I have meet the requirements and specifications of the project.

If there are any issues with these patches, please let me know.

Thank you very much.

Regards,
Yi Cong