bab ensure there's enough space for the nonce reply
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/driver-bab.c b/driver-bab.c
index 6f3590a..6d00544 100644
--- a/driver-bab.c
+++ b/driver-bab.c
@@ -72,6 +72,7 @@ static void bab_detect(__maybe_unused bool hotplug)
#define BAB_X_COORD 21
#define BAB_Y_COORD 36
+#define BAB_NOOP 0
#define BAB_BREAK ((uint8_t *)"\04")
#define BAB_ASYNC ((uint8_t *)"\05")
#define BAB_SYNC ((uint8_t *)"\06")
@@ -88,6 +89,8 @@ static void bab_detect(__maybe_unused bool hotplug)
#define bab_config_reg(_item, _reg, _ena) _bab_config_reg(_item, _reg, _ena, BAB_FFL_HERE)
#define bab_add_data(_item, _addr, _data, _siz) _bab_add_data(_item, _addr, (const uint8_t *)(_data), _siz, BAB_FFL_HERE)
+#define BAB_ADD_NOOPs(_item, _count) _bab_add_noops(_item, _count, BAB_FFL_HERE)
+
#define BAB_ADD_MIN 4
#define BAB_ADD_MAX 128
@@ -234,6 +237,8 @@ struct bab_work_reply {
uint32_t jobsel;
};
+#define BAB_CHIP_MIN sizeof(struct bab_work_reply)
+
#define ALLOC_WITEMS 1024
#define LIMIT_WITEMS 0
@@ -703,6 +708,21 @@ static void _bab_add_buf(K_ITEM *item, const uint8_t *data, size_t siz, const ch
DATAS(item)->siz += siz;
}
+static void _bab_add_noops(K_ITEM *item, size_t siz, const char *file, const char *func, const int line)
+{
+ uint32_t now_used;
+
+ now_used = DATAS(item)->siz;
+ if (now_used + siz >= BAB_MAXBUF) {
+ quitfrom(1, file, func, line,
+ "%s() DATAS buffer limit of %d exceeded=%d siz=%d",
+ __func__, BAB_MAXBUF, (int)(now_used + siz), (int)siz);
+ }
+
+ memset(&(DATAS(item)->wbuf[now_used]), BAB_NOOP, siz);
+ DATAS(item)->siz += siz;
+}
+
static void _bab_add_data(K_ITEM *item, uint32_t addr, const uint8_t *data, size_t siz, const char *file, const char *func, const int line)
{
uint8_t tmp[3];
@@ -754,6 +774,7 @@ static void bab_put(struct bab_info *babinfo, K_ITEM *sitem)
{
struct bab_work_send *chip_input;
int i, reg, bank = 0;
+ size_t chip_siz;
BAB_ADD_BREAK(sitem);
for (i = 0; i < babinfo->chips; i++) {
@@ -819,6 +840,10 @@ static void bab_put(struct bab_info *babinfo, K_ITEM *sitem)
if (babinfo->chip_conf[i])
bab_add_data(sitem, BAB_INP_ADDR, (uint8_t *)chip_input, sizeof(*chip_input));
+ chip_siz = DATAS(sitem)->siz - babinfo->chip_conf[i];
+ if (chip_siz < BAB_CHIP_MIN)
+ BAB_ADD_NOOPs(sitem, BAB_CHIP_MIN - chip_siz);
+
BAB_ADD_ASYNC(sitem);
}
DATAS(sitem)->chip_off[i] = DATAS(sitem)->siz;