Skip to content

Commit 5c428d3

Browse files
committed
check status_change is not zero first
1 parent 8ad024e commit 5c428d3

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

src/host/hub.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -327,51 +327,45 @@ static void connection_clear_conn_change_complete (tuh_xfer_t* xfer);
327327
static void connection_port_reset_complete (tuh_xfer_t* xfer);
328328

329329
// callback as response of interrupt endpoint polling
330-
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
331-
{
330+
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
332331
(void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports
333332
(void) ep_addr;
334333
TU_ASSERT(result == XFER_RESULT_SUCCESS);
335334

336335
hub_interface_t* p_hub = get_itf(dev_addr);
337336

338-
TU_LOG2(" Hub Status Change = 0x%02X\r\n", p_hub->status_change);
337+
uint8_t const status_change = p_hub->status_change;
338+
TU_LOG2(" Hub Status Change = 0x%02X\r\n", status_change);
339339

340-
// Hub bit 0 is for the hub device events
341-
if (tu_bit_test(p_hub->status_change, 0))
342-
{
343-
if (hub_port_get_status(dev_addr, 0, &p_hub->hub_status, hub_get_status_complete, 0) == false)
344-
{
340+
if ( status_change == 0 ) {
341+
// The status change event was neither for the hub, nor for any of its ports.
342+
// This shouldn't happen, but it does with some devices.
343+
// Initiate the next interrupt poll here.
344+
hub_edpt_status_xfer(dev_addr);
345+
return true;
346+
}
347+
348+
if (tu_bit_test(status_change, 0)) {
349+
// Hub bit 0 is for the hub device events
350+
if (hub_port_get_status(dev_addr, 0, &p_hub->hub_status, hub_get_status_complete, 0) == false) {
345351
//Hub status control transfer failed, retry
346352
hub_edpt_status_xfer(dev_addr);
347353
}
348354
}
349-
else
350-
{
355+
else {
351356
// Hub bits 1 to n are hub port events
352-
for (uint8_t port=1; port <= p_hub->port_count; port++)
353-
{
354-
if ( tu_bit_test(p_hub->status_change, port) )
355-
{
356-
if (hub_port_get_status(dev_addr, port, &p_hub->port_status, hub_port_get_status_complete, 0) == false)
357-
{
357+
for (uint8_t port=1; port <= p_hub->port_count; port++) {
358+
if ( tu_bit_test(status_change, port) ) {
359+
if (hub_port_get_status(dev_addr, port, &p_hub->port_status, hub_port_get_status_complete, 0) == false) {
358360
//Hub status control transfer failed, retry
359361
hub_edpt_status_xfer(dev_addr);
360362
}
361363
break;
362364
}
363365
}
364-
365-
// The status change event was neither for the hub, nor for any of
366-
// its ports. (For example `p_hub->status_change == 0`.) This
367-
// shouldn't happen, but it does with some devices. Initiate the
368-
// next interrupt poll here, because we've scheduled no other work
369-
// whose completion can initiate it.
370-
hub_edpt_status_xfer(dev_addr);
371366
}
372367

373368
// NOTE: next status transfer is queued by usbh.c after handling this request
374-
375369
return true;
376370
}
377371

0 commit comments

Comments
 (0)