]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/phonet-fix-building-with-clang.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / queue-4.19 / phonet-fix-building-with-clang.patch
1 From 02933e9d58157582e54ddc58ea792ab6f13d0317 Mon Sep 17 00:00:00 2001
2 From: Arnd Bergmann <arnd@arndb.de>
3 Date: Tue, 19 Feb 2019 22:53:50 +0100
4 Subject: phonet: fix building with clang
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 [ Upstream commit 6321aa197547da397753757bd84c6ce64b3e3d89 ]
10
11 clang warns about overflowing the data[] member in the struct pnpipehdr:
12
13 net/phonet/pep.c:295:8: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds]
14 if (hdr->data[4] == PEP_IND_READY)
15 ^ ~
16 include/net/phonet/pep.h:66:3: note: array 'data' declared here
17 u8 data[1];
18
19 Using a flexible array member at the end of the struct avoids the
20 warning, but since we cannot have a flexible array member inside
21 of the union, each index now has to be moved back by one, which
22 makes it a little uglier.
23
24 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
25 Acked-by: RĂ©mi Denis-Courmont <remi@remlab.net>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
27 Signed-off-by: Sasha Levin <sashal@kernel.org>
28 ---
29 include/net/phonet/pep.h | 5 +++--
30 net/phonet/pep.c | 32 ++++++++++++++++----------------
31 2 files changed, 19 insertions(+), 18 deletions(-)
32
33 diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
34 index b669fe6dbc3b..98f31c7ea23d 100644
35 --- a/include/net/phonet/pep.h
36 +++ b/include/net/phonet/pep.h
37 @@ -63,10 +63,11 @@ struct pnpipehdr {
38 u8 state_after_reset; /* reset request */
39 u8 error_code; /* any response */
40 u8 pep_type; /* status indication */
41 - u8 data[1];
42 + u8 data0; /* anything else */
43 };
44 + u8 data[];
45 };
46 -#define other_pep_type data[1]
47 +#define other_pep_type data[0]
48
49 static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
50 {
51 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
52 index 9fc76b19cd3c..db3473540303 100644
53 --- a/net/phonet/pep.c
54 +++ b/net/phonet/pep.c
55 @@ -132,7 +132,7 @@ static int pep_indicate(struct sock *sk, u8 id, u8 code,
56 ph->utid = 0;
57 ph->message_id = id;
58 ph->pipe_handle = pn->pipe_handle;
59 - ph->data[0] = code;
60 + ph->error_code = code;
61 return pn_skb_send(sk, skb, NULL);
62 }
63
64 @@ -153,7 +153,7 @@ static int pipe_handler_request(struct sock *sk, u8 id, u8 code,
65 ph->utid = id; /* whatever */
66 ph->message_id = id;
67 ph->pipe_handle = pn->pipe_handle;
68 - ph->data[0] = code;
69 + ph->error_code = code;
70 return pn_skb_send(sk, skb, NULL);
71 }
72
73 @@ -208,7 +208,7 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
74 struct pnpipehdr *ph;
75 struct sockaddr_pn dst;
76 u8 data[4] = {
77 - oph->data[0], /* PEP type */
78 + oph->pep_type, /* PEP type */
79 code, /* error code, at an unusual offset */
80 PAD, PAD,
81 };
82 @@ -221,7 +221,7 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
83 ph->utid = oph->utid;
84 ph->message_id = PNS_PEP_CTRL_RESP;
85 ph->pipe_handle = oph->pipe_handle;
86 - ph->data[0] = oph->data[1]; /* CTRL id */
87 + ph->data0 = oph->data[0]; /* CTRL id */
88
89 pn_skb_get_src_sockaddr(oskb, &dst);
90 return pn_skb_send(sk, skb, &dst);
91 @@ -272,17 +272,17 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
92 return -EINVAL;
93
94 hdr = pnp_hdr(skb);
95 - if (hdr->data[0] != PN_PEP_TYPE_COMMON) {
96 + if (hdr->pep_type != PN_PEP_TYPE_COMMON) {
97 net_dbg_ratelimited("Phonet unknown PEP type: %u\n",
98 - (unsigned int)hdr->data[0]);
99 + (unsigned int)hdr->pep_type);
100 return -EOPNOTSUPP;
101 }
102
103 - switch (hdr->data[1]) {
104 + switch (hdr->data[0]) {
105 case PN_PEP_IND_FLOW_CONTROL:
106 switch (pn->tx_fc) {
107 case PN_LEGACY_FLOW_CONTROL:
108 - switch (hdr->data[4]) {
109 + switch (hdr->data[3]) {
110 case PEP_IND_BUSY:
111 atomic_set(&pn->tx_credits, 0);
112 break;
113 @@ -292,7 +292,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
114 }
115 break;
116 case PN_ONE_CREDIT_FLOW_CONTROL:
117 - if (hdr->data[4] == PEP_IND_READY)
118 + if (hdr->data[3] == PEP_IND_READY)
119 atomic_set(&pn->tx_credits, wake = 1);
120 break;
121 }
122 @@ -301,12 +301,12 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
123 case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
124 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
125 break;
126 - atomic_add(wake = hdr->data[4], &pn->tx_credits);
127 + atomic_add(wake = hdr->data[3], &pn->tx_credits);
128 break;
129
130 default:
131 net_dbg_ratelimited("Phonet unknown PEP indication: %u\n",
132 - (unsigned int)hdr->data[1]);
133 + (unsigned int)hdr->data[0]);
134 return -EOPNOTSUPP;
135 }
136 if (wake)
137 @@ -318,7 +318,7 @@ static int pipe_rcv_created(struct sock *sk, struct sk_buff *skb)
138 {
139 struct pep_sock *pn = pep_sk(sk);
140 struct pnpipehdr *hdr = pnp_hdr(skb);
141 - u8 n_sb = hdr->data[0];
142 + u8 n_sb = hdr->data0;
143
144 pn->rx_fc = pn->tx_fc = PN_LEGACY_FLOW_CONTROL;
145 __skb_pull(skb, sizeof(*hdr));
146 @@ -506,7 +506,7 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
147 return -ECONNREFUSED;
148
149 /* Parse sub-blocks */
150 - n_sb = hdr->data[4];
151 + n_sb = hdr->data[3];
152 while (n_sb > 0) {
153 u8 type, buf[6], len = sizeof(buf);
154 const u8 *data = pep_get_sb(skb, &type, &len, buf);
155 @@ -739,7 +739,7 @@ static int pipe_do_remove(struct sock *sk)
156 ph->utid = 0;
157 ph->message_id = PNS_PIPE_REMOVE_REQ;
158 ph->pipe_handle = pn->pipe_handle;
159 - ph->data[0] = PAD;
160 + ph->data0 = PAD;
161 return pn_skb_send(sk, skb, NULL);
162 }
163
164 @@ -817,7 +817,7 @@ static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
165 peer_type = hdr->other_pep_type << 8;
166
167 /* Parse sub-blocks (options) */
168 - n_sb = hdr->data[4];
169 + n_sb = hdr->data[3];
170 while (n_sb > 0) {
171 u8 type, buf[1], len = sizeof(buf);
172 const u8 *data = pep_get_sb(skb, &type, &len, buf);
173 @@ -1109,7 +1109,7 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
174 ph->utid = 0;
175 if (pn->aligned) {
176 ph->message_id = PNS_PIPE_ALIGNED_DATA;
177 - ph->data[0] = 0; /* padding */
178 + ph->data0 = 0; /* padding */
179 } else
180 ph->message_id = PNS_PIPE_DATA;
181 ph->pipe_handle = pn->pipe_handle;
182 --
183 2.19.1
184