1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-29 16:31:18 +01:00

cpu/sam0_common: fix potential undefined result with sercom_id

Scan-build detected that sercom_id could return -1 and the value of this function is affected to uint8_t variables. Since these variables are used for shitfing bit in registers, this could lead to undefined behavior
This commit is contained in:
Alexandre Abadie 2019-10-25 19:07:20 +02:00
parent c1ea3c2eb6
commit 1c416185b6
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405

View File

@ -340,42 +340,53 @@ void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
*
* @return numeric id of the given SERCOM device
*/
static inline int sercom_id(const void *sercom)
static inline uint8_t sercom_id(const void *sercom)
{
#ifdef SERCOM0
if (sercom == SERCOM0)
if (sercom == SERCOM0) {
return 0;
}
#endif
#ifdef SERCOM1
if (sercom == SERCOM1)
if (sercom == SERCOM1) {
return 1;
}
#endif
#ifdef SERCOM2
if (sercom == SERCOM2)
if (sercom == SERCOM2) {
return 2;
}
#endif
#ifdef SERCOM3
if (sercom == SERCOM3)
if (sercom == SERCOM3) {
return 3;
}
#endif
#ifdef SERCOM4
if (sercom == SERCOM4)
if (sercom == SERCOM4) {
return 4;
}
#endif
#ifdef SERCOM5
if (sercom == SERCOM5)
if (sercom == SERCOM5) {
return 5;
}
#endif
#ifdef SERCOM6
if (sercom == SERCOM6)
if (sercom == SERCOM6) {
return 6;
}
#endif
#ifdef SERCOM7
if (sercom == SERCOM7)
if (sercom == SERCOM7) {
return 7;
}
#endif
return -1;
/* should not be reached, so fail with assert */
assert(false);
return SERCOM_INST_NUM;
}
/**