Skip to content

Commit 1c40cde

Browse files
Wang Haidavem330
authored andcommitted
arcnet: fix potential memory leak in com20020_probe()
In com20020_probe(), if com20020_config() fails, dev and info will not be freed, which will lead to a memory leak. This patch adds freeing dev and info after com20020_config() fails to fix this bug. Compile tested only. Fixes: 15b99ac ("[PATCH] pcmcia: add return value to _config() functions") Signed-off-by: Wang Hai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 178a4ff commit 1c40cde

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/net/arcnet/com20020_cs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static int com20020_probe(struct pcmcia_device *p_dev)
113113
struct com20020_dev *info;
114114
struct net_device *dev;
115115
struct arcnet_local *lp;
116+
int ret = -ENOMEM;
116117

117118
dev_dbg(&p_dev->dev, "com20020_attach()\n");
118119

@@ -142,12 +143,18 @@ static int com20020_probe(struct pcmcia_device *p_dev)
142143
info->dev = dev;
143144
p_dev->priv = info;
144145

145-
return com20020_config(p_dev);
146+
ret = com20020_config(p_dev);
147+
if (ret)
148+
goto fail_config;
149+
150+
return 0;
146151

152+
fail_config:
153+
free_arcdev(dev);
147154
fail_alloc_dev:
148155
kfree(info);
149156
fail_alloc_info:
150-
return -ENOMEM;
157+
return ret;
151158
} /* com20020_attach */
152159

153160
static void com20020_detach(struct pcmcia_device *link)

0 commit comments

Comments
 (0)