Skip to content

Commit 6ff8147

Browse files
author
Stefan Richter
committed
firewire: sbp2: remove obsolete reference counting
Since commit 0278ccd "firewire: sbp2: fix panic after rmmod with slow targets", the lifetime of an sbp2_target instance does no longer extent past the return of sbp2_remove(). Therefore it is no longer necessary to call fw_unit_get/put() and fw_device_get/put() in sbp2_probe/remove(). Furthermore, said commit also ensures that lu->work is not going to be executed or requeued at a time when the sbp2_target is no longer in use. Hence there is no need for sbp2_target reference counting for lu->work. Other concurrent contexts: - Processes which access the sysfs of the SCSI host device or of one of its subdevices are safe because these interfaces are all removed by scsi_remove_device/host() in sbp2_release_target(). - SBP-2 command block ORB transactions are finished when scsi_remove_device() in sbp2_release_target() returns. - SBP-2 management ORB transactions are finished when cancel_delayed_work_sync(&lu->work) before sbp2_release_target() returns. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
1 parent f39aa30 commit 6ff8147

1 file changed

Lines changed: 17 additions & 40 deletions

File tree

‎drivers/firewire/sbp2.c‎

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ struct sbp2_logical_unit {
159159
* and one struct Scsi_Host per sbp2_target.
160160
*/
161161
struct sbp2_target {
162-
struct kref kref;
163162
struct fw_unit *unit;
164163
const char *bus_id;
165164
struct list_head lu_list;
@@ -772,9 +771,8 @@ static int sbp2_lun2int(u16 lun)
772771
return scsilun_to_int(&eight_bytes_lun);
773772
}
774773

775-
static void sbp2_release_target(struct kref *kref)
774+
static void sbp2_release_target(struct sbp2_target *tgt)
776775
{
777-
struct sbp2_target *tgt = container_of(kref, struct sbp2_target, kref);
778776
struct sbp2_logical_unit *lu, *next;
779777
struct Scsi_Host *shost =
780778
container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
@@ -811,30 +809,12 @@ static void sbp2_release_target(struct kref *kref)
811809
scsi_remove_host(shost);
812810
fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
813811

814-
fw_unit_put(tgt->unit);
815812
scsi_host_put(shost);
816-
fw_device_put(device);
817-
}
818-
819-
static void sbp2_target_get(struct sbp2_target *tgt)
820-
{
821-
kref_get(&tgt->kref);
822-
}
823-
824-
static void sbp2_target_put(struct sbp2_target *tgt)
825-
{
826-
kref_put(&tgt->kref, sbp2_release_target);
827813
}
828814

829-
/*
830-
* Always get the target's kref when scheduling work on one its units.
831-
* Each workqueue job is responsible to call sbp2_target_put() upon return.
832-
*/
833815
static void sbp2_queue_work(struct sbp2_logical_unit *lu, unsigned long delay)
834816
{
835-
sbp2_target_get(lu->tgt);
836-
if (!queue_delayed_work(fw_workqueue, &lu->work, delay))
837-
sbp2_target_put(lu->tgt);
817+
queue_delayed_work(fw_workqueue, &lu->work, delay);
838818
}
839819

840820
/*
@@ -877,7 +857,7 @@ static void sbp2_login(struct work_struct *work)
877857
int generation, node_id, local_node_id;
878858

879859
if (fw_device_is_shutdown(device))
880-
goto out;
860+
return;
881861

882862
generation = device->generation;
883863
smp_rmb(); /* node IDs must not be older than generation */
@@ -899,7 +879,7 @@ static void sbp2_login(struct work_struct *work)
899879
/* Let any waiting I/O fail from now on. */
900880
sbp2_unblock(lu->tgt);
901881
}
902-
goto out;
882+
return;
903883
}
904884

905885
tgt->node_id = node_id;
@@ -925,7 +905,8 @@ static void sbp2_login(struct work_struct *work)
925905
if (lu->has_sdev) {
926906
sbp2_cancel_orbs(lu);
927907
sbp2_conditionally_unblock(lu);
928-
goto out;
908+
909+
return;
929910
}
930911

