34
34
int
35
35
tfw_msg_write (TfwMsgIter * it , const TfwStr * data )
36
36
{
37
- char * p ;
38
37
const TfwStr * c , * end ;
39
- skb_frag_t * frag ;
40
- unsigned int c_off = 0 , f_size , c_size , f_room , n_copy ;
41
38
42
39
BUG_ON (TFW_STR_DUP (data ));
40
+ if (WARN_ON_ONCE (it -> frag >= skb_shinfo (it -> skb )-> nr_frags ))
41
+ return - E2BIG ;
42
+
43
43
TFW_STR_FOR_EACH_CHUNK (c , data , end ) {
44
+ char * p ;
45
+ unsigned int c_off = 0 , c_size , f_room , n_copy ;
44
46
this_chunk :
45
- if (!frag )
46
- return - E2BIG ;
47
47
48
48
c_size = c -> len - c_off ;
49
49
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
+
51
53
f_size = skb_frag_size (frag );
52
54
f_room = PAGE_SIZE - frag -> page_offset - f_size ;
53
55
p = (char * )skb_frag_address (frag ) + f_size ;
@@ -62,24 +64,26 @@ tfw_msg_write(TfwMsgIter *it, const TfwStr *data)
62
64
63
65
memcpy_fast (p , c -> data + c_off , n_copy );
64
66
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 (WARN_ON_ONCE (!frag
76
+ && ((c_size != f_room )
77
+ || (c + 1 < end ))))
78
+ {
79
+ return - E2BIG ;
80
+ }
75
81
/*
76
- * If all data from the chunk has been copied,
77
- * then switch to the next chunk. Otherwise,
78
- * stay in the current chunk .
82
+ * Not all data from the chunk has been copied,
83
+ * stay in the current chunk and copy the rest to the
84
+ * next fragment .
79
85
*/
80
- if (c_size == f_room ) {
81
- c_off = 0 ;
82
- } else {
86
+ if (c_size != f_room ) {
83
87
c_off += n_copy ;
84
88
goto this_chunk ;
85
89
}
0 commit comments