Skip to content

Commit 6321aa1

Browse files
arndbdavem330
authored andcommitted
phonet: fix building with clang
clang warns about overflowing the data[] member in the struct pnpipehdr: net/phonet/pep.c:295:8: warning: array index 4 is past the end of the array (which contains 1 element) [-Warray-bounds] if (hdr->data[4] == PEP_IND_READY) ^ ~ include/net/phonet/pep.h:66:3: note: array 'data' declared here u8 data[1]; Using a flexible array member at the end of the struct avoids the warning, but since we cannot have a flexible array member inside of the union, each index now has to be moved back by one, which makes it a little uglier. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Rémi Denis-Courmont <remi@remlab.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b35560e commit 6321aa1

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

include/net/phonet/pep.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ struct pnpipehdr {
6363
u8 state_after_reset; /* reset request */
6464
u8 error_code; /* any response */
6565
u8 pep_type; /* status indication */
66-
u8 data[1];
66+
u8 data0; /* anything else */
6767
};
68+
u8 data[];
6869
};
69-
#define other_pep_type data[1]
70+
#define other_pep_type data[0]
7071

7172
static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
7273
{

net/phonet/pep.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int pep_indicate(struct sock *sk, u8 id, u8 code,
132132
ph->utid = 0;
133133
ph->message_id = id;
134134
ph->pipe_handle = pn->pipe_handle;
135-
ph->data[0] = code;
135+
ph->error_code = code;
136136
return pn_skb_send(sk, skb, NULL);
137137
}
138138

@@ -153,7 +153,7 @@ static int pipe_handler_request(struct sock *sk, u8 id, u8 code,
153153
ph->utid = id; /* whatever */
154154
ph->message_id = id;
155155
ph->pipe_handle = pn->pipe_handle;
156-
ph->data[0] = code;
156+
ph->error_code = code;
157157
return pn_skb_send(sk, skb, NULL);
158158
}
159159

@@ -208,7 +208,7 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
208208
struct pnpipehdr *ph;
209209
struct sockaddr_pn dst;
210210
u8 data[4] = {
211-
oph->data[0], /* PEP type */
211+
oph->pep_type, /* PEP type */
212212
code, /* error code, at an unusual offset */
213213
PAD, PAD,
214214
};
@@ -221,7 +221,7 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
221221
ph->utid = oph->utid;
222222
ph->message_id = PNS_PEP_CTRL_RESP;
223223
ph->pipe_handle = oph->pipe_handle;
224-
ph->data[0] = oph->data[1]; /* CTRL id */
224+
ph->data0 = oph->data[0]; /* CTRL id */
225225

226226
pn_skb_get_src_sockaddr(oskb, &dst);
227227
return pn_skb_send(sk, skb, &dst);
@@ -272,17 +272,17 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
272272
return -EINVAL;
273273

274274
hdr = pnp_hdr(skb);
275-
if (hdr->data[0] != PN_PEP_TYPE_COMMON) {
275+
if (hdr->pep_type != PN_PEP_TYPE_COMMON) {
276276
net_dbg_ratelimited("Phonet unknown PEP type: %u\n",
277-
(unsigned int)hdr->data[0]);
277+
(unsigned int)hdr->pep_type);
278278
return -EOPNOTSUPP;
279279
}
280280

281-
switch (hdr->data[1]) {
281+
switch (hdr->data[0]) {
282282
case PN_PEP_IND_FLOW_CONTROL:
283283
switch (pn->tx_fc) {
284284
case PN_LEGACY_FLOW_CONTROL:
285-
switch (hdr->data[4]) {
285+
switch (hdr->data[3]) {
286286
case PEP_IND_BUSY:
287287
atomic_set(&pn->tx_credits, 0);
288288
break;
@@ -292,7 +292,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
292292
}
293293
break;
294294
case PN_ONE_CREDIT_FLOW_CONTROL:
295-
if (hdr->data[4] == PEP_IND_READY)
295+
if (hdr->data[3] == PEP_IND_READY)
296296
atomic_set(&pn->tx_credits, wake = 1);
297297
break;
298298
}
@@ -301,12 +301,12 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
301301
case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
302302
if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
303303
break;
304-
atomic_add(wake = hdr->data[4], &pn->tx_credits);
304+
atomic_add(wake = hdr->data[3], &pn->tx_credits);
305305
break;
306306

307307
default:
308308
net_dbg_ratelimited("Phonet unknown PEP indication: %u\n",
309-
(unsigned int)hdr->data[1]);
309+
(unsigned int)hdr->data[0]);
310310
return -EOPNOTSUPP;
311311
}
312312
if (wake)
@@ -318,7 +318,7 @@ static int pipe_rcv_created(struct sock *sk, struct sk_buff *skb)
318318
{
319319
struct pep_sock *pn = pep_sk(sk);
320320
struct pnpipehdr *hdr = pnp_hdr(skb);
321-
u8 n_sb = hdr->data[0];
321+
u8 n_sb = hdr->data0;
322322

323323
pn->rx_fc = pn->tx_fc = PN_LEGACY_FLOW_CONTROL;
324324
__skb_pull(skb, sizeof(*hdr));
@@ -506,7 +506,7 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
506506
return -ECONNREFUSED;
507507

508508
/* Parse sub-blocks */
509-
n_sb = hdr->data[4];
509+
n_sb = hdr->data[3];
510510
while (n_sb > 0) {
511511
u8 type, buf[6], len = sizeof(buf);
512512
const u8 *data = pep_get_sb(skb, &type, &len, buf);
@@ -739,7 +739,7 @@ static int pipe_do_remove(struct sock *sk)
739739
ph->utid = 0;
740740
ph->message_id = PNS_PIPE_REMOVE_REQ;
741741
ph->pipe_handle = pn->pipe_handle;
742-
ph->data[0] = PAD;
742+
ph->data0 = PAD;
743743
return pn_skb_send(sk, skb, NULL);
744744
}
745745

@@ -817,7 +817,7 @@ static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
817817
peer_type = hdr->other_pep_type << 8;
818818

819819
/* Parse sub-blocks (options) */
820-
n_sb = hdr->data[4];
820+
n_sb = hdr->data[3];
821821
while (n_sb > 0) {
822822
u8 type, buf[1], len = sizeof(buf);
823823
const u8 *data = pep_get_sb(skb, &type, &len, buf);
@@ -1109,7 +1109,7 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
11091109
ph->utid = 0;
11101110
if (pn->aligned) {
11111111
ph->message_id = PNS_PIPE_ALIGNED_DATA;
1112-
ph->data[0] = 0; /* padding */
1112+
ph->data0 = 0; /* padding */
11131113
} else
11141114
ph->message_id = PNS_PIPE_DATA;
11151115
ph->pipe_handle = pn->pipe_handle;

0 commit comments

Comments
 (0)