Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Wang Hai and committed by
David S. Miller
1c40cde6 178a4ff1

+9 -2
+9 -2
drivers/net/arcnet/com20020_cs.c
··· 113 113 struct com20020_dev *info; 114 114 struct net_device *dev; 115 115 struct arcnet_local *lp; 116 + int ret = -ENOMEM; 116 117 117 118 dev_dbg(&p_dev->dev, "com20020_attach()\n"); 118 119 ··· 143 142 info->dev = dev; 144 143 p_dev->priv = info; 145 144 146 - return com20020_config(p_dev); 145 + ret = com20020_config(p_dev); 146 + if (ret) 147 + goto fail_config; 147 148 149 + return 0; 150 + 151 + fail_config: 152 + free_arcdev(dev); 148 153 fail_alloc_dev: 149 154 kfree(info); 150 155 fail_alloc_info: 151 - return -ENOMEM; 156 + return ret; 152 157 } /* com20020_attach */ 153 158 154 159 static void com20020_detach(struct pcmcia_device *link)