Bug 10591

Summary: [drivers/net/fs_enet/mii-fec.c]: Memory leaks for new_bus and fec
Product: Drivers Reporter: Daniel Marjamäki (danielm77)
Component: NetworkAssignee: Jeff Garzik (jgarzik)
Status: RESOLVED CODE_FIX    
Severity: normal    
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.25.1 Subsystem:
Regression: --- Bisected commit-id:

Description Daniel Marjamäki 2008-05-02 09:30:16 UTC
I think there are some possible memory leaks.

[drivers/net/fs_enet/mii-fec.c:197]: new_bus and fec
[drivers/net/fs_enet/mii-fec.c:306]: new_bus
[drivers/net/fs_enet/mii-fec.c:318]: new_bus and fec


This is the code on lines 181-197 where both new_bus and fec are leaked:

	new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);
	if (!new_bus)
		goto out;

	fec = kzalloc(sizeof(struct fec_info), GFP_KERNEL);
	if (!fec)
		goto out_mii;

	new_bus->priv = fec;
	new_bus->name = "FEC MII Bus";
	new_bus->read = &fs_enet_fec_mii_read;
	new_bus->write = &fs_enet_fec_mii_write;
	new_bus->reset = &fs_enet_fec_mii_reset;

	ret = of_address_to_resource(ofdev->node, 0, &res);
	if (ret)
		return ret;



This is the code on lines 298-319 where both new_bus and fec are leaked:

	new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL);

	if (NULL == new_bus)
		return -ENOMEM;

	fec = kzalloc(sizeof(struct fec_info), GFP_KERNEL);

	if (NULL == fec)
		return -ENOMEM;

	new_bus->name = "FEC MII Bus",
	new_bus->read = &fs_enet_fec_mii_read,
	new_bus->write = &fs_enet_fec_mii_write,
	new_bus->reset = &fs_enet_fec_mii_reset,
	new_bus->id = pdev->id;

	pdata = (struct fs_mii_fec_platform_info *)pdev->dev.platform_data;

	if (NULL == pdata) {
		printk(KERN_ERR "fs_enet FEC mdio %d: Missing platform data!\n", pdev->id);
		return -ENODEV;
	}