Skip to content

Commit 94c7f2d

Browse files
author
Inaky Perez-Gonzalez
committed
wimax: oops: wimax_dev_add() is the only one that can initialize the state
When a new wimax_dev is created, it's state has to be __WIMAX_ST_NULL until wimax_dev_add() is succesfully called. This allows calls into the stack that happen before said time to be rejected. Until now, the state was being set (by mistake) to UNINITIALIZED, which was allowing calls such as wimax_report_rfkill_hw() to go through even when a call to wimax_dev_add() had failed; that was causing an oops when touching uninitialized data. This situation is normal when the device starts reporting state before the whole initialization has been completed. It just has to be dealt with. Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
1 parent d1a2627 commit 94c7f2d

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎net/wimax/stack.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,21 @@ void __wimax_state_change(struct wimax_dev *wimax_dev, enum wimax_st new_state)
338338
*/
339339
void wimax_state_change(struct wimax_dev *wimax_dev, enum wimax_st new_state)
340340
{
341+
/*
342+
* A driver cannot take the wimax_dev out of the
343+
* __WIMAX_ST_NULL state unless by calling wimax_dev_add(). If
344+
* the wimax_dev's state is still NULL, we ignore any request
345+
* to change its state because it means it hasn't been yet
346+
* registered.
347+
*
348+
* There is no need to complain about it, as routines that
349+
* call this might be shared from different code paths that
350+
* are called before or after wimax_dev_add() has done its
351+
* job.
352+
*/
341353
mutex_lock(&wimax_dev->mutex);
342-
__wimax_state_change(wimax_dev, new_state);
354+
if (wimax_dev->state > __WIMAX_ST_NULL)
355+
__wimax_state_change(wimax_dev, new_state);
343356
mutex_unlock(&wimax_dev->mutex);
344357
return;
345358
}
@@ -376,7 +389,7 @@ EXPORT_SYMBOL_GPL(wimax_state_get);
376389
void wimax_dev_init(struct wimax_dev *wimax_dev)
377390
{
378391
INIT_LIST_HEAD(&wimax_dev->id_table_node);
379-
__wimax_state_set(wimax_dev, WIMAX_ST_UNINITIALIZED);
392+
__wimax_state_set(wimax_dev, __WIMAX_ST_NULL);
380393
mutex_init(&wimax_dev->mutex);
381394
mutex_init(&wimax_dev->mutex_reset);
382395
}

0 commit comments

Comments
 (0)