usb: prevent registering duplicate config callbacks
Originally discussed at https://github.com/libopencm3/libopencm3/pull/722
This commit is contained in:
parent
c55ec70f49
commit
f4bbe7c5bb
@ -139,7 +139,8 @@ extern int usbd_register_control_callback(usbd_device *usbd_dev, uint8_t type,
|
|||||||
|
|
||||||
/* <usb_standard.c> */
|
/* <usb_standard.c> */
|
||||||
/** Registers a "Set Config" callback
|
/** Registers a "Set Config" callback
|
||||||
* @return 0 if successful
|
* @return 0 if successful or already existed.
|
||||||
|
* @return -1 if no more space was available for callbacks.
|
||||||
*/
|
*/
|
||||||
extern int usbd_register_set_config_callback(usbd_device *usbd_dev,
|
extern int usbd_register_set_config_callback(usbd_device *usbd_dev,
|
||||||
usbd_set_config_callback callback);
|
usbd_set_config_callback callback);
|
||||||
|
@ -46,6 +46,9 @@ int usbd_register_set_config_callback(usbd_device *usbd_dev,
|
|||||||
|
|
||||||
for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
|
for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
|
||||||
if (usbd_dev->user_callback_set_config[i]) {
|
if (usbd_dev->user_callback_set_config[i]) {
|
||||||
|
if (usbd_dev->user_callback_set_config[i] == callback) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user