Skip to contentSkip to conversation

tmp/tpm_crb: cleanups

PATCH Applied Tomas Winkler 2 participants 13 messages Sep 11, 2016 – Sep 12, 2016 8 messages not in the archive TPM device driver

lore
Share & tools
lore
#0 lore raw

cover tmp/tpm_crb: cleanups

A set of cleanup patches, w/o any significant functional change.

Tomas Winkler (4):
tmp/tpm_crb: drop include to platform_device tpm/tpm_crb: cache cmd_size register value. tpm/tpm_crb: drop useless cpu_to_le32 when writing to registers tpm/tpm_crb: fix the over 80 characters checkpatch warring

 drivers/char/tpm/tpm_crb.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
Signature · 4 lines
2.7.4


------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): 1473635035-14443-1-git-send-email-tomas.winkler-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/4 tmp/tpm_crb: drop include to platform_device

The platform device is not used in this driver, drop the include to linux/platform_device.h

---
 drivers/char/tpm/tpm_crb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_crb.c +0 -1
index 82a3ccd52a3a..6a4b32599869 100644
@@ -19,7 +19,6 @@
 #include <linux/highmem.h>
 #include <linux/rculist.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
 #include "tpm.h"
 
 #define ACPI_SIG_TPM2 "TPM2"
Signature · 4 lines
2.7.4


------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): 1473635035-14443-2-git-send-email-tomas.winkler-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 1/4] tmp/tpm_crb: drop include to platform_device

Quoted 4 lines · Tomas Winkler

The platform device is not used in this driver, drop the include to linux/platform_device.h

/Jarkko

Quoted 19 lines
---
 drivers/char/tpm/tpm_crb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_crb.c +0 -1
index 82a3ccd52a3a..6a4b32599869 100644
@@ -19,7 +19,6 @@
 #include <linux/highmem.h>
 #include <linux/rculist.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
 #include "tpm.h"
 
 #define ACPI_SIG_TPM2 "TPM2"
Signature · 1 line
2.7.4

------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 1/4] tmp/tpm_crb: drop include to platform_device

Quoted 7 lines · Jarkko Sakkinen
Quoted 4 lines · Tomas Winkler

The platform device is not used in this driver, drop the include to linux/platform_device.h

Applied.

/Jarkko

Quoted 18 lines

/Jarkko

Quoted 15 lines
---
 drivers/char/tpm/tpm_crb.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_crb.c +0 -1
index 82a3ccd52a3a..6a4b32599869 100644
@@ -19,7 +19,6 @@
 #include <linux/highmem.h>
 #include <linux/rculist.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
 #include "tpm.h"
 
Quoted 4 lines
Quoted 4 lines
drivers/char/tpm/tpm_crb.c +0 -0
 #define ACPI_SIG_TPM2 "TPM2"
Signature · 1 line
2.7.4

------------------------------------------------------------------------------

#7 lore raw

PATCH v2 2/4 tpm/tpm_crb: cache cmd_size register value.

In reply to a message not in the archive

Instead of expensive register access on retrieving cmd_size on each send, save the value during initialization in the private context. The value doesn't change.

---
V2: rebased

 drivers/char/tpm/tpm_crb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_crb.c +5 -5
index 6a4b32599869..f066810bfc03 100644
@@ -80,6 +80,7 @@ struct crb_priv {
 	struct crb_control_area __iomem *cca;
 	u8 __iomem *cmd;
 	u8 __iomem *rsp;
+	u32 cmd_size;
 };
 
 static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume);
@@ -141,11 +142,9 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
 	int rc = 0;
 
-	if (len > ioread32(&priv->cca->cmd_size)) {
-		dev_err(&chip->dev,
-			"invalid command count value %x %zx\n",
-			(unsigned int) len,
-			(size_t) ioread32(&priv->cca->cmd_size));
+	if (len > priv->cmd_size) {
+		dev_err(&chip->dev, "invalid command count value %zd %d\n",
+			len, priv->cmd_size);
 		return -E2BIG;
 	}
 
@@ -301,6 +300,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 		dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical");
 		return -EINVAL;
 	}
+	priv->cmd_size = cmd_size;
 
 	priv->rsp = priv->cmd;
 	return 0;
Signature · 4 lines
2.7.4


------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): 1473635035-14443-3-git-send-email-tomas.winkler-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#9 lore raw

Re: [PATCH 2/4 v2] tpm/tpm_crb: cache cmd_size register value.

Quoted 7 lines · Tomas Winkler

Instead of expensive register access on retrieving cmd_size on each send, save the value during initialization in the private context. The value doesn't change.

