Fix NPE when devConfig[X] is NULL, remove unused variable from on-chip RAM

This commit is contained in:
Andrew J. Kroll 2013-06-18 14:43:37 -04:00
parent 53b7f82d94
commit 5812e0f5c4
2 changed files with 10 additions and 11 deletions

19
Usb.cpp
View file

@ -38,7 +38,7 @@ USB::USB() : bmHubPre(0) {
/* Initialize data structures */ /* Initialize data structures */
void USB::init() { void USB::init() {
devConfigIndex = 0; //devConfigIndex = 0;
bmHubPre = 0; bmHubPre = 0;
} }
@ -625,6 +625,7 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo
uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
//uint8_t bAddress = 0; //uint8_t bAddress = 0;
//printf("Configuring: parent = %i, port = %i\r\n", parent, port); //printf("Configuring: parent = %i, port = %i\r\n", parent, port);
uint8_t devConfigIndex;
uint8_t rcode = 0; uint8_t rcode = 0;
uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
UsbDevice *p = NULL; UsbDevice *p = NULL;
@ -676,22 +677,20 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
uint16_t pid = (uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; uint16_t pid = (uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
uint8_t klass = ((USB_DEVICE_DESCRIPTOR*)buf)->bDeviceClass; uint8_t klass = ((USB_DEVICE_DESCRIPTOR*)buf)->bDeviceClass;
// Attempt to configure if VID/PID or device class matches with a driver // Attempt to configure if VID/PID or device class matches with a driver
for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) { for (devConfigIndex = 0; devConfigIndex < USB_NUMDEVICES; devConfigIndex++) {
if (!devConfig[devConfigIndex]) continue; // no driver if (!devConfig[devConfigIndex]) continue; // no driver
if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed if (devConfig[devConfigIndex]->GetAddress()) continue; // consumed
if (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass)) { if (devConfig[devConfigIndex]->VIDPIDOK(vid, pid)) {
rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed); rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
break; break;
} else if (devConfig[devConfigIndex]->DEVCLASSOK(klass)) {
rcode = AttemptConfig(devConfigIndex, parent, port, lowspeed);
if (!rcode) break;
} }
} }
if (devConfigIndex < USB_NUMDEVICES) { if (devConfigIndex < USB_NUMDEVICES) {
if (rcode) {
//printf("Configuring error: %i\r\n", rcode);
devConfigIndex = 0;
}
return rcode; return rcode;
} }
@ -713,7 +712,6 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) {
} }
} }
// if we get here that means that the device class is not supported by any of registered classes // if we get here that means that the device class is not supported by any of registered classes
rcode = DefaultAddressing(parent, port, lowspeed); rcode = DefaultAddressing(parent, port, lowspeed);
return rcode; return rcode;
@ -723,10 +721,11 @@ uint8_t USB::ReleaseDevice(uint8_t addr) {
if (!addr) if (!addr)
return 0; return 0;
for (uint8_t i = 0; i < USB_NUMDEVICES; i++) for (uint8_t i = 0; i < USB_NUMDEVICES; i++) {
if(!devConfig[i]) continue;
if (devConfig[i]->GetAddress() == addr) if (devConfig[i]->GetAddress() == addr)
return devConfig[i]->Release(); return devConfig[i]->Release();
}
return 0; return 0;
} }

2
Usb.h
View file

@ -189,7 +189,7 @@ public:
class USB : public MAX3421E { class USB : public MAX3421E {
AddressPoolImpl<USB_NUMDEVICES> addrPool; AddressPoolImpl<USB_NUMDEVICES> addrPool;
USBDeviceConfig* devConfig[USB_NUMDEVICES]; USBDeviceConfig* devConfig[USB_NUMDEVICES];
uint8_t devConfigIndex; //uint8_t devConfigIndex;
uint8_t bmHubPre; uint8_t bmHubPre;
public: public: