diff options
| author | Johannes Berg <johannes.berg@intel.com> | 2017-06-16 08:29:20 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-06-16 11:48:37 -0400 |
| commit | 59ae1d127ac0ae404baf414c434ba2651b793f46 (patch) | |
| tree | 043e71496aa7a7db86bcc8219a3a51f533aac982 /net/x25 | |
| parent | b080db585384b9f037e015c0c28d1ad33be41dfc (diff) | |
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/x25')
| -rw-r--r-- | net/x25/x25_subr.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c index 6b5af65f491f..eb466ece1730 100644 --- a/net/x25/x25_subr.c +++ b/net/x25/x25_subr.c | |||
| @@ -188,17 +188,14 @@ void x25_write_internal(struct sock *sk, int frametype) | |||
| 188 | *dptr++ = X25_CALL_REQUEST; | 188 | *dptr++ = X25_CALL_REQUEST; |
| 189 | len = x25_addr_aton(addresses, &x25->dest_addr, | 189 | len = x25_addr_aton(addresses, &x25->dest_addr, |
| 190 | &x25->source_addr); | 190 | &x25->source_addr); |
| 191 | dptr = skb_put(skb, len); | 191 | dptr = skb_put_data(skb, addresses, len); |
| 192 | memcpy(dptr, addresses, len); | ||
| 193 | len = x25_create_facilities(facilities, | 192 | len = x25_create_facilities(facilities, |
| 194 | &x25->facilities, | 193 | &x25->facilities, |
| 195 | &x25->dte_facilities, | 194 | &x25->dte_facilities, |
| 196 | x25->neighbour->global_facil_mask); | 195 | x25->neighbour->global_facil_mask); |
| 197 | dptr = skb_put(skb, len); | 196 | dptr = skb_put_data(skb, facilities, len); |
| 198 | memcpy(dptr, facilities, len); | 197 | dptr = skb_put_data(skb, x25->calluserdata.cuddata, |
| 199 | dptr = skb_put(skb, x25->calluserdata.cudlength); | 198 | x25->calluserdata.cudlength); |
| 200 | memcpy(dptr, x25->calluserdata.cuddata, | ||
| 201 | x25->calluserdata.cudlength); | ||
| 202 | x25->calluserdata.cudlength = 0; | 199 | x25->calluserdata.cudlength = 0; |
| 203 | break; | 200 | break; |
| 204 | 201 | ||
| @@ -210,17 +207,15 @@ void x25_write_internal(struct sock *sk, int frametype) | |||
| 210 | &x25->facilities, | 207 | &x25->facilities, |
| 211 | &x25->dte_facilities, | 208 | &x25->dte_facilities, |
| 212 | x25->vc_facil_mask); | 209 | x25->vc_facil_mask); |
| 213 | dptr = skb_put(skb, len); | 210 | dptr = skb_put_data(skb, facilities, len); |
| 214 | memcpy(dptr, facilities, len); | ||
| 215 | 211 | ||
| 216 | /* fast select with no restriction on response | 212 | /* fast select with no restriction on response |
| 217 | allows call user data. Userland must | 213 | allows call user data. Userland must |
| 218 | ensure it is ours and not theirs */ | 214 | ensure it is ours and not theirs */ |
| 219 | if(x25->facilities.reverse & 0x80) { | 215 | if(x25->facilities.reverse & 0x80) { |
| 220 | dptr = skb_put(skb, | 216 | dptr = skb_put_data(skb, |
| 221 | x25->calluserdata.cudlength); | 217 | x25->calluserdata.cuddata, |
| 222 | memcpy(dptr, x25->calluserdata.cuddata, | 218 | x25->calluserdata.cudlength); |
| 223 | x25->calluserdata.cudlength); | ||
| 224 | } | 219 | } |
| 225 | x25->calluserdata.cudlength = 0; | 220 | x25->calluserdata.cudlength = 0; |
| 226 | break; | 221 | break; |
