History

can: bcm: unify bcm_msg_head handling and prepare function parameters

Oliver Hartkopp committed 10 years ago

Commit 2b5f5f51 parent 72c8a891 file · +29 −25Browse files

Unified · Split

net/can/bcm.c+29−25
@@ -693,13 +693,13 @@ rx_starttimer: · 692 unmodified lines
693693 /*
694694 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
695695 */
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)
698698 {
699699 struct bcm_op *op;
700700
701701 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))
703703 return op;
704704 }
705705
@@ -742,12 +742,13 @@ static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op) · 36 unmodified lines
742742 /*
743743 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
744744 */
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)
746747 {
747748 struct bcm_op *op, *n;
748749
749750 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)) {
751752
752753 /*
753754 * 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
787788 /*
788789 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
789790 */
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)
791793 {
792794 struct bcm_op *op, *n;
793795
794796 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)) {
796798 list_del(&op->list);
797799 bcm_remove_op(op);
798800 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
808810 static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
809811 int ifindex)
810812 {
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);
812814
813815 if (!op)
814816 return -EINVAL;
@@ -845,8 +847,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 30 unmodified lines
845847 return -EINVAL;
846848
847849 /* 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);
850851 if (op) {
851852 /* update existing BCM operation */
852853
@@ -1010,7 +1011,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 157 unmodified lines
10101011 return -EINVAL;
10111012
10121013 /* 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);
10141015 if (op) {
10151016 /* update existing BCM operation */
10161017
@@ -1192,7 +1193,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, · 175 unmodified lines
11921193 /*
11931194 * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg)
11941195 */
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)
11961198 {
11971199 struct sk_buff *skb;
11981200 struct net_device *dev;
@@ -1202,13 +1204,13 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) · 3 unmodified lines
12021204 if (!ifindex)
12031205 return -ENODEV;
12041206
1205− skb = alloc_skb(CFSIZ + sizeof(struct can_skb_priv), GFP_KERNEL);
1207+ skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), GFP_KERNEL);
12061208 if (!skb)
12071209 return -ENOMEM;
12081210
12091211 can_skb_reserve(skb);
12101212
1211− err = memcpy_from_msg(skb_put(skb, CFSIZ), msg, CFSIZ);
1213+ err = memcpy_from_msg(skb_put(skb, cfsiz), msg, cfsiz);
12121214 if (err < 0) {
12131215 kfree_skb(skb);
12141216 return err;
@@ -1230,7 +1232,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk) · 15 unmodified lines
12301232 if (err)
12311233 return err;
12321234
1233− return CFSIZ + MHSIZ;
1235+ return cfsiz + MHSIZ;
12341236 }
12351237
12361238 /*
@@ -1248,7 +1250,15 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 11 unmodified lines
12481250 return -ENOTCONN;
12491251
12501252 /* 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)
12521262 return -EINVAL;
12531263
12541264 /* 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
12821292 }
12831293 }
12841294
1285− /* read message head information */
1286−
1287− ret = memcpy_from_msg((u8 *)&msg_head, msg, MHSIZ);
1288− if (ret < 0)
1289− return ret;
1290−
12911295 lock_sock(sk);
12921296
12931297 switch (msg_head.opcode) {
@@ -1301,14 +1305,14 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 7 unmodified lines
13011305 break;
13021306
13031307 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))
13051309 ret = MHSIZ;
13061310 else
13071311 ret = -EINVAL;
13081312 break;
13091313
13101314 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))
13121316 ret = MHSIZ;
13131317 else
13141318 ret = -EINVAL;
@@ -1331,7 +1335,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) · 16 unmodified lines
13311335 if ((msg_head.nframes != 1) || (size != CFSIZ + MHSIZ))
13321336 ret = -EINVAL;
13331337 else
1334− ret = bcm_tx_send(msg, ifindex, sk);
1338+ ret = bcm_tx_send(msg, ifindex, sk, CFSIZ);
13351339 break;
13361340
13371341 default:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t