Skip to content

Commit 70044d7

Browse files
committed
firewire: don't use PREPARE_DELAYED_WORK
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 Cc: stable@vger.kernel.org # v3.9+ Cc: stable@vger.kernel.org # v3.8.2+ Cc: stable@vger.kernel.org # v3.4.60+ Cc: stable@vger.kernel.org # v3.2.40+
1 parent 5bdfff9 commit 70044d7

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
@@ -916,7 +916,7 @@ static int lookup_existing_device(struct device *dev, void *data)
916916
old->config_rom_retries = 0;
917917
fw_notice(card, "rediscovered device %s\n", dev_name(dev));
918918

919-
PREPARE_DELAYED_WORK(&old->work, fw_device_update);
919+
old->workfn = fw_device_update;
920920
fw_schedule_device_work(old, 0);
921921

922922
if (current_node == card->root_node)
@@ -1075,7 +1075,7 @@ static void fw_device_init(struct work_struct *work)
10751075
if (atomic_cmpxchg(&device->state,
10761076
FW_DEVICE_INITIALIZING,
10771077
FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
1078-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1078+
device->workfn = fw_device_shutdown;
10791079
fw_schedule_device_work(device, SHUTDOWN_DELAY);
10801080
} else {
10811081
fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
@@ -1196,13 +1196,20 @@ static void fw_device_refresh(struct work_struct *work)
11961196
dev_name(&device->device), fw_rcode_string(ret));
11971197
gone:
11981198
atomic_set(&device->state, FW_DEVICE_GONE);
1199-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1199+
device->workfn = fw_device_shutdown;
12001200
fw_schedule_device_work(device, SHUTDOWN_DELAY);
12011201
out:
12021202
if (node_id == card->root_node->node_id)
12031203
fw_schedule_bm_work(card, 0);
12041204
}
12051205

1206+
static void fw_device_workfn(struct work_struct *work)
1207+
{
1208+
struct fw_device *device = container_of(to_delayed_work(work),
1209+
struct fw_device, work);
1210+
device->workfn(work);
1211+
}
1212+
12061213
void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12071214
{
12081215
struct fw_device *device;
@@ -1252,7 +1259,8 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12521259
* power-up after getting plugged in. We schedule the
12531260
* first config rom scan half a second after bus reset.
12541261
*/
1255-
INIT_DELAYED_WORK(&device->work, fw_device_init);
1262+
device->workfn = fw_device_init;
1263+
INIT_DELAYED_WORK(&device->work, fw_device_workfn);
12561264
fw_schedule_device_work(device, INITIAL_DELAY);
12571265
break;
12581266

@@ -1268,7 +1276,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12681276
if (atomic_cmpxchg(&device->state,
12691277
FW_DEVICE_RUNNING,
12701278
FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
1271-
PREPARE_DELAYED_WORK(&device->work, fw_device_refresh);
1279+
device->workfn = fw_device_refresh;
12721280
fw_schedule_device_work(device,
12731281
device->is_local ? 0 : INITIAL_DELAY);
12741282
}
@@ -1283,7 +1291,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12831291
smp_wmb(); /* update node_id before generation */
12841292
device->generation = card->generation;
12851293
if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1286-
PREPARE_DELAYED_WORK(&device->work, fw_device_update);
1294+
device->workfn = fw_device_update;
12871295
fw_schedule_device_work(device, 0);
12881296
}
12891297
break;
@@ -1308,7 +1316,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
13081316
device = node->data;
13091317
if (atomic_xchg(&device->state,
13101318
FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
1311-
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1319+
device->workfn = fw_device_shutdown;
13121320
fw_schedule_device_work(device,
13131321
list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
13141322
}

‎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)