summaryrefslogtreecommitdiffstats
path: root/target/linux/ar7/patches-2.6.23/210-phy_fixed.patch
blob: 24040786c009c356dc92050c6ce3eed1b99be342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Index: linux-2.6.23.17/drivers/net/phy/fixed.c
===================================================================
--- linux-2.6.23.17.orig/drivers/net/phy/fixed.c
+++ linux-2.6.23.17/drivers/net/phy/fixed.c
@@ -189,6 +189,19 @@ static struct phy_driver fixed_mdio_driv
 	.driver 	= { .owner = THIS_MODULE,},
 };
 
+static void fixed_mdio_release (struct device * dev)
+{
+	struct phy_device *phydev = container_of(dev, struct phy_device, dev);
+	struct mii_bus *bus = phydev->bus;
+	struct fixed_info *fixed = bus->priv;
+
+	kfree(phydev);
+	kfree(bus->dev);
+	kfree(bus);
+	kfree(fixed->regs);
+	kfree(fixed);
+}
+
 /*-----------------------------------------------------------------------------
  *  This func is used to create all the necessary stuff, bind
  * the fixed phy driver and register all it on the mdio_bus_type.
@@ -224,6 +237,12 @@ static int fixed_mdio_register_device(in
 	}
 
 	fixed->regs = kzalloc(MII_REGS_NUM*sizeof(int), GFP_KERNEL);
+	if (NULL == fixed->regs) {
+		kfree(dev);
+		kfree(new_bus);
+		kfree(fixed);
+		return -ENOMEM;
+	}
 	fixed->regs_num = MII_REGS_NUM;
 	fixed->phy_status.speed = speed;
 	fixed->phy_status.duplex = duplex;
@@ -252,8 +271,11 @@ static int fixed_mdio_register_device(in
 	fixed->phydev = phydev;
 
 	if(NULL == phydev) {
-		err = -ENOMEM;
-		goto device_create_fail;
+		kfree(dev);
+		kfree(new_bus);
+		kfree(fixed->regs);
+		kfree(fixed);
+		return -ENOMEM;
 	}
 
 	phydev->irq = PHY_IGNORE_INTERRUPT;
@@ -265,8 +287,33 @@ static int fixed_mdio_register_device(in
 	else
 		snprintf(phydev->dev.bus_id, BUS_ID_SIZE,
 				"fixed@%d:%d", speed, duplex);
+
 	phydev->bus = new_bus;
 
+#if 1
+	phydev->dev.driver = &fixed_mdio_driver.driver;
+	phydev->dev.release = fixed_mdio_release;
+
+	err = phydev->dev.driver->probe(&phydev->dev);
+	if(err < 0) {
+		printk(KERN_ERR "Phy %s: problems with fixed driver\n",
+			phydev->dev.bus_id);
+		kfree(phydev);
+		kfree(dev);
+		kfree(new_bus);
+		kfree(fixed->regs);
+		kfree(fixed);
+		return err;
+	}
+
+	err = device_register(&phydev->dev);
+	if(err) {
+		printk(KERN_ERR "Phy %s failed to register\n",
+				phydev->dev.bus_id);
+	}
+
+	return 0;
+#else
 	err = device_register(&phydev->dev);
 	if(err) {
 		printk(KERN_ERR "Phy %s failed to register\n",
@@ -303,6 +350,7 @@ device_create_fail:
 	kfree(fixed);
 
 	return err;
+#endif
 }
 #endif