Skip to content

Commit ce6ea17

Browse files
htejunpopcornmix
authored andcommitted
firewire: don't use PREPARE_DELAYED_WORK
commit 70044d7 upstream. PREPARE_[DELAYED_]WORK() are being phased out. They have few users and a nasty surprise in terms of reentrancy guarantee as workqueue considers work items to be different if they don't have the same work function. firewire core-device and sbp2 have been been multiplexing work items with multiple work functions. Introduce fw_device_workfn() and sbp2_lu_workfn() which invoke fw_device->workfn and sbp2_logical_unit->workfn respectively and always use the two functions as the work functions and update the users to set the ->workfn fields instead of overriding work functions using PREPARE_DELAYED_WORK(). This fixes a variety of possible regressions since a2c1c57 "workqueue: consider work function when searching for busy work items" due to which fw_workqueue lost its required non-reentrancy property. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> Cc: linux1394-devel@lists.sourceforge.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a5c82bd commit ce6ea17

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎drivers/firewire/core-device.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static int lookup_existing_device(struct device *dev, void *data)
895895
old->config_rom_retries = 0;
896896
fw_notice(card, "rediscovered device %s\n", dev_name(dev));
897897

898-
PREPARE_DELAYED_WORK(&old->work, fw_device_update);
898+
old->workfn = fw_device_update;
899899
fw_schedule_device_work(old, 0);
900900

901901
if (current_node == card->root_node)
@@ -1054,7 +1054,7 @@ static void fw_device_init(struct work_struct *work)
10541054
if (atomic_cmpxchg(&device->state,
10551055
FW_DEVICE_INITIALIZING,
10561056
FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
1057-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1057+
device->workfn = fw_device_shutdown;
10581058
fw_schedule_device_work(device, SHUTDOWN_DELAY);
10591059
} else {
10601060
fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
@@ -1175,13 +1175,20 @@ static void fw_device_refresh(struct work_struct *work)
11751175
dev_name(&device->device), fw_rcode_string(ret));
11761176
gone:
11771177
atomic_set(&device->state, FW_DEVICE_GONE);
1178-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1178+
device->workfn = fw_device_shutdown;
11791179
fw_schedule_device_work(device, SHUTDOWN_DELAY);
11801180
out:
11811181
if (node_id == card->root_node->node_id)
11821182
fw_schedule_bm_work(card, 0);
11831183
}
11841184

1185+
static void fw_device_workfn(struct work_struct *work)
1186+
{
1187+
struct fw_device *device = container_of(to_delayed_work(work),
1188+
struct fw_device, work);
1189+
device->workfn(work);
1190+
}
1191+
11851192
void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
11861193
{
11871194
struct fw_device *device;
@@ -1231,7 +1238,8 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12311238
* power-up after getting plugged in. We schedule the
12321239
* first config rom scan half a second after bus reset.
12331240
*/
1234-
INIT_DELAYED_WORK(&device->work, fw_device_init);
1241+
device->workfn = fw_device_init;
1242+
INIT_DELAYED_WORK(&device->work, fw_device_workfn);
12351243
fw_schedule_device_work(device, INITIAL_DELAY);
12361244
break;
12371245

@@ -1247,7 +1255,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12471255
if (atomic_cmpxchg(&device->state,
12481256
FW_DEVICE_RUNNING,
12491257
FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
1250-
PREPARE_DELAYED_WORK(&device->work, fw_device_refresh);
1258+
device->workfn = fw_device_refresh;
12511259
fw_schedule_device_work(device,
12521260
device->is_local ? 0 : INITIAL_DELAY);
12531261
}
@@ -1262,7 +1270,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12621270
smp_wmb(); /* update node_id before generation */
12631271
device->generation = card->generation;
12641272
if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1265-
PREPARE_DELAYED_WORK(&device->work, fw_device_update);
1273+
device->workfn = fw_device_update;
12661274
fw_schedule_device_work(device, 0);
12671275
}
12681276
break;
@@ -1287,7 +1295,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12871295
device = node->data;
12881296
if (atomic_xchg(&device->state,
12891297
FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
1290-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1298+
device->workfn = fw_device_shutdown;
12911299
fw_schedule_device_work(device,
12921300
list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
12931301
}

‎drivers/firewire/sbp2.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ struct sbp2_logical_unit {
146146
*/
147147
int generation;
148148
int retries;
149+
work_func_t workfn;
149150
struct delayed_work work;
150151
bool has_sdev;
151152
bool blocked;
@@ -864,7 +865,7 @@ static void sbp2_login(struct work_struct *work)
864865
/* set appropriate retry limit(s) in BUSY_TIMEOUT register */
865866
sbp2_set_busy_timeout(lu);
866867

867-
PREPARE_DELAYED_WORK(&lu->work, sbp2_reconnect);
868+
lu->workfn = sbp2_reconnect;
868869
sbp2_agent_reset(lu);
869870

870871
/* This was a re-login. */
@@ -918,7 +919,7 @@ static void sbp2_login(struct work_struct *work)
918919
* If a bus reset happened, sbp2_update will have requeued
919920
* lu->work already. Reset the work from reconnect to login.
920921
*/
921-
PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
922+
lu->workfn = sbp2_login;
922923
}
923924

924925
static void sbp2_reconnect(struct work_struct *work)
@@ -952,7 +953,7 @@ static void sbp2_reconnect(struct work_struct *work)
952953
lu->retries++ >= 5) {
953954
dev_err(tgt_dev(tgt), "failed to reconnect\n");
954955
lu->retries = 0;
955-
PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
956+
lu->workfn = sbp2_login;
956957
}
957958
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
958959

@@ -972,6 +973,13 @@ static void sbp2_reconnect(struct work_struct *work)
972973
sbp2_conditionally_unblock(lu);
973974
}
974975

976+
static void sbp2_lu_workfn(struct work_struct *work)
977+
{
978+
struct sbp2_logical_unit *lu = container_of(to_delayed_work(work),
979+
struct sbp2_logical_unit, work);
980+
lu->workfn(work);
981+
}
982+
975983
static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
976984
{
977985
struct sbp2_logical_unit *lu;
@@ -998,7 +1006,8 @@ static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
9981006
lu->blocked = false;
9991007
++tgt->dont_block;
10001008
INIT_LIST_HEAD(&lu->orb_list);
1001-
INIT_DELAYED_WORK(&lu->work, sbp2_login);
1009+
lu->workfn = sbp2_login;
1010+
INIT_DELAYED_WORK(&lu->work, sbp2_lu_workfn);
10021011

10031012
list_add_tail(&lu->link, &tgt->lu_list);
10041013
return 0;

‎include/linux/firewire.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct fw_device {
200200
unsigned irmc:1;
201201
unsigned bc_implemented:2;
202202

203+
work_func_t workfn;
203204
struct delayed_work work;
204205
struct fw_attribute_group attribute_group;
205206
};

0 commit comments

Comments
 (0)