Skip to content

Commit bad9b58

Browse files
committed
[PUSB] Fixed checks on return values
1 parent 10512b3 commit bad9b58

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

cores/arduino/PluggableUSB.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ PluggableUSB_ PluggableUSB;
2929

3030
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
3131
{
32-
int ret = 0;
32+
int sent = 0;
3333
PUSBListNode* node;
3434
for (node = rootNode; node; node = node->next) {
35-
ret = node->getInterface(interfaceNum);
35+
int res = node->getInterface(interfaceNum);
36+
if (res == -1)
37+
return -1;
38+
sent += res;
3639
}
37-
return ret;
40+
return sent;
3841
}
3942

40-
int PluggableUSB_::getDescriptor(int8_t t)
43+
int PluggableUSB_::getDescriptor(int8_t type)
4144
{
4245
PUSBListNode* node;
4346
for (node = rootNode; node; node = node->next) {
44-
int ret = node->getDescriptor(t);
47+
int ret = node->getDescriptor(type);
48+
// ret!=0 -> request has been processed
4549
if (ret)
4650
return ret;
4751
}

libraries/HID/HID.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ int HID_::getInterface(uint8_t* interfaceNum)
3535
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
3636
}
3737

38-
int HID_::getDescriptor(int8_t t)
38+
int HID_::getDescriptor(int8_t type)
3939
{
40-
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
40+
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
4141
HIDDescriptorListNode* current = rootNode;
4242
int total = 0;
43-
while(current != NULL) {
44-
total += USB_SendControl(TRANSFER_PGM,current->data,current->length);
43+
while (current != NULL) {
44+
int res = USB_SendControl(TRANSFER_PGM, current->data, current->length);
45+
if (res == -1)
46+
return -1;
47+
total += res;
4548
current = current->next;
4649
}
4750
return total;
48-
} else {
49-
return 0;
5051
}
52+
53+
// Ignored
54+
return 0;
5155
}
5256

5357
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
@@ -71,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
7175
USB_Send(endpoint() | TRANSFER_RELEASE,data,len);
7276
}
7377

74-
bool HID_::setup(USBSetup& setup, uint8_t i)
78+
bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
7579
{
76-
if (interface() != i) {
80+
if (interface() != interfaceNum) {
7781
return false;
7882
} else {
7983
uint8_t r = setup.bRequest;

libraries/HID/HID.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class HID_ : public PUSBListNode
8383
protected:
8484
// Implementation of the PUSBListNode
8585
int getInterface(uint8_t* interfaceNum);
86-
int getDescriptor(int8_t t);
87-
bool setup(USBSetup& setup, uint8_t i);
86+
int getDescriptor(int8_t type);
87+
bool setup(USBSetup& setup, uint8_t interfaceNum);
8888

8989
private:
9090
HIDDescriptor hidInterface;

0 commit comments

Comments
 (0)