ac: fix potential overflows

Reported by static analysis. Multiplication may overflow
before being converted to the larger type, so fix this
by casting one of the operands to the destination type.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35877>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2025-06-19 10:13:04 +02:00 committed by Marge Bot
parent 0c641c8170
commit 6e371f0a8a
4 changed files with 5 additions and 5 deletions

View file

@ -1164,7 +1164,7 @@ bool ac_init_block_names(const struct radeon_info *info,
block->group_name_stride += 2;
}
block->group_names = MALLOC(block->num_groups * block->group_name_stride);
block->group_names = MALLOC((size_t)block->num_groups * block->group_name_stride);
if (!block->group_names)
return false;
@ -1198,7 +1198,7 @@ bool ac_init_block_names(const struct radeon_info *info,
block->selector_name_stride = block->group_name_stride + 5;
block->selector_names =
MALLOC(block->num_groups * block->b->selectors * block->selector_name_stride);
MALLOC((size_t)block->num_groups * block->b->selectors * block->selector_name_stride);
if (!block->selector_names)
return false;

View file

@ -940,7 +940,7 @@ static void ac_sqtt_dump_spm(const struct ac_spm_trace *spm_trace,
spm_data_ptr += 32;
/* SPM timestamps. */
uint32_t sample_size_in_qwords = sample_size_in_bytes / sizeof(uint64_t);
uint64_t sample_size_in_qwords = sample_size_in_bytes / sizeof(uint64_t);
uint64_t *timestamp_ptr = (uint64_t *)spm_data_ptr;
for (uint32_t s = 0; s < num_samples; s++) {

View file

@ -28,7 +28,7 @@ ac_sqtt_get_data_offset(const struct radeon_info *rad_info, const struct ac_sqtt
uint64_t data_offset;
data_offset = align64(sizeof(struct ac_sqtt_data_info) * max_se, 1ull << SQTT_BUFFER_ALIGN_SHIFT);
data_offset += data->buffer_size * se;
data_offset += (size_t)data->buffer_size * se;
return data_offset;
}

View file

@ -430,7 +430,7 @@ radv_vcn_av1_film_grain_init_scaling(uint8_t scaling_points[][2], uint8_t num, s
delta_y = scaling_points[i + 1][1] - scaling_points[i][1];
delta_x = scaling_points[i + 1][0] - scaling_points[i][0];
delta = delta_y * ((65536 + (delta_x >> 1)) / delta_x);
delta = delta_y * (int64_t)((65536 + (delta_x >> 1)) / delta_x);
for (x = 0; x < delta_x; x++)
scaling_lut[scaling_points[i][0] + x] = (short)(scaling_points[i][1] + (int32_t)((x * delta + 32768) >> 16));