Skip to content

Commit

Permalink
net: stmmac: add sanity check to device_property_read_u32_array call
Browse files Browse the repository at this point in the history
Currently the call to device_property_read_u32_array is not error checked
leading to potential garbage values in the delays array that are then used
in msleep delays.  Add a sanity check to the property fetching.

Addresses-Coverity: ("Uninitialized scalar variable")
Signed-off-by: Colin Ian King <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Colin Ian King authored and davem330 committed Jun 19, 2019
1 parent cf29a49 commit 760f1dc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,23 @@ int stmmac_mdio_reset(struct mii_bus *bus)
if (priv->device->of_node) {
struct gpio_desc *reset_gpio;
u32 delays[3];
int ret;

reset_gpio = devm_gpiod_get_optional(priv->device,
"snps,reset",
GPIOD_OUT_LOW);
if (IS_ERR(reset_gpio))
return PTR_ERR(reset_gpio);

device_property_read_u32_array(priv->device,
"snps,reset-delays-us",
delays, ARRAY_SIZE(delays));
ret = device_property_read_u32_array(priv->device,
"snps,reset-delays-us",
delays,
ARRAY_SIZE(delays));
if (ret) {
dev_err(ndev->dev.parent,
"invalid property snps,reset-delays-us\n");
return -EINVAL;
}

if (delays[0])
msleep(DIV_ROUND_UP(delays[0], 1000));
Expand Down

0 comments on commit 760f1dc

Please sign in to comment.