Commit bf6aede7 authored by Jean Delvare's avatar Jean Delvare Committed by Linus Torvalds

workqueue: add to_delayed_work() helper function

It is a fairly common operation to have a pointer to a work and to need a
pointer to the delayed work it is contained in.  In particular, all
delayed works which want to rearm themselves will have to do that.  So it
would seem fair to offer a helper function for this operation.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Greg KH <greg@kroah.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e4c2ff1c
...@@ -482,7 +482,7 @@ static void vio_cmo_balance(struct work_struct *work) ...@@ -482,7 +482,7 @@ static void vio_cmo_balance(struct work_struct *work)
cmo->excess.size = cmo->entitled - cmo->reserve.size; cmo->excess.size = cmo->entitled - cmo->reserve.size;
cmo->excess.free = cmo->excess.size - need; cmo->excess.free = cmo->excess.size - need;
cancel_delayed_work(container_of(work, struct delayed_work, work)); cancel_delayed_work(to_delayed_work(work));
spin_unlock_irqrestore(&vio_cmo.lock, flags); spin_unlock_irqrestore(&vio_cmo.lock, flags);
} }
......
...@@ -1882,7 +1882,7 @@ static void hifn_clear_rings(struct hifn_device *dev, int error) ...@@ -1882,7 +1882,7 @@ static void hifn_clear_rings(struct hifn_device *dev, int error)
static void hifn_work(struct work_struct *work) static void hifn_work(struct work_struct *work)
{ {
struct delayed_work *dw = container_of(work, struct delayed_work, work); struct delayed_work *dw = to_delayed_work(work);
struct hifn_device *dev = container_of(dw, struct hifn_device, work); struct hifn_device *dev = container_of(dw, struct hifn_device, work);
unsigned long flags; unsigned long flags;
int reset = 0; int reset = 0;
......
...@@ -381,7 +381,7 @@ static void hgpk_disconnect(struct psmouse *psmouse) ...@@ -381,7 +381,7 @@ static void hgpk_disconnect(struct psmouse *psmouse)
static void hgpk_recalib_work(struct work_struct *work) static void hgpk_recalib_work(struct work_struct *work)
{ {
struct delayed_work *w = container_of(work, struct delayed_work, work); struct delayed_work *w = to_delayed_work(work);
struct hgpk_data *priv = container_of(w, struct hgpk_data, recalib_wq); struct hgpk_data *priv = container_of(w, struct hgpk_data, recalib_wq);
struct psmouse *psmouse = priv->psmouse; struct psmouse *psmouse = priv->psmouse;
......
...@@ -559,7 +559,7 @@ static void dm9000_show_carrier(board_info_t *db, ...@@ -559,7 +559,7 @@ static void dm9000_show_carrier(board_info_t *db,
static void static void
dm9000_poll_work(struct work_struct *w) dm9000_poll_work(struct work_struct *w)
{ {
struct delayed_work *dw = container_of(w, struct delayed_work, work); struct delayed_work *dw = to_delayed_work(w);
board_info_t *db = container_of(dw, board_info_t, phy_poll); board_info_t *db = container_of(dw, board_info_t, phy_poll);
struct net_device *ndev = db->ndev; struct net_device *ndev = db->ndev;
......
...@@ -505,7 +505,7 @@ static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv) ...@@ -505,7 +505,7 @@ static void mlx4_en_auto_moderation(struct mlx4_en_priv *priv)
static void mlx4_en_do_get_stats(struct work_struct *work) static void mlx4_en_do_get_stats(struct work_struct *work)
{ {
struct delayed_work *delay = container_of(work, struct delayed_work, work); struct delayed_work *delay = to_delayed_work(work);
struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
stats_task); stats_task);
struct mlx4_en_dev *mdev = priv->mdev; struct mlx4_en_dev *mdev = priv->mdev;
......
...@@ -298,7 +298,7 @@ static void mlx4_en_free_rx_buf(struct mlx4_en_priv *priv, ...@@ -298,7 +298,7 @@ static void mlx4_en_free_rx_buf(struct mlx4_en_priv *priv,
void mlx4_en_rx_refill(struct work_struct *work) void mlx4_en_rx_refill(struct work_struct *work)
{ {
struct delayed_work *delay = container_of(work, struct delayed_work, work); struct delayed_work *delay = to_delayed_work(work);
struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv, struct mlx4_en_priv *priv = container_of(delay, struct mlx4_en_priv,
refill_task); refill_task);
struct mlx4_en_dev *mdev = priv->mdev; struct mlx4_en_dev *mdev = priv->mdev;
......
...@@ -103,7 +103,7 @@ void mlx4_do_sense_ports(struct mlx4_dev *dev, ...@@ -103,7 +103,7 @@ void mlx4_do_sense_ports(struct mlx4_dev *dev,
static void mlx4_sense_port(struct work_struct *work) static void mlx4_sense_port(struct work_struct *work)
{ {
struct delayed_work *delay = container_of(work, struct delayed_work, work); struct delayed_work *delay = to_delayed_work(work);
struct mlx4_sense *sense = container_of(delay, struct mlx4_sense, struct mlx4_sense *sense = container_of(delay, struct mlx4_sense,
sense_poll); sense_poll);
struct mlx4_dev *dev = sense->dev; struct mlx4_dev *dev = sense->dev;
......
...@@ -757,8 +757,7 @@ EXPORT_SYMBOL(phy_start); ...@@ -757,8 +757,7 @@ EXPORT_SYMBOL(phy_start);
*/ */
static void phy_state_machine(struct work_struct *work) static void phy_state_machine(struct work_struct *work)
{ {
struct delayed_work *dwork = struct delayed_work *dwork = to_delayed_work(work);
container_of(work, struct delayed_work, work);
struct phy_device *phydev = struct phy_device *phydev =
container_of(dwork, struct phy_device, state_queue); container_of(dwork, struct phy_device, state_queue);
int needs_aneg = 0; int needs_aneg = 0;
......
...@@ -94,7 +94,7 @@ static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port) ...@@ -94,7 +94,7 @@ static int zfcp_wka_port_get(struct zfcp_wka_port *wka_port)
static void zfcp_wka_port_offline(struct work_struct *work) static void zfcp_wka_port_offline(struct work_struct *work)
{ {
struct delayed_work *dw = container_of(work, struct delayed_work, work); struct delayed_work *dw = to_delayed_work(work);
struct zfcp_wka_port *wka_port = struct zfcp_wka_port *wka_port =
container_of(dw, struct zfcp_wka_port, work); container_of(dw, struct zfcp_wka_port, work);
......
...@@ -719,7 +719,7 @@ void ieee80211_softmac_scan(struct ieee80211_device *ieee) ...@@ -719,7 +719,7 @@ void ieee80211_softmac_scan(struct ieee80211_device *ieee)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
void ieee80211_softmac_scan_wq(struct work_struct *work) void ieee80211_softmac_scan_wq(struct work_struct *work)
{ {
struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
#else #else
void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee) void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee)
...@@ -777,7 +777,7 @@ void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee) ...@@ -777,7 +777,7 @@ void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
void ieee80211_softmac_scan_wq(struct work_struct *work) void ieee80211_softmac_scan_wq(struct work_struct *work)
{ {
struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq); struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq);
#else #else
void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee) void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee)
...@@ -2980,7 +2980,7 @@ void ieee80211_start_monitor_mode(struct ieee80211_device *ieee) ...@@ -2980,7 +2980,7 @@ void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
void ieee80211_start_ibss_wq(struct work_struct *work) void ieee80211_start_ibss_wq(struct work_struct *work)
{ {
struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq); struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
#else #else
void ieee80211_start_ibss_wq(struct ieee80211_device *ieee) void ieee80211_start_ibss_wq(struct ieee80211_device *ieee)
...@@ -3162,7 +3162,7 @@ void ieee80211_disassociate(struct ieee80211_device *ieee) ...@@ -3162,7 +3162,7 @@ void ieee80211_disassociate(struct ieee80211_device *ieee)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
void ieee80211_associate_retry_wq(struct work_struct *work) void ieee80211_associate_retry_wq(struct work_struct *work)
{ {
struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
#else #else
void ieee80211_associate_retry_wq(struct ieee80211_device *ieee) void ieee80211_associate_retry_wq(struct ieee80211_device *ieee)
......
...@@ -5438,7 +5438,7 @@ void rtl8180_hw_wakeup_wq (struct work_struct *work) ...@@ -5438,7 +5438,7 @@ void rtl8180_hw_wakeup_wq (struct work_struct *work)
// struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq); // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
// struct ieee80211_device * ieee = (struct ieee80211_device*) // struct ieee80211_device * ieee = (struct ieee80211_device*)
// container_of(work, struct ieee80211_device, watch_dog_wq); // container_of(work, struct ieee80211_device, watch_dog_wq);
struct delayed_work *dwork = container_of(work,struct delayed_work,work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq); struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
struct net_device *dev = ieee->dev; struct net_device *dev = ieee->dev;
#else #else
...@@ -5459,7 +5459,7 @@ void rtl8180_hw_sleep_wq (struct work_struct *work) ...@@ -5459,7 +5459,7 @@ void rtl8180_hw_sleep_wq (struct work_struct *work)
// struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq); // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
// struct ieee80211_device * ieee = (struct ieee80211_device*) // struct ieee80211_device * ieee = (struct ieee80211_device*)
// container_of(work, struct ieee80211_device, watch_dog_wq); // container_of(work, struct ieee80211_device, watch_dog_wq);
struct delayed_work *dwork = container_of(work,struct delayed_work,work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq); struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
struct net_device *dev = ieee->dev; struct net_device *dev = ieee->dev;
#else #else
...@@ -6407,7 +6407,7 @@ priv->txnpring)/8); ...@@ -6407,7 +6407,7 @@ priv->txnpring)/8);
void rtl8180_tx_irq_wq(struct work_struct *work) void rtl8180_tx_irq_wq(struct work_struct *work)
{ {
//struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq); //struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
struct delayed_work *dwork = container_of(work,struct delayed_work,work); struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device * ieee = (struct ieee80211_device*) struct ieee80211_device * ieee = (struct ieee80211_device*)
container_of(dwork, struct ieee80211_device, watch_dog_wq); container_of(dwork, struct ieee80211_device, watch_dog_wq);
struct net_device *dev = ieee->dev; struct net_device *dev = ieee->dev;
...@@ -6691,7 +6691,7 @@ lizhaoming--------------------------- RF power on/power off ----------------- ...@@ -6691,7 +6691,7 @@ lizhaoming--------------------------- RF power on/power off -----------------
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
void GPIOChangeRFWorkItemCallBack(struct work_struct *work) void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
{ {
//struct delayed_work *dwork = container_of(work, struct delayed_work, work); //struct delayed_work *dwork = to_delayed_work(work);
struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work); struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
struct net_device *dev = ieee->dev; struct net_device *dev = ieee->dev;
struct r8180_priv *priv = ieee80211_priv(dev); struct r8180_priv *priv = ieee80211_priv(dev);
......
...@@ -471,7 +471,7 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc) ...@@ -471,7 +471,7 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
*/ */
static void wusbhc_keep_alive_run(struct work_struct *ws) static void wusbhc_keep_alive_run(struct work_struct *ws)
{ {
struct delayed_work *dw = container_of(ws, struct delayed_work, work); struct delayed_work *dw = to_delayed_work(ws);
struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer); struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer);
mutex_lock(&wusbhc->mutex); mutex_lock(&wusbhc->mutex);
......
...@@ -41,6 +41,11 @@ struct delayed_work { ...@@ -41,6 +41,11 @@ struct delayed_work {
struct timer_list timer; struct timer_list timer;
}; };
static inline struct delayed_work *to_delayed_work(struct work_struct *work)
{
return container_of(work, struct delayed_work, work);
}
struct execute_work { struct execute_work {
struct work_struct work; struct work_struct work;
}; };
......
...@@ -3992,8 +3992,7 @@ static void cache_reap(struct work_struct *w) ...@@ -3992,8 +3992,7 @@ static void cache_reap(struct work_struct *w)
struct kmem_cache *searchp; struct kmem_cache *searchp;
struct kmem_list3 *l3; struct kmem_list3 *l3;
int node = numa_node_id(); int node = numa_node_id();
struct delayed_work *work = struct delayed_work *work = to_delayed_work(w);
container_of(w, struct delayed_work, work);
if (!mutex_trylock(&cache_chain_mutex)) if (!mutex_trylock(&cache_chain_mutex))
/* Give up. Setup the next iteration. */ /* Give up. Setup the next iteration. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment