mac80211: add dev_coredumpm() function
[openwrt/staging/chunkeey.git] / package / kernel / mac80211 / patches / 013-backport-dev_coredumpm-function.patch
1 From ec8549e611465558bdf1bb5e9d308f39e5e248cd Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 17 Sep 2017 14:41:48 +0200
4 Subject: backport dev_coredumpm() function
5
6 This is copied from a more recent backports version to add the
7 dev_coredumpm() function when the internal core devdump is not used.
8 ---
9 compat/Makefile | 1 +
10 compat/backport-4.7.c | 82 ++++++++++++++++++++++++++++++++++++++++++
11 include/linux/bp-devcoredump.h | 32 +++++++++++++++++
12 include/linux/devcoredump.h | 1 +
13 4 files changed, 116 insertions(+)
14 create mode 100644 compat/backport-4.7.c
15 create mode 100644 include/linux/bp-devcoredump.h
16
17 --- a/compat/Makefile
18 +++ b/compat/Makefile
19 @@ -32,6 +32,7 @@ compat-$(CPTCFG_KERNEL_4_3) += backport-
20 compat-$(CPTCFG_KERNEL_4_4) += backport-4.4.o
21 compat-$(CPTCFG_KERNEL_4_5) += backport-4.5.o
22 compat-$(CPTCFG_KERNEL_4_6) += backport-4.6.o
23 +compat-$(CPTCFG_KERNEL_4_6) += backport-4.7.o
24
25 compat-$(CPTCFG_BPAUTO_BUILD_CRYPTO_CCM) += crypto-ccm.o
26 compat-$(CPTCFG_BPAUTO_CRYPTO_SKCIPHER) += crypto-skcipher.o
27 --- /dev/null
28 +++ b/compat/backport-4.7.c
29 @@ -0,0 +1,82 @@
30 +/*
31 + * Copyright(c) 2016 Hauke Mehrtens <hauke@hauke-m.de>
32 + *
33 + * Backport functionality introduced in Linux 4.7.
34 + *
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License version 2 as
37 + * published by the Free Software Foundation.
38 + */
39 +
40 +#include <linux/export.h>
41 +#include <linux/list.h>
42 +#include <linux/rcupdate.h>
43 +#include <linux/slab.h>
44 +#include <linux/spinlock.h>
45 +#include <linux/skbuff.h>
46 +#include <net/netlink.h>
47 +
48 +/*
49 + * Below 3.18 or if the kernel has devcoredump disabled, we copied the
50 + * entire devcoredump, so no need to define these functions.
51 + */
52 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0) && \
53 + !defined(CPTCFG_BPAUTO_BUILD_WANT_DEV_COREDUMP)
54 +#include <linux/devcoredump.h>
55 +#include <linux/scatterlist.h>
56 +
57 +static void devcd_free_sgtable(void *data)
58 +{
59 + struct scatterlist *table = data;
60 + int i;
61 + struct page *page;
62 + struct scatterlist *iter;
63 + struct scatterlist *delete_iter;
64 +
65 + /* free pages */
66 + iter = table;
67 + for_each_sg(table, iter, sg_nents(table), i) {
68 + page = sg_page(iter);
69 + if (page)
70 + __free_page(page);
71 + }
72 +
73 + /* then free all chained tables */
74 + iter = table;
75 + delete_iter = table; /* always points on a head of a table */
76 + while (!sg_is_last(iter)) {
77 + iter++;
78 + if (sg_is_chain(iter)) {
79 + iter = sg_chain_ptr(iter);
80 + kfree(delete_iter);
81 + delete_iter = iter;
82 + }
83 + }
84 +
85 + /* free the last table */
86 + kfree(delete_iter);
87 +}
88 +
89 +static ssize_t devcd_read_from_sgtable(char *buffer, loff_t offset,
90 + size_t buf_len, void *data,
91 + size_t data_len)
92 +{
93 + struct scatterlist *table = data;
94 +
95 + if (offset > data_len)
96 + return -EINVAL;
97 +
98 + if (offset + buf_len > data_len)
99 + buf_len = data_len - offset;
100 + return sg_pcopy_to_buffer(table, sg_nents(table), buffer, buf_len,
101 + offset);
102 +}
103 +
104 +void dev_coredumpsg(struct device *dev, struct scatterlist *table,
105 + size_t datalen, gfp_t gfp)
106 +{
107 + dev_coredumpm(dev, THIS_MODULE, table, datalen, gfp,
108 + devcd_read_from_sgtable, devcd_free_sgtable);
109 +}
110 +EXPORT_SYMBOL_GPL(dev_coredumpsg);
111 +#endif /* >= 3.18.0 */
112 --- /dev/null
113 +++ b/include/linux/bp-devcoredump.h
114 @@ -0,0 +1,32 @@
115 +#ifndef __BACKPORT_LINUX_DEVCOREDUMP_H
116 +#define __BACKPORT_LINUX_DEVCOREDUMP_H
117 +#include <linux/version.h>
118 +#include <linux/scatterlist.h>
119 +
120 +/* We only need to add our wrapper inside the range from 3.18 until
121 + * 4.6, outside that we can let our BPAUTO mechanism handle it.
122 + */
123 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0) && \
124 + LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0))
125 +static inline
126 +void backport_dev_coredumpm(struct device *dev, struct module *owner,
127 + void *data, size_t datalen, gfp_t gfp,
128 + ssize_t (*read_fn)(char *buffer, loff_t offset,
129 + size_t count, void *data,
130 + size_t datalen),
131 + void (*free_fn)(void *data))
132 +{
133 + return dev_coredumpm(dev, owner, (const void *)data, datalen, gfp,
134 + (void *)read_fn, (void *)free_fn);
135 +}
136 +
137 +#define dev_coredumpm LINUX_BACKPORT(dev_coredumpm)
138 +
139 +#define dev_coredumpsg LINUX_BACKPORT(dev_coredumpsg)
140 +void dev_coredumpsg(struct device *dev, struct scatterlist *table,
141 + size_t datalen, gfp_t gfp);
142 +
143 +#endif /* (LINUX_VERSION_IS_GEQ(3,18,0) && \
144 + LINUX_VERSION_IS_LESS(4,7,0)) */
145 +
146 +#endif /* __BACKPORT_LINUX_DEVCOREDUMP_H */
147 --- a/include/linux/devcoredump.h
148 +++ b/include/linux/devcoredump.h
149 @@ -1,6 +1,7 @@
150 /* Automatically created during backport process */
151 #ifndef CPTCFG_BPAUTO_BUILD_WANT_DEV_COREDUMP
152 #include_next <linux/devcoredump.h>
153 +#include <linux/bp-devcoredump.h>
154 #else
155 #undef dev_coredumpv
156 #define dev_coredumpv LINUX_BACKPORT(dev_coredumpv)