Skip to contentSkip to conversation

usb: xhci: dbc: 2 smalll fixes for 'xhci_dbc_alloc_requests()'

PATCH In review Christophe JAILLET 2 participants 4 messages Jul 31, 2019 – Aug 5, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover usb: xhci: dbc: 2 smalll fixes for 'xhci_dbc_alloc_requests()'

Christophe JAILLET (2):
usb: xhci: dbc: Simplify error handling in 'xhci_dbc_alloc_requests()'
usb: xhci: dbc: Use GFP_KERNEL instead of GFP_ATOMIC in

    'xhci_dbc_alloc_requests()'
 drivers/usb/host/xhci-dbgtty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 usb: xhci: dbc: Simplify error handling in 'xhci_dbc_alloc_requests()'

If the 'kmalloc()' fails, we need to undo the previous 'dbc_alloc_request()' call.

Because of the more similar function name, it is more logical to use 'dbc_free_request()' instead of 'xhci_dbc_free_req()'.

Both are equivalent here because:
static void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req) {
kfree(req->buf);
dbc_free_request(dep, req);
}
and 'req->buf' is known to be NULL at this point

---
 drivers/usb/host/xhci-dbgtty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgtty.c +1 -1
index aff79ff5aba4..845939f8a0b8 100644
@@ -146,7 +146,7 @@ xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
 		req->length = DBC_MAX_PACKET;
 		req->buf = kmalloc(req->length, GFP_KERNEL);
 		if (!req->buf) {
-			xhci_dbc_free_req(dep, req);
+			dbc_free_request(dep, req);
 			break;
 		}
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 usb: xhci: dbc: Use GFP_KERNEL instead of GFP_ATOMIC in 'xhci_dbc_alloc_requests()'

In reply to Christophe JAILLET

There is no need to use GFP_ATOMIC to allocate 'req'. GFP_KERNEL should be enough and is already used for another allocation juste a few lines below.

---
I've done my best to check if a spinlock can be hold when reaching this code. Apparently it is never the case.
But double check to be sure that it is not the kmalloc that should use GFP_ATOMIC.

---
 drivers/usb/host/xhci-dbgtty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-dbgtty.c +1 -1
index 845939f8a0b8..be726c791323 100644
@@ -139,7 +139,7 @@ xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
 	struct dbc_request	*req;
 
 	for (i = 0; i < DBC_QUEUE_SIZE; i++) {
-		req = dbc_alloc_request(dep, GFP_ATOMIC);
+		req = dbc_alloc_request(dep, GFP_KERNEL);
 		if (!req)
 			break;
 
Signature · 1 line
2.20.1
#3 lore raw
In reply to Christophe JAILLET
Quoted 10 lines · Christophe JAILLET

Christophe JAILLET (2):
usb: xhci: dbc: Simplify error handling in 'xhci_dbc_alloc_requests()'
usb: xhci: dbc: Use GFP_KERNEL instead of GFP_ATOMIC in

     'xhci_dbc_alloc_requests()'
  drivers/usb/host/xhci-dbgtty.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, adding to queue

-Mathias