aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/atm/usbatm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/atm/usbatm.c')
-rw-r--r--drivers/usb/atm/usbatm.c101
1 files changed, 60 insertions, 41 deletions
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 7af1883d4bf9..779f86ecdd76 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -166,10 +166,10 @@ struct usbatm_control {
166 166
167/* ATM */ 167/* ATM */
168 168
169static void usbatm_atm_dev_close(struct atm_dev *dev); 169static void usbatm_atm_dev_close(struct atm_dev *atm_dev);
170static int usbatm_atm_open(struct atm_vcc *vcc); 170static int usbatm_atm_open(struct atm_vcc *vcc);
171static void usbatm_atm_close(struct atm_vcc *vcc); 171static void usbatm_atm_close(struct atm_vcc *vcc);
172static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); 172static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user * arg);
173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); 174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
175 175
@@ -234,8 +234,9 @@ static int usbatm_submit_urb(struct urb *urb)
234 234
235 ret = usb_submit_urb(urb, GFP_ATOMIC); 235 ret = usb_submit_urb(urb, GFP_ATOMIC);
236 if (ret) { 236 if (ret) {
237 atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n", 237 if (printk_ratelimit())
238 __func__, urb, ret); 238 atm_warn(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
239 __func__, urb, ret);
239 240
240 /* consider all errors transient and return the buffer back to the queue */ 241 /* consider all errors transient and return the buffer back to the queue */
241 urb->status = -EAGAIN; 242 urb->status = -EAGAIN;
@@ -269,10 +270,13 @@ static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
269 270
270 spin_unlock_irqrestore(&channel->lock, flags); 271 spin_unlock_irqrestore(&channel->lock, flags);
271 272
272 if (unlikely(urb->status)) 273 if (unlikely(urb->status)) {
274 if (printk_ratelimit())
275 atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
276 __func__, urb, urb->status);
273 /* throttle processing in case of an error */ 277 /* throttle processing in case of an error */
274 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 278 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
275 else 279 } else
276 tasklet_schedule(&channel->tasklet); 280 tasklet_schedule(&channel->tasklet);
277} 281}
278 282
@@ -284,11 +288,11 @@ static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
284static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance, 288static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
285 short vpi, int vci) 289 short vpi, int vci)
286{ 290{
287 struct usbatm_vcc_data *vcc; 291 struct usbatm_vcc_data *vcc_data;
288 292
289 list_for_each_entry(vcc, &instance->vcc_list, list) 293 list_for_each_entry(vcc_data, &instance->vcc_list, list)
290 if ((vcc->vci == vci) && (vcc->vpi == vpi)) 294 if ((vcc_data->vci == vci) && (vcc_data->vpi == vpi))
291 return vcc; 295 return vcc_data;
292 return NULL; 296 return NULL;
293} 297}
294 298
@@ -317,7 +321,7 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
317 cached_vcc = usbatm_find_vcc(instance, vpi, vci); 321 cached_vcc = usbatm_find_vcc(instance, vpi, vci);
318 322
319 if (!cached_vcc) 323 if (!cached_vcc)
320 atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci); 324 atm_rldbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
321 } 325 }
322 326
323 if (!cached_vcc) 327 if (!cached_vcc)
@@ -327,7 +331,9 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
327 331
328 /* OAM F5 end-to-end */ 332 /* OAM F5 end-to-end */
329 if (pti == ATM_PTI_E2EF5) { 333 if (pti == ATM_PTI_E2EF5) {
330 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci); 334 if (printk_ratelimit())
335 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
336 __func__, vpi, vci);
331 atomic_inc(&vcc->stats->rx_err); 337 atomic_inc(&vcc->stats->rx_err);
332 continue; 338 continue;
333 } 339 }
@@ -335,7 +341,7 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
335 sarb = cached_vcc->sarb; 341 sarb = cached_vcc->sarb;
336 342
337 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { 343 if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
338 atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n", 344 atm_rldbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
339 __func__, sarb->len, vcc); 345 __func__, sarb->len, vcc);
340 /* discard cells already received */ 346 /* discard cells already received */
341 skb_trim(sarb, 0); 347 skb_trim(sarb, 0);
@@ -354,7 +360,7 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
354 360
355 /* guard against overflow */ 361 /* guard against overflow */
356 if (length > ATM_MAX_AAL5_PDU) { 362 if (length > ATM_MAX_AAL5_PDU) {
357 atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n", 363 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
358 __func__, length, vcc); 364 __func__, length, vcc);
359 atomic_inc(&vcc->stats->rx_err); 365 atomic_inc(&vcc->stats->rx_err);
360 goto out; 366 goto out;
@@ -363,14 +369,14 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
363 pdu_length = usbatm_pdu_length(length); 369 pdu_length = usbatm_pdu_length(length);
364 370
365 if (sarb->len < pdu_length) { 371 if (sarb->len < pdu_length) {
366 atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", 372 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
367 __func__, pdu_length, sarb->len, vcc); 373 __func__, pdu_length, sarb->len, vcc);
368 atomic_inc(&vcc->stats->rx_err); 374 atomic_inc(&vcc->stats->rx_err);
369 goto out; 375 goto out;
370 } 376 }
371 377
372 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { 378 if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
373 atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n", 379 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
374 __func__, vcc); 380 __func__, vcc);
375 atomic_inc(&vcc->stats->rx_err); 381 atomic_inc(&vcc->stats->rx_err);
376 goto out; 382 goto out;
@@ -379,7 +385,9 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
379 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc); 385 vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
380 386
381 if (!(skb = dev_alloc_skb(length))) { 387 if (!(skb = dev_alloc_skb(length))) {
382 atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length); 388 if (printk_ratelimit())
389 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
390 __func__, length);
383 atomic_inc(&vcc->stats->rx_drop); 391 atomic_inc(&vcc->stats->rx_drop);
384 goto out; 392 goto out;
385 } 393 }
@@ -387,7 +395,8 @@ static void usbatm_extract_cells(struct usbatm_data *instance,
387 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize); 395 vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
388 396
389 if (!atm_charge(vcc, skb->truesize)) { 397 if (!atm_charge(vcc, skb->truesize)) {
390 atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize); 398 atm_rldbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n",
399 __func__, skb->truesize);
391 dev_kfree_skb(skb); 400 dev_kfree_skb(skb);
392 goto out; /* atm_charge increments rx_drop */ 401 goto out; /* atm_charge increments rx_drop */
393 } 402 }
@@ -600,13 +609,13 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
600 } 609 }
601 610
602 if (vcc->qos.aal != ATM_AAL5) { 611 if (vcc->qos.aal != ATM_AAL5) {
603 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 612 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
604 err = -EINVAL; 613 err = -EINVAL;
605 goto fail; 614 goto fail;
606 } 615 }
607 616
608 if (skb->len > ATM_MAX_AAL5_PDU) { 617 if (skb->len > ATM_MAX_AAL5_PDU) {
609 atm_dbg(instance, "%s: packet too long (%d vs %d)!\n", 618 atm_rldbg(instance, "%s: packet too long (%d vs %d)!\n",
610 __func__, skb->len, ATM_MAX_AAL5_PDU); 619 __func__, skb->len, ATM_MAX_AAL5_PDU);
611 err = -EINVAL; 620 err = -EINVAL;
612 goto fail; 621 goto fail;
@@ -665,16 +674,16 @@ static void usbatm_put_instance(struct usbatm_data *instance)
665** ATM ** 674** ATM **
666**********/ 675**********/
667 676
668static void usbatm_atm_dev_close(struct atm_dev *dev) 677static void usbatm_atm_dev_close(struct atm_dev *atm_dev)
669{ 678{
670 struct usbatm_data *instance = dev->dev_data; 679 struct usbatm_data *instance = atm_dev->dev_data;
671 680
672 dbg("%s", __func__); 681 dbg("%s", __func__);
673 682
674 if (!instance) 683 if (!instance)
675 return; 684 return;
676 685
677 dev->dev_data = NULL; 686 atm_dev->dev_data = NULL; /* catch bugs */
678 usbatm_put_instance(instance); /* taken in usbatm_atm_init */ 687 usbatm_put_instance(instance); /* taken in usbatm_atm_init */
679} 688}
680 689
@@ -735,13 +744,18 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
735 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci); 744 atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
736 745
737 /* only support AAL5 */ 746 /* only support AAL5 */
738 if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) 747 if ((vcc->qos.aal != ATM_AAL5)) {
739 || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { 748 atm_warn(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
740 atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 749 return -EINVAL;
750 }
751
752 /* sanity checks */
753 if ((vcc->qos.rxtp.max_sdu < 0) || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
754 atm_dbg(instance, "%s: max_sdu %d out of range!\n", __func__, vcc->qos.rxtp.max_sdu);
741 return -EINVAL; 755 return -EINVAL;
742 } 756 }
743 757
744 down(&instance->serialize); /* vs self, usbatm_atm_close */ 758 down(&instance->serialize); /* vs self, usbatm_atm_close, usbatm_usb_disconnect */
745 759
746 if (usbatm_find_vcc(instance, vpi, vci)) { 760 if (usbatm_find_vcc(instance, vpi, vci)) {
747 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci); 761 atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
@@ -750,7 +764,7 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
750 } 764 }
751 765
752 if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) { 766 if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
753 atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__); 767 atm_err(instance, "%s: no memory for vcc_data!\n", __func__);
754 ret = -ENOMEM; 768 ret = -ENOMEM;
755 goto fail; 769 goto fail;
756 } 770 }
@@ -762,7 +776,7 @@ static int usbatm_atm_open(struct atm_vcc *vcc)
762 776
763 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL); 777 new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
764 if (!new->sarb) { 778 if (!new->sarb) {
765 atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__); 779 atm_err(instance, "%s: no memory for SAR buffer!\n", __func__);
766 ret = -ENOMEM; 780 ret = -ENOMEM;
767 goto fail; 781 goto fail;
768 } 782 }
@@ -806,7 +820,7 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
806 820
807 usbatm_cancel_send(instance, vcc); 821 usbatm_cancel_send(instance, vcc);
808 822
809 down(&instance->serialize); /* vs self, usbatm_atm_open */ 823 down(&instance->serialize); /* vs self, usbatm_atm_open, usbatm_usb_disconnect */
810 824
811 tasklet_disable(&instance->rx_channel.tasklet); 825 tasklet_disable(&instance->rx_channel.tasklet);
812 list_del(&vcc_data->list); 826 list_del(&vcc_data->list);
@@ -829,7 +843,7 @@ static void usbatm_atm_close(struct atm_vcc *vcc)
829 atm_dbg(instance, "%s successful\n", __func__); 843 atm_dbg(instance, "%s successful\n", __func__);
830} 844}
831 845
832static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, 846static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd,
833 void __user * arg) 847 void __user * arg)
834{ 848{
835 switch (cmd) { 849 switch (cmd) {
@@ -845,10 +859,13 @@ static int usbatm_atm_init(struct usbatm_data *instance)
845 struct atm_dev *atm_dev; 859 struct atm_dev *atm_dev;
846 int ret, i; 860 int ret, i;
847 861
848 /* ATM init */ 862 /* ATM init. The ATM initialization scheme suffers from an intrinsic race
863 * condition: callbacks we register can be executed at once, before we have
864 * initialized the struct atm_dev. To protect against this, all callbacks
865 * abort if atm_dev->dev_data is NULL. */
849 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL); 866 atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
850 if (!atm_dev) { 867 if (!atm_dev) {
851 usb_dbg(instance, "%s: failed to register ATM device!\n", __func__); 868 usb_err(instance, "%s: failed to register ATM device!\n", __func__);
852 return -1; 869 return -1;
853 } 870 }
854 871
@@ -862,12 +879,13 @@ static int usbatm_atm_init(struct usbatm_data *instance)
862 atm_dev->link_rate = 128 * 1000 / 424; 879 atm_dev->link_rate = 128 * 1000 / 424;
863 880
864 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) { 881 if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
865 atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret); 882 atm_err(instance, "%s: atm_start failed: %d!\n", __func__, ret);
866 goto fail; 883 goto fail;
867 } 884 }
868 885
869 /* ready for ATM callbacks */
870 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */ 886 usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
887
888 /* ready for ATM callbacks */
871 mb(); 889 mb();
872 atm_dev->dev_data = instance; 890 atm_dev->dev_data = instance;
873 891
@@ -915,7 +933,7 @@ static int usbatm_heavy_init(struct usbatm_data *instance)
915 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL); 933 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
916 934
917 if (ret < 0) { 935 if (ret < 0) {
918 usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); 936 usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
919 return ret; 937 return ret;
920 } 938 }
921 939
@@ -953,7 +971,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
953 int i, length; 971 int i, length;
954 int need_heavy; 972 int need_heavy;
955 973
956 dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n", 974 dev_dbg(dev, "%s: trying driver %s with vendor=%04x, product=%04x, ifnum %2d\n",
957 __func__, driver->driver_name, 975 __func__, driver->driver_name,
958 le16_to_cpu(usb_dev->descriptor.idVendor), 976 le16_to_cpu(usb_dev->descriptor.idVendor),
959 le16_to_cpu(usb_dev->descriptor.idProduct), 977 le16_to_cpu(usb_dev->descriptor.idProduct),
@@ -962,7 +980,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
962 /* instance init */ 980 /* instance init */
963 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 981 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
964 if (!instance) { 982 if (!instance) {
965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__); 983 dev_err(dev, "%s: no memory for instance data!\n", __func__);
966 return -ENOMEM; 984 return -ENOMEM;
967 } 985 }
968 986
@@ -998,7 +1016,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
998 bind: 1016 bind:
999 need_heavy = 1; 1017 need_heavy = 1;
1000 if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) { 1018 if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) {
1001 dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error); 1019 dev_err(dev, "%s: bind failed: %d!\n", __func__, error);
1002 goto fail_free; 1020 goto fail_free;
1003 } 1021 }
1004 1022
@@ -1044,7 +1062,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1044 1062
1045 urb = usb_alloc_urb(iso_packets, GFP_KERNEL); 1063 urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
1046 if (!urb) { 1064 if (!urb) {
1047 dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i); 1065 dev_err(dev, "%s: no memory for urb %d!\n", __func__, i);
1048 goto fail_unbind; 1066 goto fail_unbind;
1049 } 1067 }
1050 1068
@@ -1052,9 +1070,10 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1052 1070
1053 buffer = kmalloc(channel->buf_size, GFP_KERNEL); 1071 buffer = kmalloc(channel->buf_size, GFP_KERNEL);
1054 if (!buffer) { 1072 if (!buffer) {
1055 dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i); 1073 dev_err(dev, "%s: no memory for buffer %d!\n", __func__, i);
1056 goto fail_unbind; 1074 goto fail_unbind;
1057 } 1075 }
1076 /* zero the tx padding to avoid leaking information */
1058 memset(buffer, 0, channel->buf_size); 1077 memset(buffer, 0, channel->buf_size);
1059 1078
1060 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint, 1079 usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,