ath5k: fix memory leak on buf on failed eeprom read
authorColin Ian King <colin.king@canonical.com>
Wed, 3 May 2017 14:26:00 +0000 (15:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Apr 2018 17:48:01 +0000 (19:48 +0200)
[ Upstream commit 8fed6823e06e43ee9cf7c0ffecec2f9111ce6201 ]

The AR5K_EEPROM_READ macro returns with -EIO if a read error
occurs causing a memory leak on the allocated buffer buf. Fix
this by explicitly calling ath5k_hw_nvram_read and exiting on
the via the freebuf label that performs the necessary free'ing
of buf when a read error occurs.

Detected by CoverityScan, CID#1248782 ("Resource Leak")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/wireless/ath/ath5k/debug.c

index 4f8d9ed..4a10544 100644 (file)
@@ -939,7 +939,10 @@ static int open_file_eeprom(struct inode *inode, struct file *file)
        }
 
        for (i = 0; i < eesize; ++i) {
-               AR5K_EEPROM_READ(i, val);
+               if (!ath5k_hw_nvram_read(ah, i, &val)) {
+                       ret = -EIO;
+                       goto freebuf;
+               }
                buf[i] = val;
        }