drivers: CAN: Limit the DLC to 8
This commit limits the data length code to eight. DLC > 8 returns a newly introduced CAN_TX_EINVAL error code. Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
This commit is contained in:
parent
4fc6a04eb1
commit
d558fd055a
6 changed files with 40 additions and 2 deletions
|
@ -56,6 +56,11 @@ int can_loopback_send(struct device *dev, const struct zcan_frame *frame,
|
|||
"standard" : "extended"
|
||||
, frame->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
|
||||
if (frame->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
if (!data->loopback) {
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -388,6 +388,11 @@ static int mcp2515_send(struct device *dev, const struct zcan_frame *msg,
|
|||
u8_t nnn;
|
||||
u8_t tx_frame[MCP2515_FRAME_LEN];
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", msg->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
if (k_sem_take(&dev_data->tx_sem, timeout) != 0) {
|
||||
return CAN_TIMEOUT;
|
||||
}
|
||||
|
|
|
@ -296,6 +296,11 @@ static int mcux_flexcan_send(struct device *dev, const struct zcan_frame *msg,
|
|||
status_t status;
|
||||
int alloc;
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", msg->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
alloc = mcux_get_tx_alloc(data);
|
||||
if (alloc >= 0) {
|
||||
|
|
|
@ -548,7 +548,11 @@ int can_stm32_send(struct device *dev, const struct zcan_frame *msg,
|
|||
, msg->rtr == CAN_DATAFRAME ? "no" : "yes");
|
||||
|
||||
__ASSERT(msg->dlc == 0U || msg->data != NULL, "Dataptr is null");
|
||||
__ASSERT(msg->dlc <= CAN_MAX_DLC, "DLC > 8");
|
||||
|
||||
if (msg->dlc > CAN_MAX_DLC) {
|
||||
LOG_ERR("DLC of %d exceeds maximum (%d)", msg->dlc, CAN_MAX_DLC);
|
||||
return CAN_TX_EINVAL;
|
||||
}
|
||||
|
||||
if (can->ESR & CAN_ESR_BOFF) {
|
||||
return CAN_TX_BUS_OFF;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue