Re: target: Split transport_send_check_condition_and_sense()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/11/2016 12:00 AM, Dan Carpenter wrote:
> Hello Bart Van Assche,
> 
> The patch ab78fef4d5f7: "target: Split
> transport_send_check_condition_and_sense()" from Jul 8, 2015, leads
> to the following static checker warning:
> 
> 	drivers/target/target_core_transport.c:2909 translate_sense_reason()
> 	error: XXX potentially using uninitialized 'asc'.
> 
> drivers/target/target_core_transport.c
>    2893  static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason)
>    2894  {
>    2895          const struct sense_info *si;
>    2896          u8 *buffer = cmd->sense_buffer;
>    2897          int r = (__force int)reason;
>    2898          u8 asc, ascq;
>                     ^^^
>    2899          bool desc_format = target_sense_desc_format(cmd->se_dev);
>    2900
>    2901          if (r < ARRAY_SIZE(sense_info_table) && sense_info_table[r].key)
>    2902                  si = &sense_info_table[r];
>    2903          else
>    2904                  si = &sense_info_table[(__force int)
>    2905                                         TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE];
>    2906
>    2907          if (reason == TCM_CHECK_CONDITION_UNIT_ATTENTION) {
>    2908                  core_scsi3_ua_for_check_condition(cmd, &asc, &ascq);
>                                                                 ^^^^
> No checking for negative returns.
> 
>    2909                  WARN_ON_ONCE(asc == 0);
>                                       ^^^^^^^^
>    2910          } else if (si->asc == 0) {
>    2911                  WARN_ON_ONCE(cmd->scsi_asc == 0);
>    2912                  asc = cmd->scsi_asc;
>    2913                  ascq = cmd->scsi_ascq;
>    2914          } else {
 
Hello Dan,

Thanks for reporting this. However, if you have a close look at
the patch mentioned in your e-mail then you will see that the
above warning predates my patch. Anyway, how about fixing this
warning with the patch below ?


---
 drivers/target/target_core_transport.c |  6 ++++--
 drivers/target/target_core_ua.c        | 15 +++++++--------
 drivers/target/target_core_ua.h        |  2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 867bc6d..8e8e0e9 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2821,7 +2821,7 @@ static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason)
 {
 	const struct sense_info *si;
 	u8 *buffer = cmd->sense_buffer;
-	int r = (__force int)reason;
+	int ret, r = (__force int)reason;
 	u8 asc, ascq;
 	bool desc_format = target_sense_desc_format(cmd->se_dev);
 
@@ -2832,7 +2832,9 @@ static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason)
 				       TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE];
 
 	if (reason == TCM_CHECK_CONDITION_UNIT_ATTENTION) {
-		core_scsi3_ua_for_check_condition(cmd, &asc, &ascq);
+		ret = core_scsi3_ua_for_check_condition(cmd, &asc, &ascq);
+		if (ret < 0)
+			return ret;
 		WARN_ON_ONCE(asc == 0);
 	} else if (si->asc == 0) {
 		WARN_ON_ONCE(cmd->scsi_asc == 0);
diff --git a/drivers/target/target_core_ua.c b/drivers/target/target_core_ua.c
index be25eb8..ba2a13d 100644
--- a/drivers/target/target_core_ua.c
+++ b/drivers/target/target_core_ua.c
@@ -202,10 +202,7 @@ void core_scsi3_ua_release_all(
 	spin_unlock(&deve->ua_lock);
 }
 
-void core_scsi3_ua_for_check_condition(
-	struct se_cmd *cmd,
-	u8 *asc,
-	u8 *ascq)
+int core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *asc, u8 *ascq)
 {
 	struct se_device *dev = cmd->se_dev;
 	struct se_dev_entry *deve;
@@ -215,21 +212,21 @@ void core_scsi3_ua_for_check_condition(
 	int head = 1;
 
 	if (!sess)
-		return;
+		return -EINVAL;
 
 	nacl = sess->se_node_acl;
 	if (!nacl)
-		return;
+		return -EINVAL;
 
 	rcu_read_lock();
 	deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun);
 	if (!deve) {
 		rcu_read_unlock();
-		return;
+		return -EINVAL;
 	}
 	if (!atomic_read(&deve->ua_count)) {
 		rcu_read_unlock();
-		return;
+		return -EINVAL;
 	}
 	/*
 	 * The highest priority Unit Attentions are placed at the head of the
@@ -273,6 +270,8 @@ void core_scsi3_ua_for_check_condition(
 		(dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" :
 		"Releasing", dev->dev_attrib.emulate_ua_intlck_ctrl,
 		cmd->orig_fe_lun, cmd->t_task_cdb[0], *asc, *ascq);
+
+	return 0;
 }
 
 int core_scsi3_ua_clear_for_request_sense(
diff --git a/drivers/target/target_core_ua.h b/drivers/target/target_core_ua.h
index bd6e78b..81a6016 100644
--- a/drivers/target/target_core_ua.h
+++ b/drivers/target/target_core_ua.h
@@ -34,7 +34,7 @@ extern sense_reason_t target_scsi3_ua_check(struct se_cmd *);
 extern int core_scsi3_ua_allocate(struct se_dev_entry *, u8, u8);
 extern void target_ua_allocate_lun(struct se_node_acl *, u32, u8, u8);
 extern void core_scsi3_ua_release_all(struct se_dev_entry *);
-extern void core_scsi3_ua_for_check_condition(struct se_cmd *, u8 *, u8 *);
+extern int core_scsi3_ua_for_check_condition(struct se_cmd *, u8 *, u8 *);
 extern int core_scsi3_ua_clear_for_request_sense(struct se_cmd *,
 						u8 *, u8 *);
 


 
--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux