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

net: usb: kaweth: Remove last user of kaweth_control()

kaweth_async_set_rx_mode() invokes kaweth_contol() and has two callers:

- kaweth_open() which is invoked from preemptible context
.
- kaweth_start_xmit() which holds a spinlock and has bottom halfs disabled.

If called from kaweth_start_xmit() kaweth_async_set_rx_mode() obviously
cannot block, which means it can't call kaweth_control(). This is detected
with an in_interrupt() check.

Replace the in_interrupt() check in kaweth_async_set_rx_mode() with an
argument which is set true by the caller if the context is safe to sleep,
otherwise false.

Now kaweth_control() is only called from preemptible context which means
there is no need for GFP_ATOMIC allocations anymore. Replace it with
usb_control_msg(). Cleanup the code a bit while at it.

Finally remove kaweth_control() since the last user is gone.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Sebastian Andrzej Siewior and committed by
David S. Miller
a19c2619 af3563be

+17 -151
+17 -151
drivers/net/usb/kaweth.c
··· 103 103 const struct usb_device_id *id /* from id_table */ 104 104 ); 105 105 static void kaweth_disconnect(struct usb_interface *intf); 106 - static int kaweth_internal_control_msg(struct usb_device *usb_dev, 107 - unsigned int pipe, 108 - struct usb_ctrlrequest *cmd, void *data, 109 - int len, int timeout); 110 106 static int kaweth_suspend(struct usb_interface *intf, pm_message_t message); 111 107 static int kaweth_resume(struct usb_interface *intf); 112 108 ··· 230 234 231 235 struct kaweth_ethernet_configuration configuration; 232 236 }; 233 - 234 - /**************************************************************** 235 - * kaweth_control 236 - ****************************************************************/ 237 - static int kaweth_control(struct kaweth_device *kaweth, 238 - unsigned int pipe, 239 - __u8 request, 240 - __u8 requesttype, 241 - __u16 value, 242 - __u16 index, 243 - void *data, 244 - __u16 size, 245 - int timeout) 246 - { 247 - struct usb_ctrlrequest *dr; 248 - int retval; 249 - 250 - if(in_interrupt()) { 251 - netdev_dbg(kaweth->net, "in_interrupt()\n"); 252 - return -EBUSY; 253 - } 254 - 255 - dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC); 256 - if (!dr) 257 - return -ENOMEM; 258 - 259 - dr->bRequestType = requesttype; 260 - dr->bRequest = request; 261 - dr->wValue = cpu_to_le16(value); 262 - dr->wIndex = cpu_to_le16(index); 263 - dr->wLength = cpu_to_le16(size); 264 - 265 - retval = kaweth_internal_control_msg(kaweth->dev, 266 - pipe, 267 - dr, 268 - data, 269 - size, 270 - timeout); 271 - 272 - kfree(dr); 273 - return retval; 274 - } 275 237 276 238 /**************************************************************** 277 239 * kaweth_read_configuration ··· 485 531 return result; 486 532 } 487 533 488 - static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth); 534 + static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth, 535 + bool may_sleep); 489 536 490 537 /**************************************************************** 491 538 * kaweth_usb_receive ··· 616 661 617 662 netif_start_queue(net); 618 663 619 - kaweth_async_set_rx_mode(kaweth); 664 + kaweth_async_set_rx_mode(kaweth, true); 620 665 return 0; 621 666 622 667 err_out: ··· 704 749 705 750 spin_lock_irq(&kaweth->device_lock); 706 751 707 - kaweth_async_set_rx_mode(kaweth); 752 + kaweth_async_set_rx_mode(kaweth, false); 708 753 netif_stop_queue(net); 709 754 if (IS_BLOCKED(kaweth->status)) { 710 755 goto skip; ··· 781 826 /**************************************************************** 782 827 * kaweth_async_set_rx_mode 783 828 ****************************************************************/ 784 - static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth) 829 + static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth, 830 + bool may_sleep) 785 831 { 786 - int result; 832 + int ret; 787 833 __u16 packet_filter_bitmap = kaweth->packet_filter_bitmap; 788 834 789 835 kaweth->packet_filter_bitmap = 0; 790 836 if (packet_filter_bitmap == 0) 791 837 return; 792 838 793 - if (in_interrupt()) 839 + if (!may_sleep) 794 840 return; 795 841 796 - result = kaweth_control(kaweth, 797 - usb_sndctrlpipe(kaweth->dev, 0), 798 - KAWETH_COMMAND_SET_PACKET_FILTER, 799 - USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, 800 - packet_filter_bitmap, 801 - 0, 802 - (void *)&kaweth->scratch, 803 - 0, 804 - KAWETH_CONTROL_TIMEOUT); 805 - 806 - if(result < 0) { 842 + ret = usb_control_msg(kaweth->dev, usb_sndctrlpipe(kaweth->dev, 0), 843 + KAWETH_COMMAND_SET_PACKET_FILTER, 844 + USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE, 845 + packet_filter_bitmap, 0, 846 + &kaweth->scratch, 0, 847 + KAWETH_CONTROL_TIMEOUT); 848 + if (ret < 0) 807 849 dev_err(&kaweth->intf->dev, "Failed to set Rx mode: %d\n", 808 - result); 809 - } 810 - else { 850 + ret); 851 + else 811 852 netdev_dbg(kaweth->net, "Set Rx mode to %d\n", 812 853 packet_filter_bitmap); 813 - } 814 854 } 815 855 816 856 /**************************************************************** ··· 1112 1162 free_netdev(netdev); 1113 1163 } 1114 1164 1115 - 1116 - // FIXME this completion stuff is a modified clone of 1117 - // an OLD version of some stuff in usb.c ... 1118 - struct usb_api_data { 1119 - wait_queue_head_t wqh; 1120 - int done; 1121 - }; 1122 - 1123 - /*-------------------------------------------------------------------* 1124 - * completion handler for compatibility wrappers (sync control/bulk) * 1125 - *-------------------------------------------------------------------*/ 1126 - static void usb_api_blocking_completion(struct urb *urb) 1127 - { 1128 - struct usb_api_data *awd = (struct usb_api_data *)urb->context; 1129 - 1130 - awd->done=1; 1131 - wake_up(&awd->wqh); 1132 - } 1133 - 1134 - /*-------------------------------------------------------------------* 1135 - * COMPATIBILITY STUFF * 1136 - *-------------------------------------------------------------------*/ 1137 - 1138 - // Starts urb and waits for completion or timeout 1139 - static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length) 1140 - { 1141 - struct usb_api_data awd; 1142 - int status; 1143 - 1144 - init_waitqueue_head(&awd.wqh); 1145 - awd.done = 0; 1146 - 1147 - urb->context = &awd; 1148 - status = usb_submit_urb(urb, GFP_ATOMIC); 1149 - if (status) { 1150 - // something went wrong 1151 - usb_free_urb(urb); 1152 - return status; 1153 - } 1154 - 1155 - if (!wait_event_timeout(awd.wqh, awd.done, timeout)) { 1156 - // timeout 1157 - dev_warn(&urb->dev->dev, "usb_control/bulk_msg: timeout\n"); 1158 - usb_kill_urb(urb); // remove urb safely 1159 - status = -ETIMEDOUT; 1160 - } 1161 - else { 1162 - status = urb->status; 1163 - } 1164 - 1165 - if (actual_length) { 1166 - *actual_length = urb->actual_length; 1167 - } 1168 - 1169 - usb_free_urb(urb); 1170 - return status; 1171 - } 1172 - 1173 - /*-------------------------------------------------------------------*/ 1174 - // returns status (negative) or length (positive) 1175 - static int kaweth_internal_control_msg(struct usb_device *usb_dev, 1176 - unsigned int pipe, 1177 - struct usb_ctrlrequest *cmd, void *data, 1178 - int len, int timeout) 1179 - { 1180 - struct urb *urb; 1181 - int retv; 1182 - int length = 0; /* shut up GCC */ 1183 - 1184 - urb = usb_alloc_urb(0, GFP_ATOMIC); 1185 - if (!urb) 1186 - return -ENOMEM; 1187 - 1188 - usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char*)cmd, data, 1189 - len, usb_api_blocking_completion, NULL); 1190 - 1191 - retv = usb_start_wait_urb(urb, timeout, &length); 1192 - if (retv < 0) { 1193 - return retv; 1194 - } 1195 - else { 1196 - return length; 1197 - } 1198 - } 1199 1165 1200 1166 module_usb_driver(kaweth_driver);