Skip to content

Commit cff834c

Browse files
author
Nicholas Bellinger
committed
usb-gadget/tcm: Convert to TARGET_SCF_ACK_KREF I/O krefs
This patch drops struct usbg_cmd->kref internal kref-erence usage, for proper TARGET_SCF_ACK_KREF conversion. Tested-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 71e7ae8 commit cff834c

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

drivers/usb/gadget/function/f_tcm.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ static inline struct f_uas *to_f_uas(struct usb_function *f)
4141
return container_of(f, struct f_uas, function);
4242
}
4343

44-
static void usbg_cmd_release(struct kref *);
45-
46-
static inline void usbg_cleanup_cmd(struct usbg_cmd *cmd)
47-
{
48-
kref_put(&cmd->ref, usbg_cmd_release);
49-
}
50-
5144
/* Start bot.c code */
5245

5346
static int bot_enqueue_cmd_cbw(struct f_uas *fu)
@@ -68,7 +61,7 @@ static void bot_status_complete(struct usb_ep *ep, struct usb_request *req)
6861
struct usbg_cmd *cmd = req->context;
6962
struct f_uas *fu = cmd->fu;
7063

71-
usbg_cleanup_cmd(cmd);
64+
transport_generic_free_cmd(&cmd->se_cmd, 0);
7265
if (req->status < 0) {
7366
pr_err("ERR %s(%d)\n", __func__, __LINE__);
7467
return;
@@ -605,7 +598,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req)
605598
break;
606599

607600
case UASP_QUEUE_COMMAND:
608-
usbg_cleanup_cmd(cmd);
601+
transport_generic_free_cmd(&cmd->se_cmd, 0);
609602
usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC);
610603
break;
611604

@@ -615,7 +608,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req)
615608
return;
616609

617610
cleanup:
618-
usbg_cleanup_cmd(cmd);
611+
transport_generic_free_cmd(&cmd->se_cmd, 0);
619612
}
620613

621614
static int uasp_send_status_response(struct usbg_cmd *cmd)
@@ -977,7 +970,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req)
977970
return;
978971

979972
cleanup:
980-
usbg_cleanup_cmd(cmd);
973+
transport_generic_free_cmd(&cmd->se_cmd, 0);
981974
}
982975

983976
static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req)
@@ -1046,7 +1039,7 @@ static void usbg_cmd_work(struct work_struct *work)
10461039
struct se_cmd *se_cmd;
10471040
struct tcm_usbg_nexus *tv_nexus;
10481041
struct usbg_tpg *tpg;
1049-
int dir;
1042+
int dir, flags = (TARGET_SCF_UNKNOWN_SIZE | TARGET_SCF_ACK_KREF);
10501043

10511044
se_cmd = &cmd->se_cmd;
10521045
tpg = cmd->fu->tpg;
@@ -1060,17 +1053,17 @@ static void usbg_cmd_work(struct work_struct *work)
10601053
goto out;
10611054
}
10621055

1063-
if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess,
1064-
cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun,
1065-
0, cmd->prio_attr, dir, TARGET_SCF_UNKNOWN_SIZE) < 0)
1056+
if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf,
1057+
cmd->sense_iu.sense, cmd->unpacked_lun, 0,
1058+
cmd->prio_attr, dir, flags) < 0)
10661059
goto out;
10671060

10681061
return;
10691062

10701063
out:
10711064
transport_send_check_condition_and_sense(se_cmd,
10721065
TCM_UNSUPPORTED_SCSI_OPCODE, 1);
1073-
usbg_cleanup_cmd(cmd);
1066+
transport_generic_free_cmd(&cmd->se_cmd, 0);
10741067
}
10751068

10761069
static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu,
@@ -1126,11 +1119,6 @@ static int usbg_submit_command(struct f_uas *fu,
11261119
pr_err("usbg_get_cmd failed\n");
11271120
return -ENOMEM;
11281121
}
1129-
1130-
/* XXX until I figure out why I can't free in on complete */
1131-
kref_init(&cmd->ref);
1132-
kref_get(&cmd->ref);
1133-
11341122
memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len);
11351123

11361124
if (fu->flags & USBG_USE_STREAMS) {
@@ -1203,7 +1191,7 @@ static void bot_cmd_work(struct work_struct *work)
12031191
out:
12041192
transport_send_check_condition_and_sense(se_cmd,
12051193
TCM_UNSUPPORTED_SCSI_OPCODE, 1);
1206-
usbg_cleanup_cmd(cmd);
1194+
transport_generic_free_cmd(&cmd->se_cmd, 0);
12071195
}
12081196

12091197
static int bot_submit_command(struct f_uas *fu,
@@ -1239,11 +1227,6 @@ static int bot_submit_command(struct f_uas *fu,
12391227
pr_err("usbg_get_cmd failed\n");
12401228
return -ENOMEM;
12411229
}
1242-
1243-
/* XXX until I figure out why I can't free in on complete */
1244-
kref_init(&cmd->ref);
1245-
kref_get(&cmd->ref);
1246-
12471230
memcpy(cmd->cmd_buf, cbw->CDB, cmd_len);
12481231

12491232
cmd->bot_tag = cbw->Tag;
@@ -1297,14 +1280,6 @@ static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg)
12971280
return 1;
12981281
}
12991282

1300-
static void usbg_cmd_release(struct kref *ref)
1301-
{
1302-
struct usbg_cmd *cmd = container_of(ref, struct usbg_cmd,
1303-
ref);
1304-
1305-
transport_generic_free_cmd(&cmd->se_cmd, 0);
1306-
}
1307-
13081283
static void usbg_release_cmd(struct se_cmd *se_cmd)
13091284
{
13101285
struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd,
@@ -1745,11 +1720,7 @@ static void usbg_port_unlink(struct se_portal_group *se_tpg,
17451720

17461721
static int usbg_check_stop_free(struct se_cmd *se_cmd)
17471722
{
1748-
struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd,
1749-
se_cmd);
1750-
1751-
kref_put(&cmd->ref, usbg_cmd_release);
1752-
return 1;
1723+
return target_put_sess_cmd(se_cmd);
17531724
}
17541725

17551726
static const struct target_core_fabric_ops usbg_ops = {

0 commit comments

Comments
 (0)