[haiku-commits] haiku: hrev52916 - src/add-ons/kernel/busses/usb

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 22 Feb 2019 11:29:53 -0500 (EST)

hrev52916 adds 2 changesets to branch 'master'
old head: aa5cb68bc69ce88557eb1ec22bfdea1e1a7e2594
new head: a54fc27a11ff857643d4b0dacaf641cc9ceb9ef3
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=a54fc27a11ff+%5Eaa5cb68bc69c

----------------------------------------------------------------------------

c7f186b23f29: XHCI: Make some errors more descriptive.
  
  Also contains some minor coding style cleanup.

a54fc27a11ff: XHCI: Check the device object initialized successfully before 
adding it.
  
  Fixes various NULL dereferences in other parts of the USB stack
  when the XHCI controller is not behaving quite as expected.
  
  Possibly related to #13403.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 14 insertions(+), 9 deletions(-)
src/add-ons/kernel/busses/usb/xhci.cpp | 23 ++++++++++++++---------

############################################################################

Commit:      c7f186b23f29765bf40321b2737cd517c535db9c
URL:         https://git.haiku-os.org/haiku/commit/?id=c7f186b23f29
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 05:39:36 2019 UTC

XHCI: Make some errors more descriptive.

Also contains some minor coding style cleanup.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index c739f5532e..e80407022d 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -4,7 +4,7 @@
  *
  * Authors:
  *             Augustin Cavalier <waddlesplash>
- *             Jian Chiang <j.jian.chiang@xxxxxxxxx>
+ *             Jian Chiang <j.jian.chiang@xxxxxxxxx>
  *             Jérôme Duval <jerome.duval@xxxxxxxxx>
  *             Akshay Jaggi <akshay1994.leo@xxxxxxxxx>
  *             Michael Lotz <mmlr@xxxxxxxx>
@@ -1312,7 +1312,7 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
        usb_device_descriptor deviceDescriptor;
 
        TRACE("getting the device descriptor\n");
-       pipe.SendRequest(
+       status_t status = pipe.SendRequest(
                USB_REQTYPE_DEVICE_IN | USB_REQTYPE_STANDARD,           // type
                USB_REQUEST_GET_DESCRIPTOR,                                     
                // request
                USB_DESCRIPTOR_DEVICE << 8,                                     
                // value
@@ -1323,7 +1323,8 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
                &actualLength);                                                 
                        // actual length
 
        if (actualLength != 8) {
-               TRACE_ERROR("error while getting the device descriptor\n");
+               TRACE_ERROR("error while getting the device descriptor: %s\n",
+                       strerror(status));
                device->state = XHCI_STATE_DISABLED;
                delete_area(device->input_ctx_area);
                delete_area(device->device_ctx_area);
@@ -1355,7 +1356,7 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
                TRACE("getting the hub descriptor\n");
                size_t actualLength = 0;
                usb_hub_descriptor hubDescriptor;
-               pipe.SendRequest(
+               status = pipe.SendRequest(
                        USB_REQTYPE_DEVICE_IN | USB_REQTYPE_CLASS,              
        // type
                        USB_REQUEST_GET_DESCRIPTOR,                             
                        // request
                        USB_DESCRIPTOR_HUB << 8,                                
                        // value
@@ -1366,7 +1367,8 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
                        &actualLength);
 
                if (actualLength != sizeof(usb_hub_descriptor)) {
-                       TRACE_ERROR("error while getting the hub descriptor\n");
+                       TRACE_ERROR("error while getting the hub descriptor: 
%s\n",
+                               strerror(status));
                        device->state = XHCI_STATE_DISABLED;
                        delete_area(device->input_ctx_area);
                        delete_area(device->device_ctx_area);
@@ -2092,7 +2094,6 @@ XHCI::HandleTransferComplete(xhci_trb* trb)
                        }
                }
        }
-
 }
 
 
@@ -2438,7 +2439,7 @@ XHCI::FinishTransfers()
 
                        size_t actualLength = 0;
                        if (callbackStatus == B_OK) {
-                               actualLength = requestData ? requestData->Length
+                               actualLength = requestData != NULL ? 
requestData->Length
                                        : transfer->DataLength();
 
                                if (td->trb_completion_code == 
COMP_SHORT_PACKET)

############################################################################

Revision:    hrev52916
Commit:      a54fc27a11ff857643d4b0dacaf641cc9ceb9ef3
URL:         https://git.haiku-os.org/haiku/commit/?id=a54fc27a11ff
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 06:23:08 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/13403

XHCI: Check the device object initialized successfully before adding it.

Fixes various NULL dereferences in other parts of the USB stack
when the XHCI controller is not behaving quite as expected.

Possibly related to #13403.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index e80407022d..3831098c57 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -1395,8 +1395,12 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
                deviceObject = new(std::nothrow) Device(parent, hubAddress, 
hubPort,
                        deviceDescriptor, device->address + 1, speed, false, 
device);
        }
-       if (deviceObject == NULL) {
-               TRACE_ERROR("no memory to allocate device\n");
+       if (deviceObject == NULL || deviceObject->InitCheck() != B_OK) {
+               if (deviceObject == NULL) {
+                       TRACE_ERROR("no memory to allocate device\n");
+               } else {
+                       TRACE_ERROR("device object failed to initialize\n");
+               }
                device->state = XHCI_STATE_DISABLED;
                delete_area(device->input_ctx_area);
                delete_area(device->device_ctx_area);


Other related posts:

  • » [haiku-commits] haiku: hrev52916 - src/add-ons/kernel/busses/usb - waddlesplash