Skip to content

Commit ba7b479

Browse files
authored
Merge pull request #11439 from hugueskamba/hk-remove-unreachable-statement-warnings
Remove unreachable statements warnings
2 parents fff888b + 5724c4c commit ba7b479

File tree

3 files changed

+192
-21
lines changed

3 files changed

+192
-21
lines changed

drivers/source/usb/USBDevice.cpp

Lines changed: 171 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "USBDescriptor.h"
2323
#include "usb_phy_api.h"
2424
#include "mbed_assert.h"
25+
#include "platform/mbed_error.h"
2526

2627
//#define DEBUG
2728

@@ -852,8 +853,17 @@ void USBDevice::ep0_setup()
852853
assert_locked();
853854

854855
if (_device.state < Default) {
855-
MBED_ASSERT(0);
856+
#if MBED_TRAP_ERRORS_ENABLED
857+
MBED_ERROR(
858+
MBED_MAKE_ERROR(
859+
MBED_MODULE_DRIVER_USB,
860+
MBED_ERROR_CODE_NOT_READY
861+
),
862+
"Device state is \"Powered\" or \"Detached\""
863+
);
864+
#else
856865
return;
866+
#endif // MBED_TRAP_ERRORS_ENABLED
857867
}
858868

859869
_setup_ready = true;
@@ -874,15 +884,33 @@ void USBDevice::ep0_out()
874884
assert_locked();
875885

876886
if (_device.state < Default) {
877-
MBED_ASSERT(0);
887+
#if MBED_TRAP_ERRORS_ENABLED
888+
MBED_ERROR(
889+
MBED_MAKE_ERROR(
890+
MBED_MODULE_DRIVER_USB,
891+
MBED_ERROR_CODE_NOT_READY
892+
),
893+
"Device state is \"Powered\" or \"Detached\""
894+
);
895+
#else
878896
return;
897+
#endif // MBED_TRAP_ERRORS_ENABLED
879898
}
880899

881900
if (_transfer.user_callback != None) {
882901
/* EP0 OUT should not receive data if the stack is waiting
883902
on a user callback for the buffer to fill or status */
884-
MBED_ASSERT(0);
903+
#if MBED_TRAP_ERRORS_ENABLED
904+
MBED_ERROR(
905+
MBED_MAKE_ERROR(
906+
MBED_MODULE_DRIVER_USB,
907+
MBED_ERROR_CODE_NOT_READY
908+
),
909+
"The stack is waiting on a user callback for the buffer to fill or status."
910+
);
911+
#else
885912
return;
913+
#endif // MBED_TRAP_ERRORS_ENABLED
886914
}
887915

