Skip to content

Commit 960a581

Browse files
libinyangtiwai
authored andcommitted
ALSA: hda: fix some klockwork scan warnings
This patch fixes some warnings from klockwork. These warnings are not the real issues. The patch adds the sanity check. Signed-off-by: Libin Yang <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 76f64b2 commit 960a581

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

sound/hda/hdmi_chmap.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ static void hdmi_std_setup_channel_mapping(struct hdac_chmap *chmap,
353353
int hdmi_slot = 0;
354354
/* fill actual channel mappings in ALSA channel (i) order */
355355
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])
357358
hdmi_slot++; /* skip zero slots */
358359

359360
hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
@@ -430,6 +431,12 @@ static int to_cea_slot(int ordered_ca, unsigned char pos)
430431
int mask = snd_hdac_chmap_to_spk_mask(pos);
431432
int i;
432433

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+
433440
if (mask) {
434441
for (i = 0; i < 8; i++) {
435442
if (channel_allocations[ordered_ca].speakers[7 - i] == mask)
@@ -456,7 +463,15 @@ EXPORT_SYMBOL_GPL(snd_hdac_spk_to_chmap);
456463
/* from CEA slot to ALSA API channel position */
457464
static int from_cea_slot(int ordered_ca, unsigned char slot)
458465
{
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];
460475

461476
return snd_hdac_spk_to_chmap(mask);
462477
}
@@ -523,7 +538,8 @@ static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
523538
int ordered_ca = get_channel_allocation_order(ca);
524539

525540
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)
527543
map[i] = from_cea_slot(ordered_ca, hdmi_channel_mapping[ca][i] & 0x0f);
528544
else
529545
map[i] = 0;
@@ -551,6 +567,12 @@ int snd_hdac_get_active_channels(int ca)
551567
{
552568
int ordered_ca = get_channel_allocation_order(ca);
553569

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+
554576
return channel_allocations[ordered_ca].channels;
555577
}
556578
EXPORT_SYMBOL_GPL(snd_hdac_get_active_channels);

sound/pci/hda/hda_codec.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,12 @@ static void setup_dig_out_stream(struct hda_codec *codec, hda_nid_t nid,
35843584
bool reset;
35853585

35863586
spdif = snd_hda_spdif_out_of_nid(codec, nid);
3587+
/* Add sanity check to pass klockwork check.
3588+
* This should never happen.
3589+
*/
3590+
if (WARN_ON(spdif == NULL))
3591+
return;
3592+
35873593
curr_fmt = snd_hda_codec_read(codec, nid, 0,
35883594
AC_VERB_GET_STREAM_FORMAT, 0);
35893595
reset = codec->spdif_status_reset &&
@@ -3768,7 +3774,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
37683774
spdif = snd_hda_spdif_out_of_nid(codec, mout->dig_out_nid);
37693775
if (mout->dig_out_nid && mout->share_spdif &&
37703776
mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
3771-
if (chs == 2 &&
3777+
if (chs == 2 && spdif != NULL &&
37723778
snd_hda_is_supported_format(codec, mout->dig_out_nid,
37733779
format) &&
37743780
!(spdif->status & IEC958_AES0_NONAUDIO)) {

sound/pci/hda/patch_hdmi.c

+5
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,11 @@ static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
16801680

16811681
mutex_lock(&codec->spdif_mutex);
16821682
spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
1683+
/* Add sanity check to pass klockwork check.
1684+
* This should never happen.
1685+
*/
1686+
if (WARN_ON(spdif == NULL))
1687+
return true;
16831688
non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
16841689
mutex_unlock(&codec->spdif_mutex);
16851690
return non_pcm;

0 commit comments

Comments
 (0)