Skip to contentSkip to conversation

wifi: ath12k: move struct ath12k_hw from per device to group

bug report Dan Carpenter 3 participants 3 messages Dec 10, 2024 Qualcomm ATH12K wireless driver

lore
Share & tools
lore
#0 lore raw

Hello Karthikeyan Periyasamy,

Commit a343d97f27f5 ("wifi: ath12k: move struct ath12k_hw from per device to group") from Dec 4, 2024 (linux-next), leads to the following Smatch static checker warning:

	drivers/net/wireless/ath/ath12k/mac.c:10938 ath12k_mac_destroy()
	error: we previously assumed 'ab' could be null (see line 10927)

drivers/net/wireless/ath/ath12k/mac.c

    10918 void ath12k_mac_destroy(struct ath12k_hw_group *ag)
    10919 {
    10920         struct ath12k_pdev *pdev;
    10921         struct ath12k_base *ab = ag->ab[0];
    10922         int i, j;
    10923         struct ath12k_hw *ah;
    10924 
    10925         for (i = 0; i < ag->num_devices; i++) {
    10926                 ab = ag->ab[i];
    10927                 if (!ab)
                              ^^^

The patch addes this check for NULL. What about if it's the last element which is NULL?

    10928                         continue;
    10929 
    10930                 for (j = 0; j < ab->num_radios; j++) {
    10931                         pdev = &ab->pdevs[j];
    10932                         if (!pdev->ar)
    10933                                 continue;
    10934                         pdev->ar = NULL;
    10935                 }
    10936         }
    10937 
--> 10938         for (i = 0; i < ath12k_get_num_hw(ab); i++) {
                                                    ^^

If so, then it leads to a crash here.

    10939                 ah = ath12k_ab_to_ah(ab, i);
    10940                 if (!ah)
    10941                         continue;
    10942 
    10943                 ath12k_mac_hw_destroy(ah);
    10944                 ath12k_ab_set_ah(ab, i, NULL);
    10945         }
    10946 }

regards,
dan carpenter

#1 lore raw
Quoted 21 lines · Dan Carpenter

Hello Karthikeyan Periyasamy,

Commit a343d97f27f5 ("wifi: ath12k: move struct ath12k_hw from per device to group") from Dec 4, 2024 (linux-next), leads to the following Smatch static checker warning:

	drivers/net/wireless/ath/ath12k/mac.c:10938 ath12k_mac_destroy()
	error: we previously assumed 'ab' could be null (see line 10927)

drivers/net/wireless/ath/ath12k/mac.c

     10918 void ath12k_mac_destroy(struct ath12k_hw_group *ag)
     10919 {
     10920         struct ath12k_pdev *pdev;
     10921         struct ath12k_base *ab = ag->ab[0];
     10922         int i, j;
     10923         struct ath12k_hw *ah;
     10924
     10925         for (i = 0; i < ag->num_devices; i++) {
     10926                 ab = ag->ab[i];
     10927                 if (!ab)
                               ^^^
Quoted 2 lines

The patch addes this check for NULL. What about if it's the last element which is NULL?

In some error case, it is possible to NULL.

Quoted 13 lines
     10928                         continue;
     10929
     10930                 for (j = 0; j < ab->num_radios; j++) {
     10931                         pdev = &ab->pdevs[j];
     10932                         if (!pdev->ar)
     10933                                 continue;
     10934                         pdev->ar = NULL;
     10935                 }
     10936         }
     10937
--> 10938         for (i = 0; i < ath12k_get_num_hw(ab); i++) {
                                                     ^^
Quoted 1 line

If so, then it leads to a crash here.

Yes, will raise a patch.

Quoted 12 lines
     10939                 ah = ath12k_ab_to_ah(ab, i);
     10940                 if (!ah)
     10941                         continue;
     10942
     10943                 ath12k_mac_hw_destroy(ah);
     10944                 ath12k_ab_set_ah(ab, i, NULL);
     10945         }
     10946 }

regards,
dan carpenter

Signature · 3 lines
Karthikeyan Periyasamy
--
கார்த்திகேயன் பெரியசாமி
#2 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

Hello Karthikeyan Periyasamy,

Commit a343d97f27f5 ("wifi: ath12k: move struct ath12k_hw from per device to group") from Dec 4, 2024 (linux-next), leads to the following Smatch static checker warning:

	drivers/net/wireless/ath/ath12k/mac.c:10938 ath12k_mac_destroy()
	error: we previously assumed 'ab' could be null (see line 10927)

For completeness this is also flagged here:
https://scan7.scan.coverity.com/#/project-view/52682/11354?selectedIssue=1602340