888916
if (_transfer.stage == Status) {
@@ -903,8 +931,17 @@ void USBDevice::ep0_in()
903931
assert_locked();
904932

905933
if (_device.state < Default) {
906-
MBED_ASSERT(0);
934+
#if MBED_TRAP_ERRORS_ENABLED
935+
MBED_ERROR(
936+
MBED_MAKE_ERROR(
937+
MBED_MODULE_DRIVER_USB,
938+
MBED_ERROR_CODE_NOT_READY
939+
),
940+
"Device state is \"Powered\" or \"Detached\""
941+
);
942+
#else
907943
return;
944+
#endif // MBED_TRAP_ERRORS_ENABLED
908945
}
909946

910947
#ifdef DEBUG
@@ -928,8 +965,17 @@ void USBDevice::out(usb_ep_t endpoint)
928965
assert_locked();
929966

930967
if (!EP_INDEXABLE(endpoint)) {
931-
MBED_ASSERT(0);
968+
#if MBED_TRAP_ERRORS_ENABLED
969+
MBED_ERROR(
970+
MBED_MAKE_ERROR(
971+
MBED_MODULE_DRIVER_USB,
972+
MBED_ERROR_CODE_INVALID_INDEX
973+
),
974+
"The endpoint is not indexable."
975+
);
976+
#else
932977
return;
978+
#endif // MBED_TRAP_ERRORS_ENABLED
933979
}
934980

935981
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -946,8 +992,17 @@ void USBDevice::in(usb_ep_t endpoint)
946992
assert_locked();
947993

948994
if (!EP_INDEXABLE(endpoint)) {
949-
MBED_ASSERT(0);
995+
#if MBED_TRAP_ERRORS_ENABLED
996+
MBED_ERROR(
997+
MBED_MAKE_ERROR(
998+
MBED_MODULE_DRIVER_USB,
999+
MBED_ERROR_CODE_INVALID_INDEX
1000+
),
1001+
"The endpoint is not indexable."
1002+
);
1003+
#else
9501004
return;
1005+
#endif // MBED_TRAP_ERRORS_ENABLED
9511006
}
9521007

9531008
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1056,9 +1111,18 @@ bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep
10561111
lock();
10571112

10581113
if (!EP_INDEXABLE(endpoint)) {
1059-
MBED_ASSERT(0);
1114+
#if MBED_TRAP_ERRORS_ENABLED
1115+
MBED_ERROR(
1116+
MBED_MAKE_ERROR(
1117+
MBED_MODULE_DRIVER_USB,
1118+
MBED_ERROR_CODE_INVALID_INDEX
1119+
),
1120+
"The endpoint is not indexable."
1121+
);
1122+
#else
10601123
unlock();
10611124
return false;
1125+
#endif // MBED_TRAP_ERRORS_ENABLED
10621126
}
10631127

10641128
if (!_endpoint_add_remove_allowed) {
@@ -1087,9 +1151,18 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
10871151
lock();
10881152

10891153
if (!EP_INDEXABLE(endpoint)) {
1090-
MBED_ASSERT(0);
1154+
#if MBED_TRAP_ERRORS_ENABLED
1155+
MBED_ERROR(
1156+
MBED_MAKE_ERROR(
1157+
MBED_MODULE_DRIVER_USB,
1158+
MBED_ERROR_CODE_INVALID_INDEX
1159+
),
1160+
"The endpoint is not indexable."
1161+
);
1162+
#else
10911163
unlock();
10921164
return;
1165+
#endif // MBED_TRAP_ERRORS_ENABLED
10931166
}
10941167

10951168
if (!_endpoint_add_remove_allowed) {
@@ -1133,9 +1206,18 @@ void USBDevice::endpoint_stall(usb_ep_t endpoint)
11331206
lock();
11341207

11351208
if (!EP_INDEXABLE(endpoint)) {
1136-
MBED_ASSERT(0);
1209+
#if MBED_TRAP_ERRORS_ENABLED
1210+
MBED_ERROR(
1211+
MBED_MAKE_ERROR(
1212+
MBED_MODULE_DRIVER_USB,
1213+
MBED_ERROR_CODE_INVALID_INDEX
1214+
),
1215+
"The endpoint is not indexable."
1216+
);
1217+
#else
11371218
unlock();
11381219
return;
1220+
#endif // MBED_TRAP_ERRORS_ENABLED
11391221
}
11401222

11411223
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1161,9 +1243,18 @@ void USBDevice::endpoint_unstall(usb_ep_t endpoint)
11611243
lock();
11621244

11631245
if (!EP_INDEXABLE(endpoint)) {
1164-
MBED_ASSERT(0);
1246+
#if MBED_TRAP_ERRORS_ENABLED
1247+
MBED_ERROR(
1248+
MBED_MAKE_ERROR(
1249+
MBED_MODULE_DRIVER_USB,
1250+
MBED_ERROR_CODE_INVALID_INDEX
1251+
),
1252+
"The endpoint is not indexable."
1253+
);
1254+
#else
11651255
unlock();
11661256
return;
1257+
#endif // MBED_TRAP_ERRORS_ENABLED
11671258
}
11681259

11691260
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1307,9 +1398,18 @@ void USBDevice::endpoint_abort(usb_ep_t endpoint)
13071398
lock();
13081399

13091400
if (!EP_INDEXABLE(endpoint)) {
1310-
MBED_ASSERT(0);
1401+
#if MBED_TRAP_ERRORS_ENABLED
1402+
MBED_ERROR(
1403+
MBED_MAKE_ERROR(
1404+
MBED_MODULE_DRIVER_USB,
1405+
MBED_ERROR_CODE_INVALID_INDEX
1406+
),
1407+
"The endpoint is not indexable."
1408+
);
1409+
#else
13111410
unlock();
13121411
return;
1412+
#endif // MBED_TRAP_ERRORS_ENABLED
13131413
}
13141414

13151415
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1333,9 +1433,18 @@ bool USBDevice::read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size
13331433
lock();
13341434

13351435
if (!EP_INDEXABLE(endpoint)) {
1336-
MBED_ASSERT(0);
1436+
#if MBED_TRAP_ERRORS_ENABLED
1437+
MBED_ERROR(
1438+
MBED_MAKE_ERROR(
1439+
MBED_MODULE_DRIVER_USB,
1440+
MBED_ERROR_CODE_INVALID_INDEX
1441+
),
1442+
"The endpoint is not indexable."
1443+
);
1444+
#else
13371445
unlock();
13381446
return false;
1447+
#endif // MBED_TRAP_ERRORS_ENABLED
13391448
}
13401449

13411450
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1347,9 +1456,18 @@ bool USBDevice::read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size
13471456
}
13481457

13491458
if (max_size < info->max_packet_size) {
1350-
MBED_ASSERT(0);
1459+
#if MBED_TRAP_ERRORS_ENABLED
1460+
MBED_ERROR(
1461+
MBED_MAKE_ERROR(
1462+
MBED_MODULE_DRIVER_USB,
1463+
MBED_ERROR_CODE_INVALID_SIZE
1464+
),
1465+
"The size of the data to read is less than the max packet size for this endpoint."
1466+
);
1467+
#else
13511468
unlock();
13521469
return false;
1470+
#endif // MBED_TRAP_ERRORS_ENABLED
13531471
}
13541472

13551473
if (info->pending) {
@@ -1373,9 +1491,18 @@ uint32_t USBDevice::read_finish(usb_ep_t endpoint)
13731491
lock();
13741492

13751493
if (!EP_INDEXABLE(endpoint)) {
1376-
MBED_ASSERT(0);
1494+
#if MBED_TRAP_ERRORS_ENABLED
1495+
MBED_ERROR(
1496+
MBED_MAKE_ERROR(
1497+
MBED_MODULE_DRIVER_USB,
1498+
MBED_ERROR_CODE_INVALID_INDEX
1499+
),
1500+
"The endpoint is not indexable."
1501+
);
1502+
#else
13771503
unlock();
13781504
return 0;
1505+
#endif // MBED_TRAP_ERRORS_ENABLED
13791506
}
13801507

13811508
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1397,9 +1524,18 @@ bool USBDevice::write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
13971524
lock();
13981525

13991526
if (!EP_INDEXABLE(endpoint)) {
1400-
MBED_ASSERT(0);
1527+
#if MBED_TRAP_ERRORS_ENABLED
1528+
MBED_ERROR(
1529+
MBED_MAKE_ERROR(
1530+
MBED_MODULE_DRIVER_USB,
1531+
MBED_ERROR_CODE_INVALID_INDEX
1532+
),
1533+
"The endpoint is not indexable"
1534+
);
1535+
#else
14011536
unlock();
14021537
return false;
1538+
#endif // MBED_TRAP_ERRORS_ENABLED
14031539
}
14041540

14051541
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1411,10 +1547,18 @@ bool USBDevice::write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
14111547
}
14121548

14131549
if (size > info->max_packet_size) {
1414-
// Size being written is too large
1415-
MBED_ASSERT(0);
1550+
#if MBED_TRAP_ERRORS_ENABLED
1551+
MBED_ERROR(
1552+
MBED_MAKE_ERROR(
1553+
MBED_MODULE_DRIVER_USB,
1554+
MBED_ERROR_CODE_INVALID_SIZE
1555+
),
1556+
"Size being written is too large."
1557+
);
1558+
#else
14161559
unlock();
14171560
return false;
1561+
#endif // MBED_TRAP_ERRORS_ENABLED
14181562
}
14191563

14201564
if (info->pending) {
@@ -1443,9 +1587,18 @@ uint32_t USBDevice::write_finish(usb_ep_t endpoint)
14431587
lock();
14441588

14451589
if (!EP_INDEXABLE(endpoint)) {
1446-
MBED_ASSERT(0);
1590+
#if MBED_TRAP_ERRORS_ENABLED
1591+
MBED_ERROR(
1592+
MBED_MAKE_ERROR(
1593+
MBED_MODULE_DRIVER_USB,
1594+
MBED_ERROR_CODE_INVALID_INDEX
1595+
),
1596+
"The endpoint is not indexable."
1597+
);
1598+
#else
14471599
unlock();
14481600
return 0;
1601+
#endif // MBED_TRAP_ERRORS_ENABLED
14491602
}
14501603

14511604
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];

hal/mbed_pinmap_common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b)
5252

5353
// mis-match error case
5454
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
55-
return (uint32_t)NC;
5655
}
5756

