niu: fix missing checks of niu_pci_eeprom_read
authorKangjie Lu <kjlu@umn.edu>
Tue, 25 Dec 2018 07:56:14 +0000 (01:56 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Feb 2019 18:47:17 +0000 (19:47 +0100)
[ Upstream commit 26fd962bde0b15e54234fe762d86bc0349df1de4 ]

niu_pci_eeprom_read() may fail, so we should check its return value
before using the read data.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Acked-by: Shannon Nelson <shannon.lee.nelson@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/sun/niu.c

index 9319d84bf49f07e9a9cf8514783dacb32b78fee7..d84501441eddeb812156ae206e92c869aa41f426 100644 (file)
@@ -8100,6 +8100,8 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end)
                start += 3;
 
                prop_len = niu_pci_eeprom_read(np, start + 4);
+               if (prop_len < 0)
+                       return prop_len;
                err = niu_pci_vpd_get_propname(np, start + 5, namebuf, 64);
                if (err < 0)
                        return err;
@@ -8144,8 +8146,12 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end)
                        netif_printk(np, probe, KERN_DEBUG, np->dev,
                                     "VPD_SCAN: Reading in property [%s] len[%d]\n",
                                     namebuf, prop_len);
-                       for (i = 0; i < prop_len; i++)
-                               *prop_buf++ = niu_pci_eeprom_read(np, off + i);
+                       for (i = 0; i < prop_len; i++) {
+                               err = niu_pci_eeprom_read(np, off + i);
+                               if (err >= 0)
+                                       *prop_buf = err;
+                               ++prop_buf;
+                       }
                }
 
                start += len;