Skip to content

Commit

Permalink
atl1c: Fix work event interrupt/task races
Browse files Browse the repository at this point in the history
The mechanism used to initiate work events from the interrupt
handler has a classic read/modify/write race between the interrupt
handler that sets the condition, and the worker task that reads and
clears the condition. Close these races by using atomic
bit fields.

Cc: stable@kernel.org
Cc: Jie Yang <jie.yang@atheros.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
rtg-tpi authored and davem330 committed Apr 22, 2011
1 parent e74fbd0 commit cb77183
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
6 changes: 3 additions & 3 deletions drivers/net/atl1c/atl1c.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ struct atl1c_adapter {
#define __AT_TESTING 0x0001
#define __AT_RESETTING 0x0002
#define __AT_DOWN 0x0003
u8 work_event;
#define ATL1C_WORK_EVENT_RESET 0x01
#define ATL1C_WORK_EVENT_LINK_CHANGE 0x02
unsigned long work_event;
#define ATL1C_WORK_EVENT_RESET 0
#define ATL1C_WORK_EVENT_LINK_CHANGE 1
u32 msg_enable;

bool have_msi;
Expand Down
14 changes: 5 additions & 9 deletions drivers/net/atl1c/atl1c_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static void atl1c_link_chg_event(struct atl1c_adapter *adapter)
}
}

adapter->work_event |= ATL1C_WORK_EVENT_LINK_CHANGE;
set_bit(ATL1C_WORK_EVENT_LINK_CHANGE, &adapter->work_event);
schedule_work(&adapter->common_task);
}

Expand All @@ -337,20 +337,16 @@ static void atl1c_common_task(struct work_struct *work)
adapter = container_of(work, struct atl1c_adapter, common_task);
netdev = adapter->netdev;

if (adapter->work_event & ATL1C_WORK_EVENT_RESET) {
adapter->work_event &= ~ATL1C_WORK_EVENT_RESET;
if (test_and_clear_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event)) {
netif_device_detach(netdev);
atl1c_down(adapter);
atl1c_up(adapter);
netif_device_attach(netdev);
return;
}

if (adapter->work_event & ATL1C_WORK_EVENT_LINK_CHANGE) {
adapter->work_event &= ~ATL1C_WORK_EVENT_LINK_CHANGE;
if (test_and_clear_bit(ATL1C_WORK_EVENT_LINK_CHANGE,
&adapter->work_event))
atl1c_check_link_status(adapter);
}
return;
}


Expand All @@ -369,7 +365,7 @@ static void atl1c_tx_timeout(struct net_device *netdev)
struct atl1c_adapter *adapter = netdev_priv(netdev);

/* Do the reset outside of interrupt context */
adapter->work_event |= ATL1C_WORK_EVENT_RESET;
set_bit(ATL1C_WORK_EVENT_RESET, &adapter->work_event);
schedule_work(&adapter->common_task);
}

Expand Down

0 comments on commit cb77183

Please sign in to comment.