Skip to contentSkip to conversation

tpm_tis_core: Use common error handling code in tpm_tis_send_data()

PATCH In review SF Markus Elfring 3 participants 5 messages Oct 22, 2017 – Oct 24, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm_tis_core: Use common error handling code in tpm_tis_send_data()

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 11:41:09 +0200

Add a jump target so that a specific error code assignment for timeout conditions will be in the implementation only at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/char/tpm/tpm_tis_core.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_tis_core.c +12 -14
index fdde971bc810..3681f7a74d1b 100644
@@ -262,12 +262,10 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 	status = tpm_tis_status(chip);
 	if ((status & TPM_STS_COMMAND_READY) = 0) {
 		tpm_tis_ready(chip);
-		if (wait_for_tpm_stat
-		    (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
-		     &priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
+		if (wait_for_tpm_stat(chip, TPM_STS_COMMAND_READY,
+				      chip->timeout_b, &priv->int_queue, false)
+		    < 0)
+			goto report_timeout;
 	}
 
 	while (count < len - 1) {
@@ -286,10 +284,9 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 		count += burstcnt;
 
 		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-					&priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
+				      &priv->int_queue, false) < 0)
+			goto report_timeout;
+
 		status = tpm_tis_status(chip);
 		if (!itpm && (status & TPM_STS_DATA_EXPECT) = 0) {
 			rc = -EIO;
@@ -303,10 +300,9 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 		goto out_err;
 
 	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-				&priv->int_queue, false) < 0) {
-		rc = -ETIME;
-		goto out_err;
-	}
+			      &priv->int_queue, false) < 0)
+		goto report_timeout;
+
 	status = tpm_tis_status(chip);
 	if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
 		rc = -EIO;
@@ -315,6 +311,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 
 	return 0;
 
+report_timeout:
+	rc = -ETIME;
 out_err:
 	tpm_tis_ready(chip);
 	return rc;
Signature · 1 line
2.14.2
#1 lore raw

Markus, you should focus on fixing bugs. The original code is fine. These patches are a waste of reviewer time.

regards,
dan carpenter

#2 lore raw
In reply to SF Markus Elfring
Quoted 74 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 22 Oct 2017 11:41:09 +0200

Add a jump target so that a specific error code assignment for timeout conditions will be in the implementation only at the end of this function.

This issue was detected by using the Coccinelle software.

---
 drivers/char/tpm/tpm_tis_core.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_tis_core.c +12 -14
index fdde971bc810..3681f7a74d1b 100644
@@ -262,12 +262,10 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 	status = tpm_tis_status(chip);
 	if ((status & TPM_STS_COMMAND_READY) = 0) {
 		tpm_tis_ready(chip);
-		if (wait_for_tpm_stat
-		    (chip, TPM_STS_COMMAND_READY, chip->timeout_b,
-		     &priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
+		if (wait_for_tpm_stat(chip, TPM_STS_COMMAND_READY,
+				      chip->timeout_b, &priv->int_queue, false)
+		    < 0)
+			goto report_timeout;
 	}
 
 	while (count < len - 1) {
@@ -286,10 +284,9 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 		count += burstcnt;
 
 		if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-					&priv->int_queue, false) < 0) {
-			rc = -ETIME;
-			goto out_err;
-		}
+				      &priv->int_queue, false) < 0)
+			goto report_timeout;
+
 		status = tpm_tis_status(chip);
 		if (!itpm && (status & TPM_STS_DATA_EXPECT) = 0) {
 			rc = -EIO;
@@ -303,10 +300,9 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 		goto out_err;
 
 	if (wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
-				&priv->int_queue, false) < 0) {
-		rc = -ETIME;
-		goto out_err;
-	}
+			      &priv->int_queue, false) < 0)
+		goto report_timeout;
+
 	status = tpm_tis_status(chip);
 	if (!itpm && (status & TPM_STS_DATA_EXPECT) != 0) {
 		rc = -EIO;
@@ -315,6 +311,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 
 	return 0;
 
+report_timeout:
+	rc = -ETIME;
 out_err:
 	tpm_tis_ready(chip);
 	return rc;
Signature · 1 line
2.14.2

NAK. wait_for_tpm_stat() should give that error code.

/Jarkko

#3 lore raw
Quoted 4 lines
Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +0 -0
@@ -315,6 +311,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 
 	return 0;
 
Quoted 10 lines
Quoted 8 lines
drivers/char/tpm/tpm_tis_core.c +2 -0
+report_timeout:
+	rc = -ETIME;
 out_err:
 	tpm_tis_ready(chip);
 	return rc;
Signature · 1 line
2.14.2

NAK. wait_for_tpm_stat() should give that error code.

This is a pity that you reject another bit of code reduction.

Regards,
Markus

#4 lore raw
Quoted 15 lines · SF Markus Elfring
Quoted 4 lines
Quoted 4 lines
drivers/char/tpm/tpm_tis_core.c +0 -0
@@ -315,6 +311,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)
 
 	return 0;
 
Quoted 10 lines
Quoted 8 lines
drivers/char/tpm/tpm_tis_core.c +2 -0
+report_timeout:
+	rc = -ETIME;
 out_err:
 	tpm_tis_ready(chip);
 	return rc;
Signature · 1 line
2.14.2

NAK. wait_for_tpm_stat() should give that error code.

Quoted 4 lines

This is a pity that you reject another bit of code reduction.

Regards,
Markus

It is a pity that you continue doing this constant patch trolling. That is what it is.

/Jarkko.