tahvo-usb: Fix NULL ptr deref in OTR irq handler
[openwrt/staging/dedeckeh.git] / target / linux / omap24xx / patches-2.6.38 / 590-cbus-tahvo-usb-fixes.patch
1 Index: linux-2.6.38-rc7/drivers/cbus/tahvo-usb.c
2 ===================================================================
3 --- linux-2.6.38-rc7.orig/drivers/cbus/tahvo-usb.c 2011-03-06 23:00:14.411191087 +0100
4 +++ linux-2.6.38-rc7/drivers/cbus/tahvo-usb.c 2011-03-06 23:43:26.524751556 +0100
5 @@ -98,8 +98,9 @@ struct tahvo_usb {
6 #ifdef CONFIG_USB_OTG
7 int tahvo_mode;
8 #endif
9 + struct clk *ick;
10 };
11 -static struct platform_device tahvo_usb_device;
12 +static struct tahvo_usb *tahvo_usb_device;
13
14 /*
15 * ---------------------------------------------------------------------------
16 @@ -114,8 +115,7 @@ static struct platform_device *tahvo_otg
17
18 static irqreturn_t omap_otg_irq(int irq, void *arg)
19 {
20 - struct platform_device *otg_dev = arg;
21 - struct tahvo_usb *tu = platform_get_drvdata(otg_dev);
22 + struct tahvo_usb *tu = arg;
23 u16 otg_irq;
24
25 otg_irq = omap_readw(OTG_IRQ_SRC);
26 @@ -201,12 +201,12 @@ static int __init omap_otg_probe(struct
27
28 return request_irq(tahvo_otg_dev->resource[1].start,
29 omap_otg_irq, IRQF_DISABLED, DRIVER_NAME,
30 - &tahvo_usb_device);
31 + tahvo_usb_device);
32 }
33
34 static int __exit omap_otg_remove(struct platform_device *pdev)
35 {
36 - free_irq(tahvo_otg_dev->resource[1].start, &tahvo_usb_device);
37 + free_irq(tahvo_otg_dev->resource[1].start, tahvo_usb_device);
38 tahvo_otg_dev = NULL;
39
40 return 0;
41 @@ -659,6 +659,7 @@ static int __init tahvo_usb_probe(struct
42 tu = kzalloc(sizeof(*tu), GFP_KERNEL);
43 if (!tu)
44 return -ENOMEM;
45 + tahvo_usb_device = tu;
46
47 tu->pt_dev = container_of(dev, struct platform_device, dev);
48 #ifdef CONFIG_USB_OTG
49 @@ -673,6 +674,14 @@ static int __init tahvo_usb_probe(struct
50 INIT_WORK(&tu->irq_work, tahvo_usb_irq_work);
51 mutex_init(&tu->serialize);
52
53 + tu->ick = clk_get(NULL, "usb_l4_ick");
54 + if (IS_ERR(tu->ick)) {
55 + printk(KERN_ERR "Failed to get usb_l4_ick\n");
56 + ret = PTR_ERR(tu->ick);
57 + goto err_free_tu;
58 + }
59 + clk_enable(tu->ick);
60 +
61 /* Set initial state, so that we generate kevents only on
62 * state changes */
63 tu->vbus_state = tahvo_read_reg(TAHVO_REG_IDSR) & 0x01;
64 @@ -680,10 +689,9 @@ static int __init tahvo_usb_probe(struct
65 /* We cannot enable interrupt until omap_udc is initialized */
66 ret = tahvo_request_irq(TAHVO_INT_VBUSON, tahvo_usb_vbus_interrupt,
67 (unsigned long) tu, "vbus_interrupt");
68 - if (ret != 0) {
69 - kfree(tu);
70 + if (ret) {
71 printk(KERN_ERR "Could not register Tahvo interrupt for VBUS\n");
72 - return ret;
73 + goto err_release_clk;
74 }
75
76 /* Attributes */
77 @@ -708,9 +716,7 @@ static int __init tahvo_usb_probe(struct
78 ret = otg_set_transceiver(&tu->otg);
79 if (ret < 0) {
80 printk(KERN_ERR "Cannot register USB transceiver\n");
81 - kfree(tu);
82 - tahvo_free_irq(TAHVO_INT_VBUSON);
83 - return ret;
84 + goto err_free_irq;
85 }
86
87 dev_set_drvdata(dev, tu);
88 @@ -719,10 +725,23 @@ static int __init tahvo_usb_probe(struct
89 * may not be generated in addition to this. */
90 schedule_work(&tu->irq_work);
91 return 0;
92 +
93 +err_free_irq:
94 + tahvo_free_irq(TAHVO_INT_VBUSON);
95 +err_release_clk:
96 + clk_disable(tu->ick);
97 + clk_put(tu->ick);
98 +err_free_tu:
99 + kfree(tu);
100 + tahvo_usb_device = NULL;
101 +
102 + return ret;
103 }
104
105 static int __exit tahvo_usb_remove(struct platform_device *pdev)
106 {
107 + struct tahvo_usb *tu = platform_get_drvdata(pdev);
108 +
109 dev_dbg(&pdev->dev, "remove\n");
110
111 tahvo_free_irq(TAHVO_INT_VBUSON);
112 @@ -732,6 +751,12 @@ static int __exit tahvo_usb_remove(struc
113 #ifdef CONFIG_USB_OTG
114 device_remove_file(&pdev->dev, &dev_attr_otg_mode);
115 #endif
116 + clk_disable(tu->ick);
117 + clk_put(tu->ick);
118 +
119 + kfree(tu);
120 + tahvo_usb_device = NULL;
121 +
122 return 0;
123 }
124
125 Index: linux-2.6.38-rc7/arch/arm/mach-omap2/board-n8x0.c
126 ===================================================================
127 --- linux-2.6.38-rc7.orig/arch/arm/mach-omap2/board-n8x0.c 2011-03-06 23:00:14.388188076 +0100
128 +++ linux-2.6.38-rc7/arch/arm/mach-omap2/board-n8x0.c 2011-03-06 23:06:50.508033149 +0100
129 @@ -40,6 +40,7 @@
130 #include <plat/serial.h>
131 #include <plat/cbus.h>
132 #include <plat/gpio-switch.h>
133 +#include <plat/usb.h>
134
135 #include "mux.h"
136
137 @@ -395,6 +396,14 @@ static struct musb_hdrc_platform_data tu
138 .config = &musb_config,
139 };
140
141 +static struct omap_usb_config n8x0_omap_usb_config __initdata = {
142 + .otg = 1,
143 + .register_host = 1,
144 + .register_dev = 1,
145 + .hmc_mode = 16,
146 + .pins[0] = 6,
147 +};
148 +
149 static void __init n8x0_usb_init(void)
150 {
151 int ret = 0;
152 @@ -417,6 +426,8 @@ static void __init n8x0_usb_init(void)
153 if (ret != 0)
154 goto err;
155
156 + omap2_usbfs_init(&n8x0_omap_usb_config);
157 +
158 printk(announce);
159
160 return;