5857
uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map)

hal/mbed_ticker_api.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "hal/ticker_api.h"
2020
#include "platform/mbed_critical.h"
2121
#include "platform/mbed_assert.h"
22+
#include "platform/mbed_error.h"
2223

2324
static void schedule_interrupt(const ticker_data_t *const ticker);
2425
static void update_present_time(const ticker_data_t *const ticker);
@@ -42,8 +43,17 @@ static void initialize(const ticker_data_t *ticker)
4243
const ticker_info_t *info = ticker->interface->get_info();
4344
uint32_t frequency = info->frequency;
4445
if (info->frequency == 0) {
45-
MBED_ASSERT(0);
46+
#if MBED_TRAP_ERRORS_ENABLED
47+
MBED_ERROR(
48+
MBED_MAKE_ERROR(
49+
MBED_MODULE_HAL,
50+
MBED_ERROR_CODE_NOT_READY
51+
),
52+
"Ticker frequency is zero"
53+
);
54+
#else
4655
frequency = 1000000;
56+
#endif // MBED_TRAP_ERRORS_ENABLED
4757
}
4858

4959
uint8_t frequency_shifts = 0;
@@ -56,8 +66,17 @@ static void initialize(const ticker_data_t *ticker)
5666

5767
uint32_t bits = info->bits;
5868
if ((info->bits > 32) || (info->bits < 4)) {
59-
MBED_ASSERT(0);
69+
#if MBED_TRAP_ERRORS_ENABLED
70+
MBED_ERROR(
71+
MBED_MAKE_ERROR(
72+
MBED_MODULE_HAL,
73+
MBED_ERROR_CODE_INVALID_SIZE
74+
),
75+
"Ticker number of bit is greater than 32 or less than 4 bits"
76+
);
77+
#else
6078
bits = 32;
79+
#endif // MBED_TRAP_ERRORS_ENABLED
6180
}
6281
uint32_t max_delta = 0x7 << (bits - 4); // 7/16th
6382
uint64_t max_delta_us =

0 commit comments

Comments
 (0)