Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: bcm: unify bcm_msg_head handling and prepare function parameters

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Oliver Hartkopp and committed by
Marc Kleine-Budde
2b5f5f5d 72c8a89a

+29 -25
+29 -25
net/can/bcm.c
··· 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 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 ··· 788 787 /* 789 788 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops) 790 789 */ 791 - static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex) 790 + static int bcm_delete_tx_op(struct list_head *ops, struct bcm_msg_head *mh, 791 + int ifindex) 792 792 { 793 793 struct bcm_op *op, *n; 794 794 795 795 list_for_each_entry_safe(op, n, ops, list) { 796 - if ((op->can_id == can_id) && (op->ifindex == ifindex)) { 796 + if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) { 797 797 list_del(&op->list); 798 798 bcm_remove_op(op); 799 799 return 1; /* done */ ··· 810 808 static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head, 811 809 int ifindex) 812 810 { 813 - struct bcm_op *op = bcm_find_op(ops, msg_head->can_id, ifindex); 811 + struct bcm_op *op = bcm_find_op(ops, msg_head, ifindex); 814 812 815 813 if (!op) 816 814 return -EINVAL; ··· 847 845 return -EINVAL; 848 846 849 847 /* check the given can_id */ 850 - op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex); 851 - 848 + op = bcm_find_op(&bo->tx_ops, msg_head, ifindex); 852 849 if (op) { 853 850 /* update existing BCM operation */ 854 851 ··· 1011 1010 return -EINVAL; 1012 1011 1013 1012 /* check the given can_id */ 1014 - op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex); 1013 + op = bcm_find_op(&bo->rx_ops, msg_head, ifindex); 1015 1014 if (op) { 1016 1015 /* update existing BCM operation */ 1017 1016 ··· 1193 1192 /* 1194 1193 * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg) 1195 1194 */ 1196 - static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) 1195 + static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk, 1196 + int cfsiz) 1197 1197 { 1198 1198 struct sk_buff *skb; 1199 1199 struct net_device *dev; ··· 1204 1202 if (!ifindex) 1205 1203 return -ENODEV; 1206 1204 1207 - skb = alloc_skb(CFSIZ + sizeof(struct can_skb_priv), GFP_KERNEL); 1205 + skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), GFP_KERNEL); 1208 1206 if (!skb) 1209 1207 return -ENOMEM; 1210 1208 1211 1209 can_skb_reserve(skb); 1212 1210 1213 - err = memcpy_from_msg(skb_put(skb, CFSIZ), msg, CFSIZ); 1211 + err = memcpy_from_msg(skb_put(skb, cfsiz), msg, cfsiz); 1214 1212 if (err < 0) { 1215 1213 kfree_skb(skb); 1216 1214 return err; ··· 1232 1230 if (err) 1233 1231 return err; 1234 1232 1235 - return CFSIZ + MHSIZ; 1233 + return cfsiz + MHSIZ; 1236 1234 } 1237 1235 1238 1236 /* ··· 1250 1248 return -ENOTCONN; 1251 1249 1252 1250 /* check for valid message length from userspace */ 1253 - if (size < MHSIZ || (size - MHSIZ) % CFSIZ) 1251 + if (size < MHSIZ) 1252 + return -EINVAL; 1253 + 1254 + /* read message head information */ 1255 + ret = memcpy_from_msg((u8 *)&msg_head, msg, MHSIZ); 1256 + if (ret < 0) 1257 + return ret; 1258 + 1259 + if ((size - MHSIZ) % CFSIZ) 1254 1260 return -EINVAL; 1255 1261 1256 1262 /* check for alternative ifindex for this bcm_op */ ··· 1292 1282 } 1293 1283 } 1294 1284 1295 - /* read message head information */ 1296 - 1297 - ret = memcpy_from_msg((u8 *)&msg_head, msg, MHSIZ); 1298 - if (ret < 0) 1299 - return ret; 1300 - 1301 1285 lock_sock(sk); 1302 1286 1303 1287 switch (msg_head.opcode) { ··· 1305 1301 break; 1306 1302 1307 1303 case TX_DELETE: 1308 - if (bcm_delete_tx_op(&bo->tx_ops, msg_head.can_id, ifindex)) 1304 + if (bcm_delete_tx_op(&bo->tx_ops, &msg_head, ifindex)) 1309 1305 ret = MHSIZ; 1310 1306 else 1311 1307 ret = -EINVAL; 1312 1308 break; 1313 1309 1314 1310 case RX_DELETE: 1315 - if (bcm_delete_rx_op(&bo->rx_ops, msg_head.can_id, ifindex)) 1311 + if (bcm_delete_rx_op(&bo->rx_ops, &msg_head, ifindex)) 1316 1312 ret = MHSIZ; 1317 1313 else 1318 1314 ret = -EINVAL; ··· 1335 1331 if ((msg_head.nframes != 1) || (size != CFSIZ + MHSIZ)) 1336 1332 ret = -EINVAL; 1337 1333 else 1338 - ret = bcm_tx_send(msg, ifindex, sk); 1334 + ret = bcm_tx_send(msg, ifindex, sk, CFSIZ); 1339 1335 break; 1340 1336 1341 1337 default: