1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

com/usart/cdc: ensure that device structs are memset before use

CDC and USART device drivers were not all clearing their
device structs before using them.

This specifically caused crashes in the case where the upper
COM layer was binding only a Tx path.  The Rx path callback
in the lower driver was uninitialized random data and would
result in the lower driver faulting when it tried to call the
callback.

Conflicts:
	flight/PiOS/STM32F30x/pios_usart.c
	flight/PiOS/STM32F30x/pios_usb_cdc.c
	flight/PiOS/STM32F30x/pios_usb_hid.c
This commit is contained in:
Stacey Sheldon 2013-03-14 22:57:57 -04:00 committed by Alessio Morale
parent e16be98224
commit b56f5206bd
7 changed files with 21 additions and 4 deletions

View File

@ -73,6 +73,7 @@ static struct pios_com_dev * PIOS_COM_alloc(void)
com_dev = (struct pios_com_dev *)pvPortMalloc(sizeof(*com_dev));
if (!com_dev) return (NULL);
memset(com_dev, 0, sizeof(*com_dev));
com_dev->magic = PIOS_COM_DEV_MAGIC;
return(com_dev);
}
@ -88,6 +89,8 @@ static struct pios_com_dev * PIOS_COM_alloc(void)
}
com_dev = &pios_com_devs[pios_com_num_devs++];
memset(com_dev, 0, sizeof(*com_dev));
com_dev->magic = PIOS_COM_DEV_MAGIC;
return (com_dev);

View File

@ -78,6 +78,7 @@ static struct pios_usart_dev * PIOS_USART_alloc(void)
usart_dev = (struct pios_usart_dev *)pvPortMalloc(sizeof(*usart_dev));
if (!usart_dev) return(NULL);
memset(usart_dev, 0, sizeof(*usart_dev));
usart_dev->magic = PIOS_USART_DEV_MAGIC;
return(usart_dev);
}
@ -93,6 +94,8 @@ static struct pios_usart_dev * PIOS_USART_alloc(void)
}
usart_dev = &pios_usart_devs[pios_usart_num_devs++];
memset(usart_dev, 0, sizeof(*usart_dev));
usart_dev->magic = PIOS_USART_DEV_MAGIC;
return (usart_dev);

View File

@ -88,6 +88,7 @@ static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
usb_cdc_dev = (struct pios_usb_cdc_dev *)pvPortMalloc(sizeof(*usb_cdc_dev));
if (!usb_cdc_dev) return(NULL);
memset(usb_cdc_dev, 0, sizeof(*usb_cdc_dev));
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return(usb_cdc_dev);
}
@ -103,6 +104,8 @@ static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
}
usb_cdc_dev = &pios_usb_cdc_devs[pios_usb_cdc_num_devs++];
memset(usb_cdc_dev, 0, sizeof(*usb_cdc_dev));
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return (usb_cdc_dev);

View File

@ -87,6 +87,7 @@ static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
usb_hid_dev = (struct pios_usb_hid_dev *)pvPortMalloc(sizeof(*usb_hid_dev));
if (!usb_hid_dev) return(NULL);
memset(usb_hid_dev, 0, sizeof(*usb_hid_dev));
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return(usb_hid_dev);
}
@ -102,6 +103,8 @@ static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
}
usb_hid_dev = &pios_usb_hid_devs[pios_usb_hid_num_devs++];
memset(usb_hid_dev, 0, sizeof(*usb_hid_dev));
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return (usb_hid_dev);

View File

@ -80,10 +80,7 @@ static struct pios_usart_dev * PIOS_USART_alloc(void)
usart_dev = (struct pios_usart_dev *)pvPortMalloc(sizeof(*usart_dev));
if (!usart_dev) return(NULL);
usart_dev->rx_in_cb = 0;
usart_dev->rx_in_context = 0;
usart_dev->tx_out_cb = 0;
usart_dev->tx_out_context = 0;
memset(usart_dev, 0, sizeof(*usart_dev));
usart_dev->magic = PIOS_USART_DEV_MAGIC;
return(usart_dev);
}
@ -99,6 +96,8 @@ static struct pios_usart_dev * PIOS_USART_alloc(void)
}
usart_dev = &pios_usart_devs[pios_usart_num_devs++];
memset(usart_dev, 0, sizeof(*usart_dev));
usart_dev->magic = PIOS_USART_DEV_MAGIC;
return (usart_dev);

View File

@ -101,6 +101,7 @@ static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
usb_cdc_dev = (struct pios_usb_cdc_dev *)pvPortMalloc(sizeof(*usb_cdc_dev));
if (!usb_cdc_dev) return(NULL);
memset(usb_cdc_dev, 0, sizeof(*usb_cdc_dev));
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return(usb_cdc_dev);
}
@ -116,6 +117,8 @@ static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
}
usb_cdc_dev = &pios_usb_cdc_devs[pios_usb_cdc_num_devs++];
memset(usb_cdc_dev, 0, sizeof(*usb_cdc_dev));
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return (usb_cdc_dev);

View File

@ -90,6 +90,7 @@ static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
usb_hid_dev = (struct pios_usb_hid_dev *)pvPortMalloc(sizeof(*usb_hid_dev));
if (!usb_hid_dev) return(NULL);
memset(usb_hid_dev, 0, sizeof(*usb_hid_dev));
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return(usb_hid_dev);
}
@ -105,6 +106,8 @@ static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
}
usb_hid_dev = &pios_usb_hid_devs[pios_usb_hid_num_devs++];
memset(usb_hid_dev, 0, sizeof(*usb_hid_dev));
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return (usb_hid_dev);