From 74bee99f5928fd84a876a15b54493264eeff4f16 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 18 Apr 2017 03:57:12 +0000 Subject: [PATCH 1/3] iscsi-scst: replace strncpy() by strlcpy() Follow up for r7109: strlcpy() is more appropriate in this place. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7134 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 0cb47fe31..d942afdf3 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -415,8 +415,7 @@ int target_create(const char *name, struct target **out_target) } memset(target, 0, sizeof(*target)); - strncpy(target->name, name, sizeof(target->name) - 1); - target->name[sizeof(target->name)-1] = '\0'; + strlcpy(target->name, name, sizeof(target->name)); params_set_defaults(target->target_params, target_keys); params_set_defaults(target->session_params, session_keys); From 89a939536fa1931c45a64b46b296e91028527392 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 18 Apr 2017 04:02:44 +0000 Subject: [PATCH 2/3] fcst: Linux kernel v4.10 build fix Signed-off-by: Sebastian Herbszt git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7135 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- fcst/ft_cmd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ fcst/ft_io.c | 8 ++++++++ 2 files changed, 54 insertions(+) diff --git a/fcst/ft_cmd.c b/fcst/ft_cmd.c index adc297847..b99880c1a 100644 --- a/fcst/ft_cmd.c +++ b/fcst/ft_cmd.c @@ -256,14 +256,24 @@ static void ft_cmd_done(struct ft_cmd *fcmd) { struct fc_frame *fp = fcmd->req_frame; struct fc_seq *sp = fcmd->seq; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) struct fc_lport *lport = fr_dev(fp); +#endif if (sp) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_exch_done(sp); +#else lport->tt.exch_done(sp); +#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) if (fr_seq(fp)) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_seq_release(fr_seq(fp)); +#else lport->tt.seq_release(fr_seq(fp)); +#endif #endif fc_frame_free(fp); @@ -385,11 +395,19 @@ int ft_send_response(struct scst_cmd *cmd) /* * Send response. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fcmd->seq = fc_seq_start_next(fcmd->seq); +#else fcmd->seq = lport->tt.seq_start_next(fcmd->seq); +#endif fc_fill_fc_hdr(fp, FC_RCTL_DD_CMD_STATUS, ep->did, ep->sid, FC_TYPE_FCP, FC_FC_EX_CTX | FC_FC_LAST_SEQ | FC_FC_END_SEQ, 0); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + error = FCST_INJ_SEND_ERR(fc_seq_send(lport, fcmd->seq, fp)); +#else error = FCST_INJ_SEND_ERR(lport->tt.seq_send(lport, fcmd->seq, fp)); +#endif if (error < 0) { pr_err("Sending response for exchange with OX_ID %#x and RX_ID" " %#x failed: %d\n", ep->oxid, ep->rxid, error); @@ -487,10 +505,18 @@ int ft_send_xfer_rdy(struct scst_cmd *cmd) txrdy->ft_data_ro = 0; txrdy->ft_burst_len = htonl(scst_cmd_get_bufflen(cmd)); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fcmd->seq = fc_seq_start_next(fcmd->seq); +#else fcmd->seq = lport->tt.seq_start_next(fcmd->seq); +#endif fc_fill_fc_hdr(fp, FC_RCTL_DD_DATA_DESC, ep->did, ep->sid, FC_TYPE_FCP, FC_FC_EX_CTX | FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + error = FCST_INJ_SEND_ERR(fc_seq_send(lport, fcmd->seq, fp)); +#else error = FCST_INJ_SEND_ERR(lport->tt.seq_send(lport, fcmd->seq, fp)); +#endif switch (error) { case 0: return SCST_TGT_RES_SUCCESS; @@ -560,7 +586,11 @@ out: fc_fill_reply_hdr(fp, rx_fp, FC_RCTL_DD_CMD_STATUS, 0); sp = fr_seq(fp); if (sp) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_seq_send(lport, sp, fp); +#else lport->tt.seq_send(lport, sp, fp); +#endif else lport->tt.frame_send(lport, fp); #endif @@ -687,8 +717,12 @@ static void ft_recv_cmd(struct ft_sess *sess, struct fc_frame *fp) #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) sp = fr_seq(fp); +#else +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + sp = fc_seq_assign(lport, fp); #else sp = lport->tt.seq_assign(lport, fp); +#endif if (!sp) goto busy; #endif @@ -737,7 +771,11 @@ static void ft_recv_cmd(struct ft_sess *sess, struct fc_frame *fp) cmd->state = FT_STATE_NEW; fcmd->seq = sp; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_seq_set_resp(sp, ft_recv_seq, cmd); +#else lport->tt.seq_set_resp(sp, ft_recv_seq, cmd); +#endif switch (fcp->fc_flags & (FCP_CFL_RDDATA | FCP_CFL_WRDATA)) { case 0: @@ -786,7 +824,11 @@ busy: if (fcmd) ft_cmd_done(fcmd); else if (sp) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_exch_done(sp); +#else lport->tt.exch_done(sp); +#endif } /* @@ -825,8 +867,12 @@ static void ft_cmd_ls_rjt(struct fc_frame *rx_fp, enum fc_els_rjt_reason reason, lport = fr_dev(rx_fp); rjt_data.reason = reason; rjt_data.explan = explan; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fc_seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data); +#else lport->tt.seq_els_rsp_send(rx_fp, ELS_LS_RJT, &rjt_data); #endif +#endif } /* diff --git a/fcst/ft_io.c b/fcst/ft_io.c index 19be72e8b..42639cbc5 100644 --- a/fcst/ft_io.c +++ b/fcst/ft_io.c @@ -89,7 +89,11 @@ int ft_send_read_data(struct scst_cmd *cmd) mem_len -= tlen; mem_off = tlen; } else +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + fcmd->seq = fc_seq_start_next(fcmd->seq); +#else fcmd->seq = lport->tt.seq_start_next(fcmd->seq); +#endif /* no scatter/gather in skb for odd word length due to fc_seq_send() */ use_sg = !(remaining % 4) && lport->sg_supp; @@ -175,8 +179,12 @@ int ft_send_read_data(struct scst_cmd *cmd) remaining ? (FC_FC_EX_CTX | FC_FC_REL_OFF) : (FC_FC_EX_CTX | FC_FC_REL_OFF | FC_FC_END_SEQ), fh_off); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) + error = FCST_INJ_SEND_ERR(fc_seq_send(lport, fcmd->seq, fp)); +#else error = FCST_INJ_SEND_ERR(lport->tt.seq_send(lport, fcmd->seq, fp)); +#endif if (error) { pr_warn("Sending frame with oid %#x oxid %#x resp_len" " %d failed at frame_off %u / remaining %zu" From 24b9a38b2bb67561ade8f288cbc380a86c6a010d Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 18 Apr 2017 04:06:18 +0000 Subject: [PATCH 3/3] scst: avoid possible side effect with WARN_ON_ONCE() Reported-By: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7136 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 36456f224..41f59fdf8 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4783,6 +4783,7 @@ static void scst_put_acg_work(struct work_struct *work) void scst_put_acg(struct scst_acg *acg) { struct scst_acg_put_work *put_work; + bool rc; put_work = kmalloc(sizeof(*put_work), GFP_KERNEL | __GFP_NOFAIL); if (WARN_ON_ONCE(!put_work)) { @@ -4801,7 +4802,9 @@ void scst_put_acg(struct scst_acg *acg) * Schedule the kref_put() call instead of invoking it directly to * avoid deep recursion and a stack overflow. */ - WARN_ON_ONCE(!queue_work(scst_release_acg_wq, &put_work->work)); + rc = queue_work(scst_release_acg_wq, &put_work->work); + WARN_ON_ONCE(!rc); + return; } void scst_get_acg(struct scst_acg *acg)