aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wimax/i2400m/usb-tx.c
diff options
context:
space:
mode:
authorInaky Perez-Gonzalez <inaky@linux.intel.com>2009-10-07 19:11:38 -0400
committerInaky Perez-Gonzalez <inaky@linux.intel.com>2009-10-19 02:56:22 -0400
commit4a78fd9a736db4c871bc8b583d66b61c38abd299 (patch)
tree2f8e5c53eb81091c321436b70280b9627e673815 /drivers/net/wimax/i2400m/usb-tx.c
parent0c96859d7a5f0286ed70d3c4e140ac6816a350da (diff)
wimax/i2400m: fix oops caused by race condition when exiting USB kthreads
Current i2400m USB code had to threads (one for processing RX, one for TX). When calling i2400m_{tx,rx}_release(), it would crash if the thread had exited already due to an error. So changed the code to have the thread fill in/out i2400mu->{tx,rx}_kthread under a spinlock; then the _release() function will call kthread_stop() only if {rx,tx}_kthread is still set. Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
Diffstat (limited to 'drivers/net/wimax/i2400m/usb-tx.c')
-rw-r--r--drivers/net/wimax/i2400m/usb-tx.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/drivers/net/wimax/i2400m/usb-tx.c b/drivers/net/wimax/i2400m/usb-tx.c
index 90dfff1afb8a..a3c46e99c804 100644
--- a/drivers/net/wimax/i2400m/usb-tx.c
+++ b/drivers/net/wimax/i2400m/usb-tx.c
@@ -161,9 +161,15 @@ int i2400mu_txd(void *_i2400mu)
161 struct device *dev = &i2400mu->usb_iface->dev; 161 struct device *dev = &i2400mu->usb_iface->dev;
162 struct i2400m_msg_hdr *tx_msg; 162 struct i2400m_msg_hdr *tx_msg;
163 size_t tx_msg_size; 163 size_t tx_msg_size;
164 unsigned long flags;
164 165
165 d_fnstart(4, dev, "(i2400mu %p)\n", i2400mu); 166 d_fnstart(4, dev, "(i2400mu %p)\n", i2400mu);
166 167
168 spin_lock_irqsave(&i2400m->tx_lock, flags);
169 BUG_ON(i2400mu->tx_kthread != NULL);
170 i2400mu->tx_kthread = current;
171 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
172
167 while (1) { 173 while (1) {
168 d_printf(2, dev, "TX: waiting for messages\n"); 174 d_printf(2, dev, "TX: waiting for messages\n");
169 tx_msg = NULL; 175 tx_msg = NULL;
@@ -183,6 +189,11 @@ int i2400mu_txd(void *_i2400mu)
183 if (result < 0) 189 if (result < 0)
184 break; 190 break;
185 } 191 }
192
193 spin_lock_irqsave(&i2400m->tx_lock, flags);
194 i2400mu->tx_kthread = NULL;
195 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
196
186 d_fnend(4, dev, "(i2400mu %p) = %d\n", i2400mu, result); 197 d_fnend(4, dev, "(i2400mu %p) = %d\n", i2400mu, result);
187 return result; 198 return result;
188} 199}
@@ -213,11 +224,13 @@ int i2400mu_tx_setup(struct i2400mu *i2400mu)
213 struct i2400m *i2400m = &i2400mu->i2400m; 224 struct i2400m *i2400m = &i2400mu->i2400m;
214 struct device *dev = &i2400mu->usb_iface->dev; 225 struct device *dev = &i2400mu->usb_iface->dev;
215 struct wimax_dev *wimax_dev = &i2400m->wimax_dev; 226 struct wimax_dev *wimax_dev = &i2400m->wimax_dev;
227 struct task_struct *kthread;
216 228
217 i2400mu->tx_kthread = kthread_run(i2400mu_txd, i2400mu, "%s-tx", 229 kthread = kthread_run(i2400mu_txd, i2400mu, "%s-tx",
218 wimax_dev->name); 230 wimax_dev->name);
219 if (IS_ERR(i2400mu->tx_kthread)) { 231 /* the kthread function sets i2400mu->tx_thread */
220 result = PTR_ERR(i2400mu->tx_kthread); 232 if (IS_ERR(kthread)) {
233 result = PTR_ERR(kthread);
221 dev_err(dev, "TX: cannot start thread: %d\n", result); 234 dev_err(dev, "TX: cannot start thread: %d\n", result);
222 } 235 }
223 return result; 236 return result;
@@ -225,5 +238,17 @@ int i2400mu_tx_setup(struct i2400mu *i2400mu)
225 238
226void i2400mu_tx_release(struct i2400mu *i2400mu) 239void i2400mu_tx_release(struct i2400mu *i2400mu)
227{ 240{
228 kthread_stop(i2400mu->tx_kthread); 241 unsigned long flags;
242 struct i2400m *i2400m = &i2400mu->i2400m;
243 struct device *dev = i2400m_dev(i2400m);
244 struct task_struct *kthread;
245
246 spin_lock_irqsave(&i2400m->tx_lock, flags);
247 kthread = i2400mu->tx_kthread;
248 i2400mu->tx_kthread = NULL;
249 spin_unlock_irqrestore(&i2400m->tx_lock, flags);
250 if (kthread)
251 kthread_stop(kthread);
252 else
253 d_printf(1, dev, "TX: kthread had already exited\n");
229} 254}