Skip to contentSkip to conversation

tpm: tpm_crb: relinquish locality on error path.

PATCH In review Tomas Winkler 2 participants 19 messages Apr 7, 2018 – May 11, 2018

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

PATCH 1/1 tpm: tpm_crb: relinquish locality on error path.

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only after granting locality)
---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm_crb.c +7 -3
index 7f78482cd157..34fbc6cb097b 100644
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 
 	/*
 	 * PTT HW bug w/a: wake up the device to access
@@ -520,7 +522,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 
 	return ret;
Signature · 6 lines
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 49 lines · Tomas Winkler

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only after granting

locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm_crb.c +4 -2
index 7f78482cd157..34fbc6cb097b 100644
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device *device, struct
 crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 
 	/*
drivers/char/tpm/tpm_crb.c +1 -1
 	 * PTT HW bug w/a: wake up the device to access
@@ -520,7 +522,7 @@ static int crb_map_io(struct acpi_device *device, struct
 crb_priv *priv,
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
drivers/char/tpm/tpm_crb.c +2 -0
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device *device, struct
 crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 
Quoted 1 line

return ret;

Thanks, please just call it before returning in the error path.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 49 lines · Tomas Winkler
Quoted 30 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality.
This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only after

granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm_crb.c +4 -2
index 7f78482cd157..34fbc6cb097b 100644
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 
 	/*
Quoted 1 line

* PTT HW bug w/a: wake up the device to access @@ -520,7 +522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#centralized-exiting-of-functions

Thanks
Tomas

Quoted 2 lines

/Jarkko

????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????? ???j:+v???w?j?m????????w?????f???h?????????

#3 lore raw
Quoted 56 lines · Tomas
Quoted 56 lines · Tomas Winkler
Quoted 31 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality.
This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only after

granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm_crb.c +4 -2
index 7f78482cd157..34fbc6cb097b 100644
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 2 lines
drivers/char/tpm/tpm_crb.c +0 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7 +522,7

@@

Quoted 19 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +3 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device *device,
 struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

return ret;

Thanks, please just call it before returning in the error path.

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#centralized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 63 lines · Tomas
Quoted 61 lines
Quoted 60 lines · Tomas Winkler
Quoted 32 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only

after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index 7f78482cd157..34fbc6cb097b 100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 2 lines
drivers/char/tpm/tpm_crb.c +0 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7 +522,7

@@

Quoted 19 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +3 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 
Quoted 1 line

return ret;

Thanks, please just call it before returning in the error path.

Quoted 8 lines
Quoted 5 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#centra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Where is the complexitity ? I see it as a standard way of undoing on exit. Tomas

????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????? ???j:+v???w?j?m????????w?????f???h?????????

#5 lore raw
Quoted 70 lines
Quoted 70 lines · Tomas
Quoted 68 lines
Quoted 54 lines · Tomas Winkler
Quoted 32 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only

after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index 7f78482cd157..34fbc6cb097b 100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 3 lines
drivers/char/tpm/tpm_crb.c +1 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#cent
ra
lized-ex
iting-of-functions

Quoted 5 lines
Quoted 2 lines

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????? ???j:+v???w?j?m????????w?????f???h?????????

#6 lore raw
Quoted 73 lines · Tomas
Quoted 73 lines
Quoted 72 lines · Tomas
Quoted 62 lines
Quoted 54 lines · Tomas Winkler
Quoted 32 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only

after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index 7f78482cd157..34fbc6cb097b 100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 3 lines
drivers/char/tpm/tpm_crb.c +1 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 6 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Quoted 6 lines
Quoted 2 lines

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).
* Use just label named out as we have only one exception handler.

I'll move on to testing, and if it it passes, I can do those updates myself.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Tested-by
#7 lore raw
Quoted 88 lines · Jarkko Sakkinen
Quoted 73 lines · Tomas
Quoted 73 lines
Quoted 72 lines · Tomas
Quoted 62 lines
Quoted 54 lines · Tomas Winkler
Quoted 32 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish locality. This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued only

after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index 7f78482cd157..34fbc6cb097b 100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 3 lines
drivers/char/tpm/tpm_crb.c +1 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 6 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Quoted 6 lines
Quoted 2 lines

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

Quoted 7 lines

* Remove the extra newline (the last line addition in the patch).
* Use just label named out as we have only one exception handler.

I'll move on to testing, and if it it passes, I can do those updates myself.

/Jarkko

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
In reply to Jarkko Sakkinen
Quoted 86 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 6 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas
Quoted 5 lines
Quoted 5 lines · Tomas Winkler
Quoted 3 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 69 lines
Quoted 69 lines
Quoted 68 lines
Quoted 58 lines
Quoted 50 lines
Quoted 30 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued

only after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 3 lines
drivers/char/tpm/tpm_crb.c +1 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 7 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#
cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Quoted 6 lines
Quoted 2 lines

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

Quoted 8 lines

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no need for go_idle which is under out label.

Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates myself.

Thanks, I prefer to resend myself.

Tomas

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

#8 lore raw
In reply to Jarkko Sakkinen
Quoted 97 lines · Jarkko Sakkinen
Quoted 7 lines · Tomas
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Tomas
Quoted 5 lines
Quoted 5 lines · Tomas Winkler
Quoted 3 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to

relinquish locality.

Quoted 87 lines
Quoted 70 lines
Quoted 70 lines
Quoted 69 lines
Quoted 59 lines
Quoted 51 lines
Quoted 30 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued

only after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 4 lines
drivers/char/tpm/tpm_crb.c +1 -1
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@
-520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 7 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.htm
l#cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Quoted 6 lines
Quoted 2 lines

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).
* Use just label named out as we have only one exception handler.

Quoted 7 lines
Quoted 4 lines

I'll move on to testing, and if it it passes, I can do those updates myself.

/Jarkko

Thanks
Tomas

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

#10 lore raw
In reply to Winkler, Tomas
Quoted 94 lines · Tomas
Quoted 86 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 6 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas
Quoted 5 lines
Quoted 5 lines · Tomas Winkler
Quoted 3 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 69 lines
Quoted 69 lines
Quoted 68 lines
Quoted 58 lines
Quoted 50 lines
Quoted 30 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be issued

only after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 3 lines
drivers/char/tpm/tpm_crb.c +1 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@ -520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct acpi_device
 *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 7 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.html#
cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Quoted 6 lines
Quoted 2 lines

Where is the complexity ? I see it as a standard way of undoing on exit. Tomas

Jarkko, can you please respond.
Thanks
Tomas

Quoted 8 lines

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).

Quoted 8 lines

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no need for go_idle which is under out label.

Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates myself.

Thanks, I prefer to resend myself.

Tomas

Add my tested-by as it is cosmectic change, thanks.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw
Quoted 105 lines · Tomas
Quoted 79 lines
Quoted 79 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 7 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas Winkler
Quoted 4 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 67 lines
Quoted 51 lines
Quoted 30 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be

issued only after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 4 lines
drivers/char/tpm/tpm_crb.c +1 -1
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@
-520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.h
tml#
cent
ra
lized-ex
iting-of-functions

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Where is the complexity ? I see it as a standard way of undoing on

exit.

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 1 line

Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Quoted 6 lines
Quoted 3 lines

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no

Quoted 8 lines

need for go_idle which is under out label.

Quoted 5 lines
Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates myself.

Thanks, I prefer to resend myself.

Tomas

Add my tested-by as it is cosmectic change, thanks.

What change exactly? I had impression you've accepted the patch as is? Thanks
Tomas

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

#12 lore raw
Quoted 110 lines · Tomas
Quoted 110 lines · Tomas
Quoted 79 lines
Quoted 79 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 7 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas Winkler
Quoted 4 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 67 lines
Quoted 51 lines
Quoted 30 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be

issued only after granting
locality)

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +4 -2
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res, buf-
 >control_address,
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
 

drivers/char/tpm/tpm_crb.c

Quoted 4 lines
drivers/char/tpm/tpm_crb.c +1 -1
 	/*
 	 * PTT HW bug w/a: wake up the device to access @@
-520,7
+522,7

@@

Quoted 15 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
 
 	pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
 	pa_low  = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-style.h
tml#
cent
ra
lized-ex
iting-of-functions

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by doing this.

Where is the complexity ? I see it as a standard way of undoing on

exit.

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 1 line

Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-Fri.

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Quoted 6 lines
Quoted 3 lines

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no

need for go_idle which is under out label.

Quoted 4 lines
Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates myself.

Thanks, I prefer to resend myself.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Tomas

Add my tested-by as it is cosmectic change, thanks.

What change exactly? I had impression you've accepted the patch as is? Thanks
Tomas

Hmm... maybe there is some misunderstandig but I thought you were going to make the updates above yourself and send a revised patch.

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
Quoted 126 lines
Quoted 47 lines
Quoted 47 lines · Tomas
Quoted 43 lines
Quoted 43 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 7 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas Winkler
Quoted 4 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be

issued only after granting
locality)
Signed-off-by: Tomas Winkler
<[email protected]>

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +0 -0
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res,

buf-

Quoted 1 line

control_address,

drivers/char/tpm/tpm_crb.c +4 -2
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c

Quoted 2 lines
drivers/char/tpm/tpm_crb.c +0 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access

@@

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

-520,7
+522,7

@@

Quoted 8 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
Quoted 29 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pa_high = ioread32(&priv->regs_t-

ctrl_cmd_pa_high);

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

pa_low =
ioread32(&priv->regs_t->ctrl_cmd_pa_low);

drivers/char/tpm/tpm_crb.c +0 -0
@@ -565,6 +567,8 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 9 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-sty
le.h
tml#
cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by

doing this.

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Where is the complexity ? I see it as a standard way of undoing on

exit.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-

Fri.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no

need for go_idle which is under out label.

Quoted 2 lines
Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates

myself.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Thanks, I prefer to resend myself.

Tomas

Add my tested-by as it is cosmectic change, thanks.

Quoted 6 lines
Quoted 3 lines

What change exactly? I had impression you've accepted the patch as is? Thanks
Tomas

Hmm... maybe there is some misunderstandig but I thought you were going to make the updates above yourself and send a revised patch.

Probably, if I remember there were to mails going in asynchronous, I've received your tested-by, the second I've sent this answer, so I thought you came to the conclusion that there is nothing to change in the patch yourself.
Frankly I've checked the patch and there are no even extra new lines in my version unless it has scrambled on the way.

Thanks
Tomas

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

#14 lore raw
Quoted 134 lines · Tomas
Quoted 126 lines
Quoted 47 lines
Quoted 47 lines · Tomas
Quoted 43 lines
Quoted 43 lines

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error path.

Quoted 7 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
Quoted 6 lines · Tomas Winkler
Quoted 4 lines

In crb_map_io() function, __crb_request_locality() is called prior to crb_cmd_ready(), but if one of the consecutive function fails the flow bails out instead of trying to relinquish

locality.

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines

This patch adds goto jump to __crb_relinquish_locality() on the error path.

Fixes 888d867df441 (tpm: cmd_ready command can be

issued only after granting
locality)
Signed-off-by: Tomas Winkler
<[email protected]>

---
 drivers/char/tpm/tpm_crb.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644

drivers/char/tpm/tpm_crb.c +0 -0
@@ -511,8 +511,10 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	priv->regs_t = crb_map_res(dev, priv, &io_res,

buf-

Quoted 1 line

control_address,

drivers/char/tpm/tpm_crb.c +4 -2
 				   sizeof(struct crb_regs_tail));
-	if (IS_ERR(priv->regs_t))
-		return PTR_ERR(priv->regs_t);
+	if (IS_ERR(priv->regs_t)) {
+		ret = PTR_ERR(priv->regs_t);
+		goto out_relinquish_locality;
+	}
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/char/tpm/tpm_crb.c

Quoted 2 lines
drivers/char/tpm/tpm_crb.c +0 -0
 	/*
 	 * PTT HW bug w/a: wake up the device to access

@@

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

-520,7
+522,7

@@

Quoted 8 lines

static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,

drivers/char/tpm/tpm_crb.c +1 -1
 	 */
 	ret = crb_cmd_ready(dev, priv);
 	if (ret)