$ git am -3 ~/Downloads/2-4-v2-tpm-tpm_crb-cache-cmd_size-register-value..patch
Applying: tpm/tpm_crb: cache cmd_size register value.
fatal: sha1 information is lacking or useless (drivers/char/tpm/tpm_crb.c).
error: could not build fake ancestor
Patch failed at 0001 tpm/tpm_crb: cache cmd_size register value.
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
VCS_INFO_get_data_git:225: no such file or directory: .git/rebase-apply/msg-clean                                                                           

/Jarkko

Quoted 45 lines

---
V2: rebased

 drivers/char/tpm/tpm_crb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_crb.c +5 -5
index 6a4b32599869..f066810bfc03 100644
@@ -80,6 +80,7 @@ struct crb_priv {
 	struct crb_control_area __iomem *cca;
 	u8 __iomem *cmd;
 	u8 __iomem *rsp;
+	u32 cmd_size;
 };
 
 static SIMPLE_DEV_PM_OPS(crb_pm, tpm_pm_suspend, tpm_pm_resume);
@@ -141,11 +142,9 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
 	int rc = 0;
 
-	if (len > ioread32(&priv->cca->cmd_size)) {
-		dev_err(&chip->dev,
-			"invalid command count value %x %zx\n",
-			(unsigned int) len,
-			(size_t) ioread32(&priv->cca->cmd_size));
+	if (len > priv->cmd_size) {
+		dev_err(&chip->dev, "invalid command count value %zd %d\n",
+			len, priv->cmd_size);
 		return -E2BIG;
 	}
 
@@ -301,6 +300,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 		dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical");
 		return -EINVAL;
 	}
+	priv->cmd_size = cmd_size;
 
 	priv->rsp = priv->cmd;
 	return 0;
Signature · 1 line
2.7.4

------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: [PATCH 2/4 v2] tpm/tpm_crb: cache cmd_size register value.

Quoted 9 lines · Jarkko Sakkinen
Quoted 7 lines · Tomas Winkler

Instead of expensive register access on retrieving cmd_size on each send, save the value during initialization in the private context. The value doesn't change.

Quoted 10 lines
$ git am -3 ~/Downloads/2-4-v2-tpm-tpm_crb-cache-cmd_size-register-value..patch
Applying: tpm/tpm_crb: cache cmd_size register value.
fatal: sha1 information is lacking or useless (drivers/char/tpm/tpm_crb.c).
error: could not build fake ancestor
Patch failed at 0001 tpm/tpm_crb: cache cmd_size register value.
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
VCS_INFO_get_data_git:225: no such file or directory: .git/rebase-apply/msg-clean                                                                           

I did this:

patch -p1 < ~/Downloads/2-4-v2-tpm-tpm_crb-cache-cmd_size-register-value..patch git commit -a -s --author="Tomas Winkler <[email protected]>"

It's now pushed. Could you check that it looks OK for you so that I can include this to the next pull request?

/Jarkko

------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [PATCH 2/4 v2] tpm/tpm_crb: cache cmd_size register value.

Quoted 24 lines · Jarkko Sakkinen
Quoted 9 lines · Tomas Winkler
Quoted 7 lines

Instead of expensive register access on retrieving cmd_size on each send, save the value during initialization in the private context. The value doesn't change.

Quoted 11 lines
$ git am -3
~/Downloads/2-4-v2-tpm-tpm_crb-cache-cmd_size-register-value..patch
Applying: tpm/tpm_crb: cache cmd_size register value.
fatal: sha1 information is lacking or useless (drivers/char/tpm/tpm_crb.c).
error: could not build fake ancestor
Patch failed at 0001 tpm/tpm_crb: cache cmd_size register value.
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
VCS_INFO_get_data_git:225: no such file or directory: .git/rebase-

apply/msg-clean

Quoted 8 lines

I did this:

patch -p1 < ~/Downloads/2-4-v2-tpm-tpm_crb-cache-cmd_size-register-
value..patch
git commit -a -s --author="Tomas Winkler <[email protected]>"

It's now pushed. Could you check that it looks OK for you so that I can include this to the next pull request?

Looks great.

Thanks
Tomas

------------------------------------------------------------------------------

#14 lore raw

PATCH 3/4 tpm/tpm_crb: drop useless cpu_to_le32 when writing to registers

In reply to a message not in the archive

Don't apply endianity conversion when writing to the registers this is already handled by the system.

---
 drivers/char/tpm/tpm_crb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_crb.c +2 -2
index f066810bfc03..0c9989d0106e 100644
@@ -154,7 +154,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	wmb();
 
 	if (priv->flags & CRB_FL_CRB_START)
-		iowrite32(cpu_to_le32(CRB_START_INVOKE), &priv->cca->start);
+		iowrite32(CRB_START_INVOKE, &priv->cca->start);
 
 	if (priv->flags & CRB_FL_ACPI_START)
 		rc = crb_do_acpi_start(chip);
@@ -166,7 +166,7 @@ static void crb_cancel(struct tpm_chip *chip)
 {
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
 
-	iowrite32(cpu_to_le32(CRB_CANCEL_INVOKE), &priv->cca->cancel);
+	iowrite32(CRB_CANCEL_INVOKE, &priv->cca->cancel);
 
 	/* Make sure that cmd is populated before issuing cancel. */
 	wmb();
Signature · 4 lines
2.7.4


------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): 1473635035-14443-4-git-send-email-tomas.winkler-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

Reviewed-by
#16 lore raw

Re: [PATCH 3/4] tpm/tpm_crb: drop useless cpu_to_le32 when writing to registers

Quoted 4 lines · Tomas Winkler

Don't apply endianity conversion when writing to the registers this is already handled by the system.

/Jarkko

Quoted 29 lines
---
 drivers/char/tpm/tpm_crb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_crb.c +2 -2
index f066810bfc03..0c9989d0106e 100644
@@ -154,7 +154,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	wmb();
 
 	if (priv->flags & CRB_FL_CRB_START)
-		iowrite32(cpu_to_le32(CRB_START_INVOKE), &priv->cca->start);
+		iowrite32(CRB_START_INVOKE, &priv->cca->start);
 
 	if (priv->flags & CRB_FL_ACPI_START)
 		rc = crb_do_acpi_start(chip);
@@ -166,7 +166,7 @@ static void crb_cancel(struct tpm_chip *chip)
 {
 	struct crb_priv *priv = dev_get_drvdata(&chip->dev);
 
-	iowrite32(cpu_to_le32(CRB_CANCEL_INVOKE), &priv->cca->cancel);
+	iowrite32(CRB_CANCEL_INVOKE, &priv->cca->cancel);
 
 	/* Make sure that cmd is populated before issuing cancel. */
 	wmb();
Signature · 1 line
2.7.4

------------------------------------------------------------------------------

#17 lore raw

PATCH 4/4 tpm/tpm_crb: fix the over 80 characters checkpatch warring

In reply to a message not in the archive

Because of the line break in the debug print the chackpatch is not silent on 80 characters limitation.

The easiest fix is to straighten the lines, it's also more readable.

WARNING: line over 80 characters
+ FW_BUG "TPM2 ACPI table does not define a memory
resource\n");

---
 drivers/char/tpm/tpm_crb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/char/tpm/tpm_crb.c +1 -2
index 0c9989d0106e..6e9d1bca712f 100644
@@ -263,8 +263,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 	acpi_dev_free_resource_list(&resources);
 
 	if (resource_type(&io_res) != IORESOURCE_MEM) {
-		dev_err(dev,
-			FW_BUG "TPM2 ACPI table does not define a memory resource\n");
+		dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n");
 		return -EINVAL;
 	}
 
Signature · 4 lines
2.7.4


------------------------------------------------------------------------------

A message that is not in the archive (sent off-list or not yet received): 1473635035-14443-5-git-send-email-tomas.winkler-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

Reviewed-by
#19 lore raw

Re: [PATCH 4/4] tpm/tpm_crb: fix the over 80 characters checkpatch warring

Quoted 10 lines · Tomas Winkler

Because of the line break in the debug print the chackpatch is not silent on 80 characters limitation.

The easiest fix is to straighten the lines, it's also more readable.

WARNING: line over 80 characters
+ FW_BUG "TPM2 ACPI table does not define a memory
resource\n");

/Jarkko

Quoted 21 lines
---
 drivers/char/tpm/tpm_crb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/char/tpm/tpm_crb.c +1 -2
index 0c9989d0106e..6e9d1bca712f 100644
@@ -263,8 +263,7 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
 	acpi_dev_free_resource_list(&resources);
 
 	if (resource_type(&io_res) != IORESOURCE_MEM) {
-		dev_err(dev,
-			FW_BUG "TPM2 ACPI table does not define a memory resource\n");
+		dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.7.4

------------------------------------------------------------------------------

#20 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tomas Winkler

A set of cleanup patches, w/o any significant functional change.

Tomas Winkler (4):
tmp/tpm_crb: drop include to platform_device tpm/tpm_crb: cache cmd_size register value. tpm/tpm_crb: drop useless cpu_to_le32 when writing to registers tpm/tpm_crb: fix the over 80 characters checkpatch warring

 drivers/char/tpm/tpm_crb.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

I applied all of these.

/Jarkko

------------------------------------------------------------------------------