Commit abcd3d6f authored by Moritz Fischer's avatar Moritz Fischer Committed by David S. Miller

net: nixge: Fix error path for obtaining mac address

Fix issue where nixge_get_nvmem_address() returns a non-NULL
return value on a failed nvmem_cell_get() that causes an invalid
access when error value encoded in pointer is dereferenced.

Furthermore ensure that buffer allocated by nvmem_cell_read()
actually gets kfreed() if the function succeeds.

Fixes commit 492caffa ("net: ethernet: nixge: Add support for
National Instruments XGE netdev")
Reported-by: default avatarAlex Williams <alex.williams@ni.com>
Signed-off-by: default avatarMoritz Fischer <mdf@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1751eb42
......@@ -1170,7 +1170,7 @@ static void *nixge_get_nvmem_address(struct device *dev)
cell = nvmem_cell_get(dev, "address");
if (IS_ERR(cell))
return cell;
return NULL;
mac = nvmem_cell_read(cell, &cell_size);
nvmem_cell_put(cell);
......@@ -1202,10 +1202,12 @@ static int nixge_probe(struct platform_device *pdev)
ndev->max_mtu = NIXGE_JUMBO_MTU;
mac_addr = nixge_get_nvmem_address(&pdev->dev);
if (mac_addr && is_valid_ether_addr(mac_addr))
if (mac_addr && is_valid_ether_addr(mac_addr)) {
ether_addr_copy(ndev->dev_addr, mac_addr);
else
kfree(mac_addr);
} else {
eth_hw_addr_random(ndev);
}
priv = netdev_priv(ndev);
priv->ndev = ndev;
......
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