-		return ret;
+		goto out_relinquish_locality;
Quoted 29 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pa_high = ioread32(&priv->regs_t-

ctrl_cmd_pa_high);

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

pa_low =
ioread32(&priv->regs_t->ctrl_cmd_pa_low);

drivers/char/tpm/tpm_crb.c +0 -0
@@ -565,6 +567,8 @@ static int crb_map_io(struct
 acpi_device *device, struct crb_priv *priv,
 
 	crb_go_idle(dev, priv);
 
Quoted 7 lines
Quoted 5 lines
drivers/char/tpm/tpm_crb.c +2 -0
+out_relinquish_locality:
+
 	__crb_relinquish_locality(dev, priv, 0);
 

return ret;

Thanks, please just call it before returning in the error path.

Quoted 9 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding-sty
le.h
tml#
cent
ra
lized-ex
iting-of-functions

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by

doing this.

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Where is the complexity ? I see it as a standard way of undoing on

exit.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-

Fri.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception handler.

Cannot do that, as the bail out is prior to cmd_ready request so there is no

need for go_idle which is under out label.

Quoted 2 lines
Quoted 2 lines

I'll move on to testing, and if it it passes, I can do those updates

myself.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Thanks, I prefer to resend myself.

Tomas

Add my tested-by as it is cosmectic change, thanks.

Quoted 6 lines
Quoted 3 lines

What change exactly? I had impression you've accepted the patch as is? Thanks
Tomas

Hmm... maybe there is some misunderstandig but I thought you were going to make the updates above yourself and send a revised patch.

Quoted 6 lines

Probably, if I remember there were to mails going in asynchronous, I've received your tested-by, the second I've sent this answer, so I thought you came to the conclusion that there is nothing to change in the patch yourself.
Frankly I've checked the patch and there are no even extra new lines in my version unless it has scrambled on the way.

Thanks
Tomas

The only thing was the label name. That is why I asked if I can change it by myself instead of you having to send a follow up patch. Did you send a new one? Did not find it from patchwork.

/Jarkko

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

#15 lore raw
Quoted 152 lines · Tomas
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Tomas
Quoted 1 line
Quoted 1 line

Subject: Re: [PATCH] tpm: tpm_crb: relinquish locality on error

path.

Quoted 69 lines
Quoted 69 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines · Tomas
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas Winkler
Quoted 5 lines

In crb_map_io() function,
__crb_request_locality() is called prior to
crb_cmd_ready(), but if one of the consecutive
function fails the flow bails out instead of
trying to relinquish

locality.

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines

This patch adds goto jump to
__crb_relinquish_locality() on the error path.

Fixes: 888d867df441 (tpm: cmd_ready command can
be issued only after granting
locality)
Signed-off-by: Tomas Winkler
<[email protected]>
---
drivers/char/tpm/tpm_crb.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/tpm_crb.c
b/drivers/char/tpm/tpm_crb.c index
7f78482cd157..34fbc6cb097b
100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -511,8 +511,10 @@ static int
crb_map_io(struct acpi_device *device, struct
crb_priv *priv,

priv->regs_t = crb_map_res(dev, priv, &io_res,
buf-
control_address,
sizeof(struct crb_regs_tail));
- if (IS_ERR(priv->regs_t))
- return PTR_ERR(priv->regs_t);
+ if (IS_ERR(priv->regs_t)) {
+ ret = PTR_ERR(priv->regs_t);
+ goto out_relinquish_locality;
+ }

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

/*
* PTT HW bug w/a: wake up the device to
access

@@

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

-520,7
+522,7

@@

Quoted 8 lines

static int crb_map_io(struct acpi_device
*device, struct crb_priv *priv,
*/
ret = crb_cmd_ready(dev, priv);
if (ret)
- return ret;
+ goto out_relinquish_locality;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pa_high = ioread32(&priv->regs_t-

ctrl_cmd_pa_high);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

pa_low =
ioread32(&priv->regs_t->ctrl_cmd_pa_low);
@@ -565,6 +567,8 @@ static int crb_map_io(struct
acpi_device *device, struct crb_priv *priv,

crb_go_idle(dev, priv);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

+out_relinquish_locality:
+
__crb_relinquish_locality(dev, priv, 0);

return ret;

Thanks, please just call it before returning in the error

path.

Quoted 30 lines
Quoted 30 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

Can you please elaborate why, isn't the centralized exiting of functions preferred kernel coding style?
https://www.kernel.org/doc/html/v4.11/process/coding
-sty
le.h
tml#
cent
ra
lized-ex
iting-of-functions

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

You exit only from one location (not multiple) and not from a nested context. Here you just add more complexity by

doing this.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Where is the complexity ? I see it as a standard way of undoing on

exit.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Tomas

Jarkko, can you please respond.
Thanks
Tomas

I was away for Mon-Wed last week and did not work on TPM for Thu-

Fri.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

My earlier comment was incorrect as there are two locations to exit (not sure how I managed to overlook the patch that way).

Thus, I have only two very minor requets:

* Remove the extra newline (the last line addition in the patch).

Okay

Quoted 1 line

* Use just label named out as we have only one exception

handler.

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Cannot do that, as the bail out is prior to cmd_ready request so there is no

need for go_idle which is under out label.

Quoted 3 lines
Quoted 3 lines

I'll move on to testing, and if it it passes, I can do those updates

myself.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

Thanks, I prefer to resend myself.

Tomas

Add my tested-by as it is cosmectic change, thanks.

What change exactly? I had impression you've accepted the patch as is? Thanks
Tomas

Quoted 6 lines
Quoted 2 lines

Hmm... maybe there is some misunderstandig but I thought you were going to make the updates above yourself and send a revised patch.

Probably, if I remember there were to mails going in asynchronous, I've received your tested-by, the second I've sent this answer, so I thought

you came to the conclusion that there is nothing to change in the patch yourself.

Quoted 1 line

Frankly I've checked the patch and there are no even extra new lines in my

Quoted 8 lines

version unless it has scrambled on the way.

Quoted 3 lines

Thanks
Tomas

The only thing was the label name. That is why I asked if I can change it by myself instead of you having to send a follow up patch. Did you send a new one? Did not find it from patchwork.

There is already one 'out' label in that function, what would you prefer for this new label name? Thanks
Tomas

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

#16 lore raw
Quoted 3 lines · Tomas

There is already one 'out' label in that function, what would you prefer for this new label name? Thanks
Tomas

Aah, of course. My bad that I did not notice it but please just point me if I miss something obvious like that :-) I'll apply the patch today..

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw
Quoted 10 lines · Tomas
Quoted 1 line

There is already one 'out' label in that function, what would you prefer for

this new label name?

Quoted 2 lines

Thanks
Tomas

Aah, of course. My bad that I did not notice it but please just point me if I miss something obvious like that :-) I'll apply the patch today..

Thanks
Tomas

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

#18 lore raw
Quoted 4 lines · Tomas
Quoted 4 lines · Tomas
Quoted 1 line

There is already one 'out' label in that function, what would you prefer for

this new label name?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Thanks
Tomas

Aah, of course. My bad that I did not notice it but please just point me if I miss something obvious like that :-) I'll apply the patch today..

Thanks
Tomas

It's also in next now!

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html