* [PATCH 0/3] nfc: refactor USB endpoint lookups
@ 2026-03-30 10:36 Johan Hovold
2026-03-30 10:36 ` [PATCH 1/3] nfc: nfcmrvl: refactor endpoint lookup Johan Hovold
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Johan Hovold @ 2026-03-30 10:36 UTC (permalink / raw)
To: netdev; +Cc: linux-kernel, Johan Hovold
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.
Johan
Johan Hovold (3):
nfc: nfcmrvl: refactor endpoint lookup
nfc: pn533: refactor endpoint lookup
nfc: port100: refactor endpoint lookup
drivers/nfc/nfcmrvl/usb.c | 20 ++++----------------
drivers/nfc/pn533/usb.c | 34 +++++++++++-----------------------
drivers/nfc/port100.c | 27 ++++++---------------------
3 files changed, 21 insertions(+), 60 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] nfc: nfcmrvl: refactor endpoint lookup
2026-03-30 10:36 [PATCH 0/3] nfc: refactor USB endpoint lookups Johan Hovold
@ 2026-03-30 10:36 ` Johan Hovold
2026-03-30 10:36 ` [PATCH 2/3] nfc: pn533: " Johan Hovold
2026-03-30 10:36 ` [PATCH 3/3] nfc: port100: " Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-03-30 10:36 UTC (permalink / raw)
To: netdev; +Cc: linux-kernel, Johan Hovold
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/nfc/nfcmrvl/usb.c | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index ea7309453096..6c4711c869f0 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -288,9 +288,9 @@ static int nfcmrvl_probe(struct usb_interface *intf,
{
struct nfcmrvl_usb_drv_data *drv_data;
struct nfcmrvl_private *priv;
- int i;
struct usb_device *udev = interface_to_usbdev(intf);
struct nfcmrvl_platform_data config;
+ int ret;
/* No configuration for USB */
memset(&config, 0, sizeof(config));
@@ -302,21 +302,9 @@ static int nfcmrvl_probe(struct usb_interface *intf,
if (!drv_data)
return -ENOMEM;
- for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
- struct usb_endpoint_descriptor *ep_desc;
-
- ep_desc = &intf->cur_altsetting->endpoint[i].desc;
-
- if (!drv_data->bulk_tx_ep &&
- usb_endpoint_is_bulk_out(ep_desc)) {
- drv_data->bulk_tx_ep = ep_desc;
- } else if (!drv_data->bulk_rx_ep &&
- usb_endpoint_is_bulk_in(ep_desc)) {
- drv_data->bulk_rx_ep = ep_desc;
- }
- }
-
- if (!drv_data->bulk_tx_ep || !drv_data->bulk_rx_ep)
+ ret = usb_find_common_endpoints(intf->cur_altsetting, &drv_data->bulk_rx_ep,
+ &drv_data->bulk_tx_ep, NULL, NULL);
+ if (ret)
return -ENODEV;
drv_data->udev = udev;
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] nfc: pn533: refactor endpoint lookup
2026-03-30 10:36 [PATCH 0/3] nfc: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:36 ` [PATCH 1/3] nfc: nfcmrvl: refactor endpoint lookup Johan Hovold
@ 2026-03-30 10:36 ` Johan Hovold
2026-03-30 10:36 ` [PATCH 3/3] nfc: port100: " Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-03-30 10:36 UTC (permalink / raw)
To: netdev; +Cc: linux-kernel, Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints
(and determining endpoint numbers) instead of open coding.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/nfc/pn533/usb.c | 34 +++++++++++-----------------------
1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/drivers/nfc/pn533/usb.c b/drivers/nfc/pn533/usb.c
index 0ff2f0d7caf4..efb07f944fce 100644
--- a/drivers/nfc/pn533/usb.c
+++ b/drivers/nfc/pn533/usb.c
@@ -476,14 +476,9 @@ static const struct pn533_phy_ops usb_phy_ops = {
static int pn533_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
+ struct usb_endpoint_descriptor *ep_in, *ep_out;
struct pn533 *priv;
struct pn533_usb_phy *phy;
- struct usb_host_interface *iface_desc;
- struct usb_endpoint_descriptor *endpoint;
- int in_endpoint = 0;
- int out_endpoint = 0;
- int rc = -ENOMEM;
- int i;
u32 protocols;
enum pn533_protocol_type protocol_type = PN533_PROTO_REQ_ACK_RESP;
struct pn533_frame_ops *fops = NULL;
@@ -491,6 +486,7 @@ static int pn533_usb_probe(struct usb_interface *interface,
int in_buf_len = PN533_EXT_FRAME_HEADER_LEN +
PN533_STD_FRAME_MAX_PAYLOAD_LEN +
PN533_STD_FRAME_TAIL_LEN;
+ int rc;
phy = devm_kzalloc(&interface->dev, sizeof(*phy), GFP_KERNEL);
if (!phy)
@@ -503,21 +499,11 @@ static int pn533_usb_probe(struct usb_interface *interface,
phy->udev = interface_to_usbdev(interface);
phy->interface = interface;
- iface_desc = interface->cur_altsetting;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
- endpoint = &iface_desc->endpoint[i].desc;
-
- if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint))
- in_endpoint = endpoint->bEndpointAddress;
-
- if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint))
- out_endpoint = endpoint->bEndpointAddress;
- }
-
- if (!in_endpoint || !out_endpoint) {
+ rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in,
+ &ep_out, NULL, NULL);
+ if (rc) {
nfc_err(&interface->dev,
"Could not find bulk-in or bulk-out endpoint\n");
- rc = -ENODEV;
goto error;
}
@@ -525,18 +511,20 @@ static int pn533_usb_probe(struct usb_interface *interface,
phy->out_urb = usb_alloc_urb(0, GFP_KERNEL);
phy->ack_urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!phy->in_urb || !phy->out_urb || !phy->ack_urb)
+ if (!phy->in_urb || !phy->out_urb || !phy->ack_urb) {
+ rc = -ENOMEM;
goto error;
+ }
usb_fill_bulk_urb(phy->in_urb, phy->udev,
- usb_rcvbulkpipe(phy->udev, in_endpoint),
+ usb_rcvbulkpipe(phy->udev, usb_endpoint_num(ep_in)),
in_buf, in_buf_len, NULL, phy);
usb_fill_bulk_urb(phy->out_urb, phy->udev,
- usb_sndbulkpipe(phy->udev, out_endpoint),
+ usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)),
NULL, 0, pn533_out_complete, phy);
usb_fill_bulk_urb(phy->ack_urb, phy->udev,
- usb_sndbulkpipe(phy->udev, out_endpoint),
+ usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)),
NULL, 0, pn533_ack_complete, phy);
switch (id->driver_info) {
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] nfc: port100: refactor endpoint lookup
2026-03-30 10:36 [PATCH 0/3] nfc: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:36 ` [PATCH 1/3] nfc: nfcmrvl: refactor endpoint lookup Johan Hovold
2026-03-30 10:36 ` [PATCH 2/3] nfc: pn533: " Johan Hovold
@ 2026-03-30 10:36 ` Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-03-30 10:36 UTC (permalink / raw)
To: netdev; +Cc: linux-kernel, Johan Hovold
Use the common USB helpers for looking up bulk and interrupt endpoints
(and determining endpoint numbers) instead of open coding.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/nfc/port100.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c
index 09dcc6f4c4f3..5ae61d7ebcfe 100644
--- a/drivers/nfc/port100.c
+++ b/drivers/nfc/port100.c
@@ -1489,15 +1489,11 @@ MODULE_DEVICE_TABLE(usb, port100_table);
static int port100_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
+ struct usb_endpoint_descriptor *ep_in, *ep_out;
struct port100 *dev;
int rc;
- struct usb_host_interface *iface_desc;
- struct usb_endpoint_descriptor *endpoint;
- int in_endpoint;
- int out_endpoint;
u16 fw_version;
u64 cmd_type_mask;
- int i;
dev = devm_kzalloc(&interface->dev, sizeof(struct port100), GFP_KERNEL);
if (!dev)
@@ -1508,22 +1504,11 @@ static int port100_probe(struct usb_interface *interface,
dev->interface = interface;
usb_set_intfdata(interface, dev);
- in_endpoint = out_endpoint = 0;
- iface_desc = interface->cur_altsetting;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
- endpoint = &iface_desc->endpoint[i].desc;
-
- if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint))
- in_endpoint = endpoint->bEndpointAddress;
-
- if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint))
- out_endpoint = endpoint->bEndpointAddress;
- }
-
- if (!in_endpoint || !out_endpoint) {
+ rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in,
+ &ep_out, NULL, NULL);
+ if (rc) {
nfc_err(&interface->dev,
"Could not find bulk-in or bulk-out endpoint\n");
- rc = -ENODEV;
goto error;
}
@@ -1537,10 +1522,10 @@ static int port100_probe(struct usb_interface *interface,
}
usb_fill_bulk_urb(dev->in_urb, dev->udev,
- usb_rcvbulkpipe(dev->udev, in_endpoint),
+ usb_rcvbulkpipe(dev->udev, usb_endpoint_num(ep_in)),
NULL, 0, NULL, dev);
usb_fill_bulk_urb(dev->out_urb, dev->udev,
- usb_sndbulkpipe(dev->udev, out_endpoint),
+ usb_sndbulkpipe(dev->udev, usb_endpoint_num(ep_out)),
NULL, 0, port100_send_complete, dev);
dev->out_urb->transfer_flags = URB_ZERO_PACKET;
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-30 10:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 10:36 [PATCH 0/3] nfc: refactor USB endpoint lookups Johan Hovold
2026-03-30 10:36 ` [PATCH 1/3] nfc: nfcmrvl: refactor endpoint lookup Johan Hovold
2026-03-30 10:36 ` [PATCH 2/3] nfc: pn533: " Johan Hovold
2026-03-30 10:36 ` [PATCH 3/3] nfc: port100: " Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox