Skip to contentSkip to conversation

mv-otg: use to_delayed_work instead of cast

PATCH New Cesar Eduardo Barros 1 participant 1 message Dec 4, 2012 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mv-otg: use to_delayed_work instead of cast

Directly casting a work_struct pointer to a delayed_work is risky if the work member of struct delayed_work is ever moved from being the first member.

Instead, use the inline function to_delayed_work(), which does the same cast in a safer way (using container_of).

---
 drivers/usb/otg/mv_otg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/otg/mv_otg.c +1 -1
index 3f124e8..156e1d9 100644
@@ -420,7 +420,7 @@ static void mv_otg_work(struct work_struct *work)
 	struct usb_otg *otg;
 	int old_state;
 
-	mvotg = container_of((struct delayed_work *)work, struct mv_otg, work);
+	mvotg = container_of(to_delayed_work(work), struct mv_otg, work);
 
 run:
 	/* work queue is single thread, or we need spin_lock to protect */
Signature · 1 line
1.7.11.7