From 598cfc9d673d3ba84b262d1e8a9476e424029c69 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Tue, 16 Jan 2024 14:52:47 +0100 Subject: [PATCH] infra: round up input_size to even sizes and addresses --- kernel/brick.c | 8 ++++++-- kernel/brick.h | 6 +++++- kernel/sy_old/sy_generic.c | 9 +++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/brick.c b/kernel/brick.c index 9ffd3b51..16ed3739 100644 --- a/kernel/brick.c +++ b/kernel/brick.c @@ -201,6 +201,7 @@ int generic_brick_init_full( for (i = 0; i < brick_type->max_inputs; i++) { struct generic_input *input = data; const struct generic_input_type *type = *input_types++; + int input_size; if (!type || type->input_size <= 0) { return -EINVAL; @@ -209,8 +210,11 @@ int generic_brick_init_full( status = generic_input_init(brick, i, type, input, (names && *names) ? *names++ : type->type_name); if (status < 0) return status; - data += type->input_size; - size -= type->input_size; + input_size = type->input_size; + input_size = DIV_ROUND_UP(input_size, + sizeof(void *)) * sizeof(void *); + data += input_size; + size -= input_size; if (size < 0) return -ENOMEM; } diff --git a/kernel/brick.h b/kernel/brick.h index d8991526..5ce11fa4 100644 --- a/kernel/brick.h +++ b/kernel/brick.h @@ -561,7 +561,11 @@ INLINE int generic_size(const struct generic_brick_type *brick_type) size = DIV_ROUND_UP(size, sizeof(void *)) * sizeof(void *); size += brick_type->max_inputs * sizeof(void*); for (i = 0; i < brick_type->max_inputs; i++) { - size += brick_type->default_input_types[i]->input_size; + int input_size = brick_type->default_input_types[i]->input_size; + + input_size = DIV_ROUND_UP(input_size, + sizeof(void *)) * sizeof(void *); + size += input_size; } size += brick_type->max_outputs * sizeof(void*); for (i = 0; i < brick_type->max_outputs; i++) { diff --git a/kernel/sy_old/sy_generic.c b/kernel/sy_old/sy_generic.c index 11c523bb..cc77fc6e 100644 --- a/kernel/sy_old/sy_generic.c +++ b/kernel/sy_old/sy_generic.c @@ -2849,15 +2849,20 @@ struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent input_types = brick_type->default_input_types; for (i = 0; i < brick_type->max_inputs; i++) { const struct generic_input_type *type = *input_types++; + int input_size; + if (unlikely(!type)) { MARS_ERR("input_type %d is missing\n", i); goto err_name; } - if (unlikely(type->input_size <= 0)) { + input_size = type->input_size; + if (unlikely(input_size <= 0)) { MARS_ERR("bad input_size at %d\n", i); goto err_name; } - size += type->input_size; + input_size = DIV_ROUND_UP(input_size, + sizeof(void *)) * sizeof(void *); + size += input_size; } output_types = brick_type->default_output_types; for (i = 0; i < brick_type->max_outputs; i++) {