Skip to content

Commit 8c83c88

Browse files
committed
Merge branch 'sctp-endianness-fixes'
Xin Long says: ==================== sctp: a bunch of fixes for some sparse warnings As Eric noticed, when running 'make C=2 M=net/sctp/', a plenty of warnings or errors checked by sparse appear. They are all problems about Endian and type cast. Most of them are just warnings by which no issues could be caused while some might be bugs. This patchset fixes them with four patches basically according to how they are introduced. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 50317fc + 978aa04 commit 8c83c88

File tree

10 files changed

+59
-50
lines changed

10 files changed

+59
-50
lines changed

include/linux/sctp.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct sctp_datahdr {
231231
__be32 tsn;
232232
__be16 stream;
233233
__be16 ssn;
234-
__be32 ppid;
234+
__u32 ppid;
235235
__u8 payload[0];
236236
};
237237

@@ -716,28 +716,28 @@ struct sctp_reconf_chunk {
716716

717717
struct sctp_strreset_outreq {
718718
struct sctp_paramhdr param_hdr;
719-
__u32 request_seq;
720-
__u32 response_seq;
721-
__u32 send_reset_at_tsn;
722-
__u16 list_of_streams[0];
719+
__be32 request_seq;
720+
__be32 response_seq;
721+
__be32 send_reset_at_tsn;
722+
__be16 list_of_streams[0];
723723
};
724724

725725
struct sctp_strreset_inreq {
726726
struct sctp_paramhdr param_hdr;
727-
__u32 request_seq;
728-
__u16 list_of_streams[0];
727+
__be32 request_seq;
728+
__be16 list_of_streams[0];
729729
};
730730

731731
struct sctp_strreset_tsnreq {
732732
struct sctp_paramhdr param_hdr;
733-
__u32 request_seq;
733+
__be32 request_seq;
734734
};
735735

736736
struct sctp_strreset_addstrm {
737737
struct sctp_paramhdr param_hdr;
738-
__u32 request_seq;
739-
__u16 number_of_streams;
740-
__u16 reserved;
738+
__be32 request_seq;
739+
__be16 number_of_streams;
740+
__be16 reserved;
741741
};
742742

743743
enum {
@@ -752,16 +752,16 @@ enum {
752752

753753
struct sctp_strreset_resp {
754754
struct sctp_paramhdr param_hdr;
755-
__u32 response_seq;
756-
__u32 result;
755+
__be32 response_seq;
756+
__be32 result;
757757
};
758758

759759
struct sctp_strreset_resptsn {
760760
struct sctp_paramhdr param_hdr;
761-
__u32 response_seq;
762-
__u32 result;
763-
__u32 senders_next_tsn;
764-
__u32 receivers_next_tsn;
761+
__be32 response_seq;
762+
__be32 result;
763+
__be32 senders_next_tsn;
764+
__be32 receivers_next_tsn;
765765
};
766766

767767
#endif /* __LINUX_SCTP_H__ */

include/net/sctp/sm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
261261
struct sctp_fwdtsn_skip *skiplist);
262262
struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc);
263263
struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc,
264-
__u16 stream_num, __u16 *stream_list,
264+
__u16 stream_num, __be16 *stream_list,
265265
bool out, bool in);
266266
struct sctp_chunk *sctp_make_strreset_tsnreq(
267267
const struct sctp_association *asoc);

include/net/sctp/ulpevent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
130130

131131
struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
132132
const struct sctp_association *asoc, __u16 flags,
133-
__u16 stream_num, __u16 *stream_list, gfp_t gfp);
133+
__u16 stream_num, __be16 *stream_list, gfp_t gfp);
134134

135135
struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
136136
const struct sctp_association *asoc, __u16 flags,

include/uapi/linux/sctp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ struct sctp_remote_error {
376376
__u16 sre_type;
377377
__u16 sre_flags;
378378
__u32 sre_length;
379-
__u16 sre_error;
379+
__be16 sre_error;
380380
sctp_assoc_t sre_assoc_id;
381381
__u8 sre_data[0];
382382
};

net/sctp/input.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
794794
struct sctp_hash_cmp_arg {
795795
const union sctp_addr *paddr;
796796
const struct net *net;
797-
u16 lport;
797+
__be16 lport;
798798
};
799799

800800
static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
@@ -820,37 +820,37 @@ static inline int sctp_hash_cmp(struct rhashtable_compare_arg *arg,
820820
return err;
821821
}
822822

