Commit e6e33770 authored by Du Cheng's avatar Du Cheng Committed by Greg Kroah-Hartman

ethernet: sun: niu: fix missing checks of niu_pci_eeprom_read()

niu_pci_eeprom_read() may fail, so add checks to its return value and
propagate the error up the callstack.

An examination of the callstack up to niu_pci_eeprom_read shows that:

niu_pci_eeprom_read() // returns int
    niu_pci_vpd_scan_props() // returns int
        niu_pci_vpd_fetch() // returns *void*
            niu_get_invariants() // returns int

since niu_pci_vpd_fetch() returns void which breaks the bubbling up,
change its return type to int so that error is propagated upwards.
Signed-off-by: default avatarDu Cheng <ducheng2@gmail.com>
Cc: Shannon Nelson <shannon.lee.nelson@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210503115736.2104747-24-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7930742d
...@@ -8097,6 +8097,8 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) ...@@ -8097,6 +8097,8 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end)
start += 3; start += 3;
prop_len = niu_pci_eeprom_read(np, start + 4); 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); err = niu_pci_vpd_get_propname(np, start + 5, namebuf, 64);
if (err < 0) if (err < 0)
return err; return err;
...@@ -8141,8 +8143,12 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) ...@@ -8141,8 +8143,12 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end)
netif_printk(np, probe, KERN_DEBUG, np->dev, netif_printk(np, probe, KERN_DEBUG, np->dev,
"VPD_SCAN: Reading in property [%s] len[%d]\n", "VPD_SCAN: Reading in property [%s] len[%d]\n",
namebuf, prop_len); namebuf, prop_len);
for (i = 0; i < prop_len; i++) for (i = 0; i < prop_len; i++) {
*prop_buf++ = niu_pci_eeprom_read(np, off + i); err = niu_pci_eeprom_read(np, off + i);
if (err < 0)
return err;
*prop_buf++ = err;
}
} }
start += len; start += len;
...@@ -8152,14 +8158,14 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end) ...@@ -8152,14 +8158,14 @@ static int niu_pci_vpd_scan_props(struct niu *np, u32 start, u32 end)
} }
/* ESPC_PIO_EN_ENABLE must be set */ /* ESPC_PIO_EN_ENABLE must be set */
static void niu_pci_vpd_fetch(struct niu *np, u32 start) static int niu_pci_vpd_fetch(struct niu *np, u32 start)
{ {
u32 offset; u32 offset;
int err; int err;
err = niu_pci_eeprom_read16_swp(np, start + 1); err = niu_pci_eeprom_read16_swp(np, start + 1);
if (err < 0) if (err < 0)
return; return err;
offset = err + 3; offset = err + 3;
...@@ -8168,12 +8174,14 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start) ...@@ -8168,12 +8174,14 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start)
u32 end; u32 end;
err = niu_pci_eeprom_read(np, here); err = niu_pci_eeprom_read(np, here);
if (err < 0)
return err;
if (err != 0x90) if (err != 0x90)
return; return -EINVAL;
err = niu_pci_eeprom_read16_swp(np, here + 1); err = niu_pci_eeprom_read16_swp(np, here + 1);
if (err < 0) if (err < 0)
return; return err;
here = start + offset + 3; here = start + offset + 3;
end = start + offset + err; end = start + offset + err;
...@@ -8181,9 +8189,12 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start) ...@@ -8181,9 +8189,12 @@ static void niu_pci_vpd_fetch(struct niu *np, u32 start)
offset += err; offset += err;
err = niu_pci_vpd_scan_props(np, here, end); err = niu_pci_vpd_scan_props(np, here, end);
if (err < 0 || err == 1) if (err < 0)
return; return err;
if (err == 1)
return -EINVAL;
} }
return 0;
} }
/* ESPC_PIO_EN_ENABLE must be set */ /* ESPC_PIO_EN_ENABLE must be set */
...@@ -9274,8 +9285,11 @@ static int niu_get_invariants(struct niu *np) ...@@ -9274,8 +9285,11 @@ static int niu_get_invariants(struct niu *np)
offset = niu_pci_vpd_offset(np); offset = niu_pci_vpd_offset(np);
netif_printk(np, probe, KERN_DEBUG, np->dev, netif_printk(np, probe, KERN_DEBUG, np->dev,
"%s() VPD offset [%08x]\n", __func__, offset); "%s() VPD offset [%08x]\n", __func__, offset);
if (offset) if (offset) {
niu_pci_vpd_fetch(np, offset); err = niu_pci_vpd_fetch(np, offset);
if (err < 0)
return err;
}
nw64(ESPC_PIO_EN, 0); nw64(ESPC_PIO_EN, 0);
if (np->flags & NIU_FLAGS_VPD_VALID) { if (np->flags & NIU_FLAGS_VPD_VALID) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment