infra: round up input_size to even sizes and addresses

This commit is contained in:
Thomas Schoebel-Theuer 2024-01-16 14:52:47 +01:00
parent bd3fa16b64
commit 598cfc9d67
3 changed files with 18 additions and 5 deletions

View File

@ -201,6 +201,7 @@ int generic_brick_init_full(
for (i = 0; i < brick_type->max_inputs; i++) { for (i = 0; i < brick_type->max_inputs; i++) {
struct generic_input *input = data; struct generic_input *input = data;
const struct generic_input_type *type = *input_types++; const struct generic_input_type *type = *input_types++;
int input_size;
if (!type || type->input_size <= 0) { if (!type || type->input_size <= 0) {
return -EINVAL; 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); status = generic_input_init(brick, i, type, input, (names && *names) ? *names++ : type->type_name);
if (status < 0) if (status < 0)
return status; return status;
data += type->input_size; input_size = type->input_size;
size -= type->input_size; input_size = DIV_ROUND_UP(input_size,
sizeof(void *)) * sizeof(void *);
data += input_size;
size -= input_size;
if (size < 0) if (size < 0)
return -ENOMEM; return -ENOMEM;
} }

View File

@ -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 = DIV_ROUND_UP(size, sizeof(void *)) * sizeof(void *);
size += brick_type->max_inputs * sizeof(void*); size += brick_type->max_inputs * sizeof(void*);
for (i = 0; i < brick_type->max_inputs; i++) { 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*); size += brick_type->max_outputs * sizeof(void*);
for (i = 0; i < brick_type->max_outputs; i++) { for (i = 0; i < brick_type->max_outputs; i++) {

View File

@ -2849,15 +2849,20 @@ struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent
input_types = brick_type->default_input_types; input_types = brick_type->default_input_types;
for (i = 0; i < brick_type->max_inputs; i++) { for (i = 0; i < brick_type->max_inputs; i++) {
const struct generic_input_type *type = *input_types++; const struct generic_input_type *type = *input_types++;
int input_size;
if (unlikely(!type)) { if (unlikely(!type)) {
MARS_ERR("input_type %d is missing\n", i); MARS_ERR("input_type %d is missing\n", i);
goto err_name; 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); MARS_ERR("bad input_size at %d\n", i);
goto err_name; 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; output_types = brick_type->default_output_types;
for (i = 0; i < brick_type->max_outputs; i++) { for (i = 0; i < brick_type->max_outputs; i++) {