Skip to content

Commit c7d5897

Browse files
keestiwai
authored andcommitted
ALSA: mixart: Reduce size of mixart_timer_notify
The mixart_timer_notify structure was larger than could be represented by the mixart_msg_data array storage. Adjust the size to as large as possible to fix the warning seen with -Warray-bounds builds: sound/pci/mixart/mixart_core.c: In function 'snd_mixart_threaded_irq': sound/pci/mixart/mixart_core.c:447:50: error: array subscript 'struct mixart_timer_notify[0]' is partly outside array bounds of 'u32[128]' {aka 'unsigned int[128]'} [-Werror=array-bounds] 447 | for(i=0; i<notify->stream_count; i++) { | ^~ sound/pci/mixart/mixart_core.c:328:12: note: while referencing 'mixart_msg_data' 328 | static u32 mixart_msg_data[MSG_DEFAULT_SIZE / 4]; | ^~~~~~~~~~~~~~~ Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20211207062941.2413679-1-keescook@chromium.org Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 86a9bb5 commit c7d5897

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

sound/pci/mixart/mixart_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#define MSG_DESCRIPTOR_SIZE 0x24
2424
#define MSG_HEADER_SIZE (MSG_DESCRIPTOR_SIZE + 4)
2525

26-
#define MSG_DEFAULT_SIZE 512
27-
2826
#define MSG_TYPE_MASK 0x00000003 /* mask for following types */
2927
#define MSG_TYPE_NOTIFY 0 /* embedded -> driver (only notification, do not get_msg() !) */
3028
#define MSG_TYPE_COMMAND 1 /* driver <-> embedded (a command has no answer) */
@@ -444,6 +442,7 @@ irqreturn_t snd_mixart_threaded_irq(int irq, void *dev_id)
444442
struct mixart_timer_notify *notify;
445443
notify = (struct mixart_timer_notify *)mixart_msg_data;
446444

445+
BUILD_BUG_ON(sizeof(notify) > sizeof(mixart_msg_data));
447446
for(i=0; i<notify->stream_count; i++) {
448447

449448
u32 buffer_id = notify->streams[i].buffer_id;

sound/pci/mixart/mixart_core.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum mixart_message_id {
4949
MSG_CLOCK_SET_PROPERTIES = 0x200002,
5050
};
5151

52+
#define MSG_DEFAULT_SIZE 512
5253

5354
struct mixart_msg
5455
{
@@ -251,10 +252,17 @@ struct mixart_sample_pos
251252
u32 sample_pos_low_part;
252253
} __attribute__((packed));
253254

255+
/*
256+
* This structure is limited by the size of MSG_DEFAULT_SIZE. Instead of
257+
* having MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS many streams,
258+
* this is capped to have a total size below MSG_DEFAULT_SIZE.
259+
*/
260+
#define MIXART_MAX_TIMER_NOTIFY_STREAMS \
261+
((MSG_DEFAULT_SIZE - sizeof(u32)) / sizeof(struct mixart_sample_pos))
254262
struct mixart_timer_notify
255263
{
256264
u32 stream_count;
257-
struct mixart_sample_pos streams[MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS];
265+
struct mixart_sample_pos streams[MIXART_MAX_TIMER_NOTIFY_STREAMS];
258266
} __attribute__((packed));
259267

260268

0 commit comments

Comments
 (0)