@@ -353,7 +353,8 @@ static void hdmi_std_setup_channel_mapping(struct hdac_chmap *chmap,
353
353
int hdmi_slot = 0 ;
354
354
/* fill actual channel mappings in ALSA channel (i) order */
355
355
for (i = 0 ; i < ch_alloc -> channels ; i ++ ) {
356
- while (!ch_alloc -> speakers [7 - hdmi_slot ] && !WARN_ON (hdmi_slot >= 8 ))
356
+ while (!WARN_ON (hdmi_slot >= 8 ) &&
357
+ !ch_alloc -> speakers [7 - hdmi_slot ])
357
358
hdmi_slot ++ ; /* skip zero slots */
358
359
359
360
hdmi_channel_mapping [ca ][i ] = (i << 4 ) | hdmi_slot ++ ;
@@ -430,6 +431,12 @@ static int to_cea_slot(int ordered_ca, unsigned char pos)
430
431
int mask = snd_hdac_chmap_to_spk_mask (pos );
431
432
int i ;
432
433
434
+ /* Add sanity check to pass klockwork check.
435
+ * This should never happen.
436
+ */
437
+ if (ordered_ca >= ARRAY_SIZE (channel_allocations ))
438
+ return -1 ;
439
+
433
440
if (mask ) {
434
441
for (i = 0 ; i < 8 ; i ++ ) {
435
442
if (channel_allocations [ordered_ca ].speakers [7 - i ] == mask )
@@ -456,7 +463,15 @@ EXPORT_SYMBOL_GPL(snd_hdac_spk_to_chmap);
456
463
/* from CEA slot to ALSA API channel position */
457
464
static int from_cea_slot (int ordered_ca , unsigned char slot )
458
465
{
459
- int mask = channel_allocations [ordered_ca ].speakers [7 - slot ];
466
+ int mask ;
467
+
468
+ /* Add sanity check to pass klockwork check.
469
+ * This should never happen.
470
+ */
471
+ if (slot >= 8 )
472
+ return 0 ;
473
+
474
+ mask = channel_allocations [ordered_ca ].speakers [7 - slot ];
460
475
461
476
return snd_hdac_spk_to_chmap (mask );
462
477
}
@@ -523,7 +538,8 @@ static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
523
538
int ordered_ca = get_channel_allocation_order (ca );
524
539
525
540
for (i = 0 ; i < 8 ; i ++ ) {
526
- if (i < channel_allocations [ordered_ca ].channels )
541
+ if (ordered_ca < ARRAY_SIZE (channel_allocations ) &&
542
+ i < channel_allocations [ordered_ca ].channels )
527
543
map [i ] = from_cea_slot (ordered_ca , hdmi_channel_mapping [ca ][i ] & 0x0f );
528
544
else
529
545
map [i ] = 0 ;
@@ -551,6 +567,12 @@ int snd_hdac_get_active_channels(int ca)
551
567
{
552
568
int ordered_ca = get_channel_allocation_order (ca );
553
569
570
+ /* Add sanity check to pass klockwork check.
571
+ * This should never happen.
572
+ */
573
+ if (ordered_ca >= ARRAY_SIZE (channel_allocations ))
574
+ ordered_ca = 0 ;
575
+
554
576
return channel_allocations [ordered_ca ].channels ;
555
577
}
556
578
EXPORT_SYMBOL_GPL (snd_hdac_get_active_channels );
0 commit comments