Commit 75a5b8d
usb: gadget: f_ncm: Refactor bind path to use __free()
After an bind/unbind cycle, the ncm->notify_req is left stale. If a
subsequent bind fails, the unified error label attempts to free this
stale request, leading to a NULL pointer dereference when accessing
ep->ops->free_request.
Refactor the error handling in the bind path to use the __free()
automatic cleanup mechanism.
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020
Call trace:
usb_ep_free_request+0x2c/0xec
ncm_bind+0x39c/0x3dc
usb_add_function+0xcc/0x1f0
configfs_composite_bind+0x468/0x588
gadget_bind_driver+0x104/0x270
really_probe+0x190/0x374
__driver_probe_device+0xa0/0x12c
driver_probe_device+0x3c/0x218
__device_attach_driver+0x14c/0x188
bus_for_each_drv+0x10c/0x168
__device_attach+0xfc/0x198
device_initial_probe+0x14/0x24
bus_probe_device+0x94/0x11c
device_add+0x268/0x48c
usb_add_gadget+0x198/0x28c
dwc3_gadget_init+0x700/0x858
__dwc3_set_mode+0x3cc/0x664
process_scheduled_works+0x1d8/0x488
worker_thread+0x244/0x334
kthread+0x114/0x1bc
ret_from_fork+0x10/0x20
Fixes: 9f6ce42 ("usb: gadget: f_ncm.c added")
Cc: stable@kernel.org
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Link: https://lore.kernel.org/r/20250916-ready-v1-3-4997bf277548@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250916-ready-v1-3-4997bf277548@google.com1 parent 201c53c commit 75a5b8d
1 file changed
Lines changed: 33 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
1436 | 1438 | | |
1437 | 1439 | | |
1438 | 1440 | | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
1439 | 1444 | | |
1440 | 1445 | | |
1441 | 1446 | | |
1442 | 1447 | | |
1443 | 1448 | | |
1444 | 1449 | | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
| 1450 | + | |
| 1451 | + | |
1448 | 1452 | | |
1449 | | - | |
1450 | | - | |
1451 | 1453 | | |
1452 | 1454 | | |
1453 | 1455 | | |
| |||
1459 | 1461 | | |
1460 | 1462 | | |
1461 | 1463 | | |
1462 | | - | |
| 1464 | + | |
1463 | 1465 | | |
1464 | 1466 | | |
1465 | 1467 | | |
1466 | 1468 | | |
1467 | 1469 | | |
1468 | | - | |
1469 | | - | |
1470 | | - | |
1471 | | - | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
1472 | 1473 | | |
1473 | 1474 | | |
1474 | 1475 | | |
| |||
1478 | 1479 | | |
1479 | 1480 | | |
1480 | 1481 | | |
1481 | | - | |
| 1482 | + | |
1482 | 1483 | | |
1483 | 1484 | | |
1484 | 1485 | | |
1485 | 1486 | | |
1486 | 1487 | | |
1487 | 1488 | | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | 1489 | | |
1493 | 1490 | | |
1494 | | - | |
| 1491 | + | |
1495 | 1492 | | |
1496 | 1493 | | |
1497 | 1494 | | |
| |||
1500 | 1497 | | |
1501 | 1498 | | |
1502 | 1499 | | |
1503 | | - | |
1504 | | - | |
1505 | 1500 | | |
1506 | 1501 | | |
1507 | 1502 | | |
1508 | | - | |
| 1503 | + | |
1509 | 1504 | | |
1510 | 1505 | | |
1511 | 1506 | | |
1512 | 1507 | | |
1513 | | - | |
| 1508 | + | |
1514 | 1509 | | |
1515 | 1510 | | |
1516 | 1511 | | |
1517 | 1512 | | |
1518 | | - | |
| 1513 | + | |
1519 | 1514 | | |
1520 | 1515 | | |
1521 | | - | |
1522 | | - | |
1523 | 1516 | | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
1528 | | - | |
1529 | | - | |
1530 | | - | |
1531 | | - | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
1532 | 1525 | | |
1533 | 1526 | | |
1534 | 1527 | | |
| |||
1548 | 1541 | | |
1549 | 1542 | | |
1550 | 1543 | | |
1551 | | - | |
| 1544 | + | |
1552 | 1545 | | |
1553 | 1546 | | |
1554 | 1547 | | |
| |||
1561 | 1554 | | |
1562 | 1555 | | |
1563 | 1556 | | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
1564 | 1565 | | |
1565 | 1566 | | |
1566 | 1567 | | |
1567 | 1568 | | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
1580 | | - | |
1581 | 1569 | | |
1582 | 1570 | | |
1583 | 1571 | | |
| |||
0 commit comments