Unified · Split
| @@ -693,13 +693,13 @@ rx_starttimer: · 692 unmodified lines | ||
| 693 | 693 | /* |
| 694 | 694 | * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements |
| 695 | 695 | */ |
| 696 | −static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id, | |
| 697 | − int ifindex) | |
| 696 | +static struct bcm_op *bcm_find_op(struct list_head *ops, | |
| 697 | + struct bcm_msg_head *mh, int ifindex) | |
| 698 | 698 | { |
| 699 | 699 | struct bcm_op *op; |
| 700 | 700 | |
| 701 | 701 | list_for_each_entry(op, ops, list) { |
| 702 | − if ((op->can_id == can_id) && (op->ifindex == ifindex)) | |
| 702 | + if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) | |
| 703 | 703 | return op; |
| 704 | 704 | } |
| 705 | 705 | |
| @@ -742,12 +742,13 @@ static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op) · 36 unmodified lines | ||
| 742 | 742 | /* |
| 743 | 743 | * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops) |
| 744 | 744 | */ |
| 745 | −static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex) | |
| 745 | +static int bcm_delete_rx_op(struct list_head *ops, struct bcm_msg_head *mh, | |
| 746 | + int ifindex) | |
| 746 | 747 | { |
| 747 | 748 | struct bcm_op *op, *n; |
| 748 | 749 | |
| 749 | 750 | list_for_each_entry_safe(op, n, ops, list) { |
| 750 | − if ((op->can_id == can_id) && (op->ifindex == ifindex)) { | |
| 751 | + if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) { | |
| 751 | 752 | |
| 752 | 753 | /* |
| 753 | 754 | * Don't care if we're bound or not (due to netdev |
| @@ -787,12 +788,13 @@ static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex) · 33 unmodified lines | ||
| 787 | 788 | /* |
| 788 | 789 | * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops) |
| 789 | 790 | */ |
| 790 | −static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex) | |
| 791 | +static int bcm_delete_tx_op(struct list_head *ops, struct bcm_msg_head *mh, | |
| 792 | + int ifindex) | |
| 791 | 793 | { |
| 792 | 794 | struct bcm_op *op, *n; |
| 793 | 795 | |
| 794 | 796 | list_for_each_entry_safe(op, n, ops, list) { |
| 795 | − if ((op->can_id == can_id) && (op->ifindex == ifindex)) { | |
| 797 | + if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) { | |
| 796 | 798 | list_del(&op->list); |
| 797 | 799 | bcm_remove_op(op); |
| 798 | 800 | return 1; /* done */ |
| @@ -808,7 +810,7 @@ static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex) · 9 unmodified lines | ||
| 808 | 810 | static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head, |
| 809 | 811 | int ifindex) |
| 810 | 812 | { |
| 811 | − struct bcm_op *op = bcm_find_op(ops, msg_head->can_id, ifindex); | |
| 813 | + struct bcm_op *op = bcm_find_op(ops, msg_head, ifindex); | |
| 812 | 814 | |
| 813 | 815 | if (!op) |
| 814 | 816 | return -EINVAL; |
| @@ -845,8 +847,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 30 unmodified lines | ||
| 845 | 847 | return -EINVAL; |
| 846 | 848 | |
| 847 | 849 | /* check the given can_id */ |
| 848 | − op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex); | |
| 849 | − | |
| 850 | + op = bcm_find_op(&bo->tx_ops, msg_head, ifindex); | |
| 850 | 851 | if (op) { |
| 851 | 852 | /* update existing BCM operation */ |
| 852 | 853 | |
| @@ -1010,7 +1011,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 157 unmodified lines | ||
| 1010 | 1011 | return -EINVAL; |
| 1011 | 1012 | |
| 1012 | 1013 | /* check the given can_id */ |
| 1013 | − op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex); | |
| 1014 | + op = bcm_find_op(&bo->rx_ops, msg_head, ifindex); | |
| 1014 | 1015 | if (op) { |
| 1015 | 1016 | /* update existing BCM operation */ |
| 1016 | 1017 | |
| @@ -1192,7 +1193,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 175 unmodified lines | ||
| 1192 | 1193 | /* |
| 1193 | 1194 | * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg) |
| 1194 | 1195 | */ |
| 1195 | −static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) | |
| 1196 | +static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk, | |
| 1197 | + int cfsiz) | |
| 1196 | 1198 | { |
| 1197 | 1199 | struct sk_buff *skb; |
| 1198 | 1200 | struct net_device *dev; |
| @@ -1202,13 +1204,13 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) · 3 unmodified lines | ||
| 1202 | 1204 | if (!ifindex) |
| 1203 | 1205 | return -ENODEV; |
| 1204 | 1206 | |
| 1205 | − skb = alloc_skb(CFSIZ + sizeof(struct can_skb_priv), GFP_KERNEL); | |
| 1207 | + skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), GFP_KERNEL); | |
| 1206 | 1208 | if (!skb) |
| 1207 | 1209 | return -ENOMEM; |
| 1208 | 1210 | |
| 1209 | 1211 | can_skb_reserve(skb); |
| 1210 | 1212 | |
| 1211 | − err = memcpy_from_msg(skb_put(skb, CFSIZ), msg, CFSIZ); | |
| 1213 | + err = memcpy_from_msg(skb_put(skb, cfsiz), msg, cfsiz); | |
| 1212 | 1214 | if (err < 0) { |
| 1213 | 1215 | kfree_skb(skb); |
| 1214 | 1216 | return err; |
| @@ -1230,7 +1232,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) · 15 unmodified lines | ||
| 1230 | 1232 | if (err) |
| 1231 | 1233 | return err; |
| 1232 | 1234 | |
| 1233 | − return CFSIZ + MHSIZ; | |
| 1235 | + return cfsiz + MHSIZ; | |
| 1234 | 1236 | } |
| 1235 | 1237 | |
| 1236 | 1238 | /* |
| @@ -1248,7 +1250,15 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 11 unmodified lines | ||
| 1248 | 1250 | return -ENOTCONN; |
| 1249 | 1251 | |
| 1250 | 1252 | /* check for valid message length from userspace */ |
| 1251 | − if (size < MHSIZ || (size - MHSIZ) % CFSIZ) | |
| 1253 | + if (size < MHSIZ) | |
| 1254 | + return -EINVAL; | |
| 1255 | + | |
| 1256 | + /* read message head information */ | |
| 1257 | + ret = memcpy_from_msg((u8 *)&msg_head, msg, MHSIZ); | |
| 1258 | + if (ret < 0) | |
| 1259 | + return ret; | |
| 1260 | + | |
| 1261 | + if ((size - MHSIZ) % CFSIZ) | |
| 1252 | 1262 | return -EINVAL; |
| 1253 | 1263 | |
| 1254 | 1264 | /* check for alternative ifindex for this bcm_op */ |
| @@ -1282,12 +1292,6 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 27 unmodified lines | ||
| 1282 | 1292 | } |
| 1283 | 1293 | } |
| 1284 | 1294 | |
| 1285 | − /* read message head information */ | |
| 1286 | − | |
| 1287 | − ret = memcpy_from_msg((u8 *)&msg_head, msg, MHSIZ); | |
| 1288 | − if (ret < 0) | |
| 1289 | − return ret; | |
| 1290 | − | |
| 1291 | 1295 | lock_sock(sk); |
| 1292 | 1296 | |
| 1293 | 1297 | switch (msg_head.opcode) { |
| @@ -1301,14 +1305,14 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 7 unmodified lines | ||
| 1301 | 1305 | break; |
| 1302 | 1306 | |
| 1303 | 1307 | case TX_DELETE: |
| 1304 | − if (bcm_delete_tx_op(&bo->tx_ops, msg_head.can_id, ifindex)) | |
| 1308 | + if (bcm_delete_tx_op(&bo->tx_ops, &msg_head, ifindex)) | |
| 1305 | 1309 | ret = MHSIZ; |
| 1306 | 1310 | else |
| 1307 | 1311 | ret = -EINVAL; |
| 1308 | 1312 | break; |
| 1309 | 1313 | |
| 1310 | 1314 | case RX_DELETE: |
| 1311 | − if (bcm_delete_rx_op(&bo->rx_ops, msg_head.can_id, ifindex)) | |
| 1315 | + if (bcm_delete_rx_op(&bo->rx_ops, &msg_head, ifindex)) | |
| 1312 | 1316 | ret = MHSIZ; |
| 1313 | 1317 | else |
| 1314 | 1318 | ret = -EINVAL; |
| @@ -1331,7 +1335,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 16 unmodified lines | ||
| 1331 | 1335 | if ((msg_head.nframes != 1) || (size != CFSIZ + MHSIZ)) |
| 1332 | 1336 | ret = -EINVAL; |
| 1333 | 1337 | else |
| 1334 | − ret = bcm_tx_send(msg, ifindex, sk); | |
| 1338 | + ret = bcm_tx_send(msg, ifindex, sk, CFSIZ); | |
| 1335 | 1339 | break; |
| 1336 | 1340 | |
| 1337 | 1341 | default: |