Skip to content

Commit f763b9d

Browse files
committed
Remove dead stores and dengerous initialisation
1 parent 3ed0fd9 commit f763b9d

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

tempesta_fw/msg.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@
3434
int
3535
tfw_msg_write(TfwMsgIter *it, const TfwStr *data)
3636
{
37-
char *p;
3837
const TfwStr *c, *end;
39-
skb_frag_t *frag = &skb_shinfo(it->skb)->frags[it->frag];
40-
unsigned int c_off = 0, f_size, c_size, f_room, n_copy;
4138

4239
BUG_ON(TFW_STR_DUP(data));
40+
if (WARN_ON_ONCE(it->frag >= skb_shinfo(it->skb)->nr_frags))
41+
return -E2BIG;
42+
4343
TFW_STR_FOR_EACH_CHUNK(c, data, end) {
44+
char *p;
45+
unsigned int c_off = 0, c_size, f_room, n_copy;
4446
this_chunk:
45-
if (!frag)
46-
return -E2BIG;
4747

4848
c_size = c->len - c_off;
4949
if (it->frag >= 0) {
50-
frag = &skb_shinfo(it->skb)->frags[it->frag];
50+
unsigned int f_size;
51+
skb_frag_t *frag = &skb_shinfo(it->skb)->frags[it->frag];
52+
5153
f_size = skb_frag_size(frag);
5254
f_room = PAGE_SIZE - frag->page_offset - f_size;
5355
p = (char *)skb_frag_address(frag) + f_size;
@@ -62,24 +64,25 @@ tfw_msg_write(TfwMsgIter *it, const TfwStr *data)
6264

6365
memcpy_fast(p, c->data + c_off, n_copy);
6466

65-
if (c_size < f_room) {
66-
/*
67-
* The chunk fits in the SKB fragment with room
68-
* to spare. Stay in the same SKB fragment, switch
69-
* to next chunk of the string.
70-
*/
71-
c_off = 0;
72-
} else {
73-
frag = ss_skb_frag_next(&it->skb, it->skb_head,
74-
&it->frag);
67+
/*
68+
* The chunk occupied all the spare space in the SKB fragment,
69+
* switch to the next fragment.
70+
*/
71+
if (c_size >= f_room) {
72+
skb_frag_t *frag = ss_skb_frag_next(&it->skb,
73+
it->skb_head,
74+
&it->frag);
75+
if (unlikely(!frag)
76+
&& ((c_size != f_room) || (c + 1 < end)))
77+
{
78+
return -E2BIG;
79+
}
7580
/*
76-
* If all data from the chunk has been copied,
77-
* then switch to the next chunk. Otherwise,
78-
* stay in the current chunk.
81+
* Not all data from the chunk has been copied,
82+
* stay in the current chunk and copy the rest to the
83+
* next fragment.
7984
*/
80-
if (c_size == f_room) {
81-
c_off = 0;
82-
} else {
85+
if (c_size != f_room) {
8386
c_off += n_copy;
8487
goto this_chunk;
8588
}

0 commit comments

Comments
 (0)