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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'nfc-refactor-usb-endpoint-lookups'

Johan Hovold says:

====================
nfc: refactor USB endpoint lookups

Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.
====================

Link: https://patch.msgid.link/20260330103655.1672331-1-johan@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+21 -60
+4 -16
drivers/nfc/nfcmrvl/usb.c
··· 288 288 { 289 289 struct nfcmrvl_usb_drv_data *drv_data; 290 290 struct nfcmrvl_private *priv; 291 - int i; 292 291 struct usb_device *udev = interface_to_usbdev(intf); 293 292 struct nfcmrvl_platform_data config; 293 + int ret; 294 294 295 295 /* No configuration for USB */ 296 296 memset(&config, 0, sizeof(config)); ··· 302 302 if (!drv_data) 303 303 return -ENOMEM; 304 304 305 - for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { 306 - struct usb_endpoint_descriptor *ep_desc; 307 - 308 - ep_desc = &intf->cur_altsetting->endpoint[i].desc; 309 - 310 - if (!drv_data->bulk_tx_ep && 311 - usb_endpoint_is_bulk_out(ep_desc)) { 312 - drv_data->bulk_tx_ep = ep_desc; 313 - } else if (!drv_data->bulk_rx_ep && 314 - usb_endpoint_is_bulk_in(ep_desc)) { 315 - drv_data->bulk_rx_ep = ep_desc; 316 - } 317 - } 318 - 319 - if (!drv_data->bulk_tx_ep || !drv_data->bulk_rx_ep) 305 + ret = usb_find_common_endpoints(intf->cur_altsetting, &drv_data->bulk_rx_ep, 306 + &drv_data->bulk_tx_ep, NULL, NULL); 307 + if (ret) 320 308 return -ENODEV; 321 309 322 310 drv_data->udev = udev;
+11 -23
drivers/nfc/pn533/usb.c
··· 476 476 static int pn533_usb_probe(struct usb_interface *interface, 477 477 const struct usb_device_id *id) 478 478 { 479 + struct usb_endpoint_descriptor *ep_in, *ep_out; 479 480 struct pn533 *priv; 480 481 struct pn533_usb_phy *phy; 481 - struct usb_host_interface *iface_desc; 482 - struct usb_endpoint_descriptor *endpoint; 483 - int in_endpoint = 0; 484 - int out_endpoint = 0; 485 - int rc = -ENOMEM; 486 - int i; 487 482 u32 protocols; 488 483 enum pn533_protocol_type protocol_type = PN533_PROTO_REQ_ACK_RESP; 489 484 struct pn533_frame_ops *fops = NULL; ··· 486 491 int in_buf_len = PN533_EXT_FRAME_HEADER_LEN + 487 492 PN533_STD_FRAME_MAX_PAYLOAD_LEN + 488 493 PN533_STD_FRAME_TAIL_LEN; 494 + int rc; 489 495 490 496 phy = devm_kzalloc(&interface->dev, sizeof(*phy), GFP_KERNEL); 491 497 if (!phy) ··· 499 503 phy->udev = interface_to_usbdev(interface); 500 504 phy->interface = interface; 501 505 502 - iface_desc = interface->cur_altsetting; 503 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 504 - endpoint = &iface_desc->endpoint[i].desc; 505 - 506 - if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint)) 507 - in_endpoint = endpoint->bEndpointAddress; 508 - 509 - if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint)) 510 - out_endpoint = endpoint->bEndpointAddress; 511 - } 512 - 513 - if (!in_endpoint || !out_endpoint) { 506 + rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in, 507 + &ep_out, NULL, NULL); 508 + if (rc) { 514 509 nfc_err(&interface->dev, 515 510 "Could not find bulk-in or bulk-out endpoint\n"); 516 - rc = -ENODEV; 517 511 goto error; 518 512 } 519 513 ··· 511 525 phy->out_urb = usb_alloc_urb(0, GFP_KERNEL); 512 526 phy->ack_urb = usb_alloc_urb(0, GFP_KERNEL); 513 527 514 - if (!phy->in_urb || !phy->out_urb || !phy->ack_urb) 528 + if (!phy->in_urb || !phy->out_urb || !phy->ack_urb) { 529 + rc = -ENOMEM; 515 530 goto error; 531 + } 516 532 517 533 usb_fill_bulk_urb(phy->in_urb, phy->udev, 518 - usb_rcvbulkpipe(phy->udev, in_endpoint), 534 + usb_rcvbulkpipe(phy->udev, usb_endpoint_num(ep_in)), 519 535 in_buf, in_buf_len, NULL, phy); 520 536 521 537 usb_fill_bulk_urb(phy->out_urb, phy->udev, 522 - usb_sndbulkpipe(phy->udev, out_endpoint), 538 + usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)), 523 539 NULL, 0, pn533_out_complete, phy); 524 540 usb_fill_bulk_urb(phy->ack_urb, phy->udev, 525 - usb_sndbulkpipe(phy->udev, out_endpoint), 541 + usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)), 526 542 NULL, 0, pn533_ack_complete, phy); 527 543 528 544 switch (id->driver_info) {
+6 -21
drivers/nfc/port100.c
··· 1489 1489 static int port100_probe(struct usb_interface *interface, 1490 1490 const struct usb_device_id *id) 1491 1491 { 1492 + struct usb_endpoint_descriptor *ep_in, *ep_out; 1492 1493 struct port100 *dev; 1493 1494 int rc; 1494 - struct usb_host_interface *iface_desc; 1495 - struct usb_endpoint_descriptor *endpoint; 1496 - int in_endpoint; 1497 - int out_endpoint; 1498 1495 u16 fw_version; 1499 1496 u64 cmd_type_mask; 1500 - int i; 1501 1497 1502 1498 dev = devm_kzalloc(&interface->dev, sizeof(struct port100), GFP_KERNEL); 1503 1499 if (!dev) ··· 1504 1508 dev->interface = interface; 1505 1509 usb_set_intfdata(interface, dev); 1506 1510 1507 - in_endpoint = out_endpoint = 0; 1508 - iface_desc = interface->cur_altsetting; 1509 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 1510 - endpoint = &iface_desc->endpoint[i].desc; 1511 - 1512 - if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint)) 1513 - in_endpoint = endpoint->bEndpointAddress; 1514 - 1515 - if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint)) 1516 - out_endpoint = endpoint->bEndpointAddress; 1517 - } 1518 - 1519 - if (!in_endpoint || !out_endpoint) { 1511 + rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in, 1512 + &ep_out, NULL, NULL); 1513 + if (rc) { 1520 1514 nfc_err(&interface->dev, 1521 1515 "Could not find bulk-in or bulk-out endpoint\n"); 1522 - rc = -ENODEV; 1523 1516 goto error; 1524 1517 } 1525 1518 ··· 1522 1537 } 1523 1538 1524 1539 usb_fill_bulk_urb(dev->in_urb, dev->udev, 1525 - usb_rcvbulkpipe(dev->udev, in_endpoint), 1540 + usb_rcvbulkpipe(dev->udev, usb_endpoint_num(ep_in)), 1526 1541 NULL, 0, NULL, dev); 1527 1542 usb_fill_bulk_urb(dev->out_urb, dev->udev, 1528 - usb_sndbulkpipe(dev->udev, out_endpoint), 1543 + usb_sndbulkpipe(dev->udev, usb_endpoint_num(ep_out)), 1529 1544 NULL, 0, port100_send_complete, dev); 1530 1545 dev->out_urb->transfer_flags = URB_ZERO_PACKET; 1531 1546