Skip to content

Commit 9afec6e

Browse files
andy-shevdavem330
authored andcommitted
stmmac: prevent probe drivers to crash kernel
In the case when alloc_netdev fails we return NULL to a caller. But there is no check for NULL in the probe drivers. This patch changes NULL to an error pointer. The function description is amended to reflect what we may get returned. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 24e579c commit 9afec6e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,9 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
27782778
* @addr: iobase memory address
27792779
* Description: this is the main probe function used to
27802780
* call the alloc_etherdev, allocate the priv structure.
2781+
* Return:
2782+
* on success the new private structure is returned, otherwise the error
2783+
* pointer.
27812784
*/
27822785
struct stmmac_priv *stmmac_dvr_probe(struct device *device,
27832786
struct plat_stmmacenet_data *plat_dat,
@@ -2789,7 +2792,7 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
27892792

27902793
ndev = alloc_etherdev(sizeof(struct stmmac_priv));
27912794
if (!ndev)
2792-
return NULL;
2795+
return ERR_PTR(-ENOMEM);
27932796

27942797
SET_NETDEV_DEV(ndev, device);
27952798

0 commit comments

Comments
 (0)