netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: dsa: loop: Check for memory allocation failure
@ 2017-05-06  5:29 Christophe JAILLET
  2017-05-06 14:45 ` Andrew Lunn
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Christophe JAILLET @ 2017-05-06  5:29 UTC (permalink / raw)
  To: andrew, vivien.didelot, f.fainelli
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

If 'devm_kzalloc' fails, a NULL pointer will be dereferenced.
Return -ENOMEM instead, as done for some other memory allocation just a
few lines above.

Fixes: 98cd1552ea27 ("net: dsa: Mock-up driver")

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/dsa/dsa_loop.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index f0fc4de4fc9a..a19e1781e9bb 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -256,6 +256,9 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev)
 		return -ENOMEM;
 
 	ps = devm_kzalloc(&mdiodev->dev, sizeof(*ps), GFP_KERNEL);
+	if (!ps)
+		return -ENOMEM;
+
 	ps->netdev = dev_get_by_name(&init_net, pdata->netdev);
 	if (!ps->netdev)
 		return -EPROBE_DEFER;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-05-09 15:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-06  5:29 [PATCH] net: dsa: loop: Check for memory allocation failure Christophe JAILLET
2017-05-06 14:45 ` Andrew Lunn
2017-05-07 23:22 ` Florian Fainelli
2017-05-08 12:05 ` David Laight
2017-05-08 12:32   ` Julia Lawall
2017-05-08 17:44     ` Joe Perches
2017-05-08 23:46       ` Julia Lawall
2017-05-09  0:35         ` Florian Fainelli
2017-05-09  0:39           ` Julia Lawall
2017-05-09 15:18           ` Joe Perches
2017-05-08 19:01 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).