823-
static inline u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
823+
static inline __u32 sctp_hash_obj(const void *data, u32 len, u32 seed)
824824
{
825825
const struct sctp_transport *t = data;
826826
const union sctp_addr *paddr = &t->ipaddr;
827827
const struct net *net = sock_net(t->asoc->base.sk);
828-
u16 lport = htons(t->asoc->base.bind_addr.port);
829-
u32 addr;
828+
__be16 lport = htons(t->asoc->base.bind_addr.port);
829+
__u32 addr;
830830

831831
if (paddr->sa.sa_family == AF_INET6)
832832
addr = jhash(&paddr->v6.sin6_addr, 16, seed);
833833
else
834-
addr = paddr->v4.sin_addr.s_addr;
834+
addr = (__force __u32)paddr->v4.sin_addr.s_addr;
835835

836-
return jhash_3words(addr, ((__u32)paddr->v4.sin_port) << 16 |
836+
return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
837837
(__force __u32)lport, net_hash_mix(net), seed);
838838
}
839839

840-
static inline u32 sctp_hash_key(const void *data, u32 len, u32 seed)
840+
static inline __u32 sctp_hash_key(const void *data, u32 len, u32 seed)
841841
{
842842
const struct sctp_hash_cmp_arg *x = data;
843843
const union sctp_addr *paddr = x->paddr;
844844
const struct net *net = x->net;
845-
u16 lport = x->lport;
846-
u32 addr;
845+
__be16 lport = x->lport;
846+
__u32 addr;
847847

848848
if (paddr->sa.sa_family == AF_INET6)
849849
addr = jhash(&paddr->v6.sin6_addr, 16, seed);
850850
else
851-
addr = paddr->v4.sin_addr.s_addr;
851+
addr = (__force __u32)paddr->v4.sin_addr.s_addr;
852852

853-
return jhash_3words(addr, ((__u32)paddr->v4.sin_port) << 16 |
853+
return jhash_3words(addr, ((__force __u32)paddr->v4.sin_port) << 16 |
854854
(__force __u32)lport, net_hash_mix(net), seed);
855855
}
856856

net/sctp/ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static int sctp_v6_skb_iif(const struct sk_buff *skb)
738738
/* Was this packet marked by Explicit Congestion Notification? */
739739
static int sctp_v6_is_ce(const struct sk_buff *skb)
740740
{
741-
return *((__u32 *)(ipv6_hdr(skb))) & htonl(1 << 20);
741+
return *((__u32 *)(ipv6_hdr(skb))) & (__force __u32)htonl(1 << 20);
742742
}
743743

744744
/* Dump the v6 addr to the seq file. */

net/sctp/sm_make_chunk.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
28542854
addr_param_len = af->to_addr_param(addr, &addr_param);
28552855
param.param_hdr.type = flags;
28562856
param.param_hdr.length = htons(paramlen + addr_param_len);
2857-
param.crr_id = i;
2857+
param.crr_id = htonl(i);
28582858

28592859
sctp_addto_chunk(retval, paramlen, &param);
28602860
sctp_addto_chunk(retval, addr_param_len, &addr_param);
@@ -2867,7 +2867,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
28672867
addr_param_len = af->to_addr_param(addr, &addr_param);
28682868
param.param_hdr.type = SCTP_PARAM_DEL_IP;
28692869
param.param_hdr.length = htons(paramlen + addr_param_len);
2870-
param.crr_id = i;
2870+
param.crr_id = htonl(i);
28712871

28722872
sctp_addto_chunk(retval, paramlen, &param);
28732873
sctp_addto_chunk(retval, addr_param_len, &addr_param);
@@ -3591,7 +3591,7 @@ static struct sctp_chunk *sctp_make_reconf(const struct sctp_association *asoc,
35913591
*/
35923592
struct sctp_chunk *sctp_make_strreset_req(
35933593
const struct sctp_association *asoc,
3594-
__u16 stream_num, __u16 *stream_list,
3594+
__u16 stream_num, __be16 *stream_list,
35953595
bool out, bool in)
35963596
{
35973597
struct sctp_strreset_outreq outreq;
@@ -3788,7 +3788,8 @@ bool sctp_verify_reconf(const struct sctp_association *asoc,
37883788
{
37893789
struct sctp_reconf_chunk *hdr;
37903790
union sctp_params param;
3791-
__u16 last = 0, cnt = 0;
3791+
__be16 last = 0;
3792+
__u16 cnt = 0;
37923793

37933794
hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
37943795
sctp_walk_params(param, hdr, params) {

net/sctp/sm_sideeffect.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,12 +1607,12 @@ static int sctp_cmd_interpreter(enum sctp_event event_type,
16071607
break;
16081608

16091609
case SCTP_CMD_INIT_FAILED:
1610-
sctp_cmd_init_failed(commands, asoc, cmd->obj.err);
1610+
sctp_cmd_init_failed(commands, asoc, cmd->obj.u32);
16111611
break;
16121612

16131613
case SCTP_CMD_ASSOC_FAILED:
16141614
sctp_cmd_assoc_failed(commands, asoc, event_type,
1615-
subtype, chunk, cmd->obj.err);
1615+
subtype, chunk, cmd->obj.u32);
16161616
break;
16171617

16181618
case SCTP_CMD_INIT_COUNTER_INC:
@@ -1680,8 +1680,8 @@ static int sctp_cmd_interpreter(enum sctp_event event_type,
16801680
case SCTP_CMD_PROCESS_CTSN:
16811681
/* Dummy up a SACK for processing. */
16821682
sackh.cum_tsn_ack = cmd->obj.be32;
1683-
sackh.a_rwnd = asoc->peer.rwnd +
1684-
asoc->outqueue.outstanding_bytes;
1683+
sackh.a_rwnd = htonl(asoc->peer.rwnd +
1684+
asoc->outqueue.outstanding_bytes);
16851685
sackh.num_gap_ack_blocks = 0;
16861686
sackh.num_dup_tsns = 0;
16871687
chunk->subh.sack_hdr = &sackh;

net/sctp/stream.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
118118
__u16 i, str_nums, *str_list;
119119
struct sctp_chunk *chunk;
120120
int retval = -EINVAL;
121+
__be16 *nstr_list;
121122
bool out, in;
122123

123124
if (!asoc->peer.reconf_capable ||
@@ -148,13 +149,18 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
148149
if (str_list[i] >= stream->incnt)
149150
goto out;
150151

152+
nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
153+
if (!nstr_list) {
154+
retval = -ENOMEM;
155+
goto out;
156+
}
157+
151158
for (i = 0; i < str_nums; i++)
152-
str_list[i] = htons(str_list[i]);
159+
nstr_list[i] = htons(str_list[i]);
153160

154-
chunk = sctp_make_strreset_req(asoc, str_nums, str_list, out, in);
161+
chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
155162

156-
for (i = 0; i < str_nums; i++)
157-
str_list[i] = ntohs(str_list[i]);
163+
kfree(nstr_list);
158164

159165
if (!chunk) {
160166
retval = -ENOMEM;
@@ -305,7 +311,7 @@ int sctp_send_add_streams(struct sctp_association *asoc,
305311
}
306312

307313
static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
308-
struct sctp_association *asoc, __u32 resp_seq,
314+
struct sctp_association *asoc, __be32 resp_seq,
309315
__be16 type)
310316
{
311317
struct sctp_chunk *chunk = asoc->strreset_chunk;
@@ -345,8 +351,9 @@ struct sctp_chunk *sctp_process_strreset_outreq(
345351
{
346352
struct sctp_strreset_outreq *outreq = param.v;
347353
struct sctp_stream *stream = &asoc->stream;
348-
__u16 i, nums, flags = 0, *str_p = NULL;
349354
__u32 result = SCTP_STRRESET_DENIED;
355+
__u16 i, nums, flags = 0;
356+
__be16 *str_p = NULL;
350357
__u32 request_seq;
351358

352359
request_seq = ntohl(outreq->request_seq);
@@ -439,8 +446,9 @@ struct sctp_chunk *sctp_process_strreset_inreq(
439446
struct sctp_stream *stream = &asoc->stream;
440447
__u32 result = SCTP_STRRESET_DENIED;
441448
struct sctp_chunk *chunk = NULL;
442-
__u16 i, nums, *str_p;
443449
__u32 request_seq;
450+
__u16 i, nums;
451+
__be16 *str_p;
444452

445453
request_seq = ntohl(inreq->request_seq);
446454
if (TSN_lt(asoc->strreset_inseq, request_seq) ||
@@ -769,7 +777,7 @@ struct sctp_chunk *sctp_process_strreset_resp(
769777

770778
if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
771779
struct sctp_strreset_outreq *outreq;
772-
__u16 *str_p;
780+
__be16 *str_p;
773781

774782
outreq = (struct sctp_strreset_outreq *)req;
775783
str_p = outreq->list_of_streams;
@@ -794,7 +802,7 @@ struct sctp_chunk *sctp_process_strreset_resp(
794802
nums, str_p, GFP_ATOMIC);
795803
} else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) {
796804
struct sctp_strreset_inreq *inreq;
797-
__u16 *str_p;
805+
__be16 *str_p;
798806

799807
/* if the result is performed, it's impossible for inreq */
800808
if (result == SCTP_STRRESET_PERFORMED)

net/sctp/ulpevent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
847847

848848
struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
849849
const struct sctp_association *asoc, __u16 flags, __u16 stream_num,
850-
__u16 *stream_list, gfp_t gfp)
850+
__be16 *stream_list, gfp_t gfp)
851851
{
852852
struct sctp_stream_reset_event *sreset;
853853
struct sctp_ulpevent *event;

0 commit comments

Comments
 (0)