|
71 | 71 | #define SLCAN_CMD_LEN 1
|
72 | 72 | #define SLCAN_SFF_ID_LEN 3
|
73 | 73 | #define SLCAN_EFF_ID_LEN 8
|
| 74 | +#define SLCAN_DATA_LENGTH_LEN 1 |
| 75 | +#define SLCAN_ERROR_LEN 1 |
74 | 76 | #define SLCAN_STATE_LEN 1
|
75 | 77 | #define SLCAN_STATE_BE_RXCNT_LEN 3
|
76 | 78 | #define SLCAN_STATE_BE_TXCNT_LEN 3
|
77 |
| -#define SLCAN_STATE_FRAME_LEN (1 + SLCAN_CMD_LEN + \ |
78 |
| - SLCAN_STATE_BE_RXCNT_LEN + \ |
79 |
| - SLCAN_STATE_BE_TXCNT_LEN) |
| 79 | +#define SLCAN_STATE_MSG_LEN (SLCAN_CMD_LEN + \ |
| 80 | + SLCAN_STATE_LEN + \ |
| 81 | + SLCAN_STATE_BE_RXCNT_LEN + \ |
| 82 | + SLCAN_STATE_BE_TXCNT_LEN) |
| 83 | +#define SLCAN_ERROR_MSG_LEN_MIN (SLCAN_CMD_LEN + \ |
| 84 | + SLCAN_ERROR_LEN + \ |
| 85 | + SLCAN_DATA_LENGTH_LEN) |
| 86 | +#define SLCAN_FRAME_MSG_LEN_MIN (SLCAN_CMD_LEN + \ |
| 87 | + SLCAN_SFF_ID_LEN + \ |
| 88 | + SLCAN_DATA_LENGTH_LEN) |
80 | 89 | struct slcan {
|
81 | 90 | struct can_priv can;
|
82 | 91 |
|
@@ -176,6 +185,9 @@ static void slcan_bump_frame(struct slcan *sl)
|
176 | 185 | u32 tmpid;
|
177 | 186 | char *cmd = sl->rbuff;
|
178 | 187 |
|
| 188 | + if (sl->rcount < SLCAN_FRAME_MSG_LEN_MIN) |
| 189 | + return; |
| 190 | + |
179 | 191 | skb = alloc_can_skb(sl->dev, &cf);
|
180 | 192 | if (unlikely(!skb)) {
|
181 | 193 | sl->dev->stats.rx_dropped++;
|
@@ -281,7 +293,7 @@ static void slcan_bump_state(struct slcan *sl)
|
281 | 293 | return;
|
282 | 294 | }
|
283 | 295 |
|
284 |
| - if (state == sl->can.state || sl->rcount < SLCAN_STATE_FRAME_LEN) |
| 296 | + if (state == sl->can.state || sl->rcount != SLCAN_STATE_MSG_LEN) |
285 | 297 | return;
|
286 | 298 |
|
287 | 299 | cmd += SLCAN_STATE_BE_RXCNT_LEN + SLCAN_CMD_LEN + 1;
|
@@ -328,6 +340,9 @@ static void slcan_bump_err(struct slcan *sl)
|
328 | 340 | bool rx_errors = false, tx_errors = false, rx_over_errors = false;
|
329 | 341 | int i, len;
|
330 | 342 |
|
| 343 | + if (sl->rcount < SLCAN_ERROR_MSG_LEN_MIN) |
| 344 | + return; |
| 345 | + |
331 | 346 | /* get len from sanitized ASCII value */
|
332 | 347 | len = cmd[1];
|
333 | 348 | if (len >= '0' && len < '9')
|
@@ -456,8 +471,7 @@ static void slcan_bump(struct slcan *sl)
|
456 | 471 | static void slcan_unesc(struct slcan *sl, unsigned char s)
|
457 | 472 | {
|
458 | 473 | if ((s == '\r') || (s == '\a')) { /* CR or BEL ends the pdu */
|
459 |
| - if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && |
460 |
| - sl->rcount > 4) |
| 474 | + if (!test_and_clear_bit(SLF_ERROR, &sl->flags)) |
461 | 475 | slcan_bump(sl);
|
462 | 476 |
|
463 | 477 | sl->rcount = 0;
|
|
0 commit comments