931912
if (lu->tgt->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
@@ -957,7 +938,8 @@ static void sbp2_login(struct work_struct *work)
957938
lu->has_sdev = true;
958939
scsi_device_put(sdev);
959940
sbp2_allow_block(lu);
960-
goto out;
941+
942+
return;
961943

962944
out_logout_login:
963945
smp_rmb(); /* generation may have changed */
@@ -971,8 +953,6 @@ static void sbp2_login(struct work_struct *work)
971953
* lu->work already. Reset the work from reconnect to login.
972954
*/
973955
PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
974-
out:
975-
sbp2_target_put(tgt);
976956
}
977957

978958
static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
@@ -1141,7 +1121,6 @@ static int sbp2_probe(struct device *dev)
11411121
tgt = (struct sbp2_target *)shost->hostdata;
11421122
dev_set_drvdata(&unit->device, tgt);
11431123
tgt->unit = unit;
1144-
kref_init(&tgt->kref);
11451124
INIT_LIST_HEAD(&tgt->lu_list);
11461125
tgt->bus_id = dev_name(&unit->device);
11471126
tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
@@ -1154,9 +1133,6 @@ static int sbp2_probe(struct device *dev)
11541133
if (scsi_add_host(shost, &unit->device) < 0)
11551134
goto fail_shost_put;
11561135

1157-
fw_device_get(device);
1158-
fw_unit_get(unit);
1159-
11601136
/* implicit directory ID */
11611137
tgt->directory_id = ((unit->directory - device->config_rom) * 4
11621138
+ CSR_CONFIG_ROM) & 0xffffff;
@@ -1166,7 +1142,7 @@ static int sbp2_probe(struct device *dev)
11661142

11671143
if (sbp2_scan_unit_dir(tgt, unit->directory, &model,
11681144
&firmware_revision) < 0)
1169-
goto fail_tgt_put;
1145+
goto fail_release_target;
11701146

11711147
sbp2_clamp_management_orb_timeout(tgt);
11721148
sbp2_init_workarounds(tgt, model, firmware_revision);
@@ -1183,10 +1159,11 @@ static int sbp2_probe(struct device *dev)
11831159
/* Do the login in a workqueue so we can easily reschedule retries. */
11841160
list_for_each_entry(lu, &tgt->lu_list, link)
11851161
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
1162+
11861163
return 0;
11871164

1188-
fail_tgt_put:
1189-
sbp2_target_put(tgt);
1165+
fail_release_target:
1166+
sbp2_release_target(tgt);
11901167
return -ENOMEM;
11911168

11921169
fail_shost_put:
@@ -1203,7 +1180,8 @@ static int sbp2_remove(struct device *dev)
12031180
list_for_each_entry(lu, &tgt->lu_list, link)
12041181
cancel_delayed_work_sync(&lu->work);
12051182

1206-
sbp2_target_put(tgt);
1183+
sbp2_release_target(tgt);
1184+
12071185
return 0;
12081186
}
12091187

@@ -1216,7 +1194,7 @@ static void sbp2_reconnect(struct work_struct *work)
12161194
int generation, node_id, local_node_id;
12171195

12181196
if (fw_device_is_shutdown(device))
1219-
goto out;
1197+
return;
12201198

12211199
generation = device->generation;
12221200
smp_rmb(); /* node IDs must not be older than generation */
@@ -1241,7 +1219,8 @@ static void sbp2_reconnect(struct work_struct *work)
12411219
PREPARE_DELAYED_WORK(&lu->work, sbp2_login);
12421220
}
12431221
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
1244-
goto out;
1222+
1223+
return;
12451224
}
12461225

12471226
tgt->node_id = node_id;
@@ -1255,8 +1234,6 @@ static void sbp2_reconnect(struct work_struct *work)
12551234
sbp2_agent_reset(lu);
12561235
sbp2_cancel_orbs(lu);
12571236
sbp2_conditionally_unblock(lu);
1258-
out:
1259-
sbp2_target_put(tgt);
12601237
}
12611238

12621239
static void sbp2_update(struct fw_unit *unit)

0 commit comments

Comments
 (0)