tpm: ibmvtpm: simplify crq initialization and document crq format
Subsystems (2)
PATCH 1/1 tpm: ibmvtpm: simplify crq initialization and document crq format
The crq is passed in registers and is the same on BE and LE hosts. However, current implementation allocates a structure on-stack to represent the crq, initializes the members swapping them to BE, and loads the structure swapping it from BE. This is pointless and causes GCC warnings about ununitialized members. Get rid of the structure and the warnings.
---
v2
fix typos and spelling in comments
--- drivers/char/tpm/tpm_ibmvtpm.c | 96 ++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 36 deletions(-)
drivers/char/tpm/tpm_ibmvtpm.c +60 -36
@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = {MODULE_DEVICE_TABLE (vio, tpm_ibmvtpm_device_table);/** +* +* ibmvtpm_send_crq_word - Send a CRQ request +* @vdev: vio device struct +* @w1: pre-constructed first word of tpm crq (second word is reserved) +* +* Return: +* 0 - Success +* Non-zero - Failure +*/ +static int ibmvtpm_send_crq_word (struct vio_dev *vdev,u64 w1) +{ +return plpar_hcall_norets (H_SEND_CRQ , vdev->unit_address, w1,0 ); +} + +/** +* * ibmvtpm_send_crq - Send a CRQ request * * @vdev: vio device struct -* @w1: first word -* @w2: second word +* @valid: Valid field +* @msg: Type field +* @len: Length field +* @data: Data field +* +* The ibmvtpm crq is defined as follows: +* +* Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 +* ----------------------------------------------------------------------- +* Word0 | Valid | Type | Length | Data +* ----------------------------------------------------------------------- +* Word1 | Reserved +* ----------------------------------------------------------------------- +* +* Which matches the following structure (on bigendian host): +* +* struct ibmvtpm_crq { +* u8 valid; +* u8 msg; +* __be16 len; +* __be32 data; +* __be64 reserved; +* } __attribute__((packed, aligned(8))); +* +* However, the value is passed in a register so just compute the numeric value +* to load into the register avoiding byteswap altogether. Endian only affects +* memory loads and stores - registers are internally represented the same. * * Return: -* 0 -Sucess +* 0 (H_SUCCESS) - Success * Non-zero - Failure */ -static int ibmvtpm_send_crq (struct vio_dev *vdev,u64 w1,u64 w2) +static int ibmvtpm_send_crq (struct vio_dev *vdev, +u8 valid,u8 msg,u16 len,u32 data) { -return plpar_hcall_norets (H_SEND_CRQ , vdev->unit_address, w1, w2); +u64 w1 = ((u64 )valid <<56 ) | ((u64 )msg <<48 ) | ((u64 )len <<32 ) | + (u64 )data; +return ibmvtpm_send_crq_word (vdev, w1); }/**
@@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)static int tpm_ibmvtpm_send (struct tpm_chip *chip,u8 *buf,size_t count) {struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -__be64 *word = (__be64 *)&crq;int rc, sig;if (!ibmvtpm->rtce_buf) {
@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)spin_lock (&ibmvtpm->rtce_lock); ibmvtpm->res_len =0 ;memcpy ((void *)ibmvtpm->rtce_buf, (void *)buf, count); - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_TPM_COMMAND ; - crq.len =cpu_to_be16 (count); - crq.data =cpu_to_be32 (ibmvtpm->rtce_dma_handle);/* * set the processing flag before the Hcall, since we may get the
@@ -148,8 +186,9 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)*/ ibmvtpm->tpm_processing_cmd = true; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]), -be64_to_cpu (word[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_TPM_COMMAND , + count, ibmvtpm->rtce_dma_handle);if (rc !=H_SUCCESS ) {dev_err (ibmvtpm->dev,"tpm_ibmvtpm_send failed rc=%d\n" , rc); rc =0 ;
@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)*/ static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev *ibmvtpm) { -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_RTCE_BUFFER_SIZE ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_RTCE_BUFFER_SIZE ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_get_rtce_size failed rc=%d\n" , rc);
@@ -210,15 +244,10 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)*/ static int ibmvtpm_crq_get_version (struct ibmvtpm_dev *ibmvtpm) { -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_VERSION ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_VERSION ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_get_version failed rc=%d\n" , rc);
@@ -238,7 +267,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) {int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_COMP_CMD );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_send_init_complete failed rc=%d\n" , rc);
@@ -258,7 +287,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) {int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_CMD );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_send_init failed rc=%d\n" , rc);
@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev);struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc =0 ; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_PREPARE_TO_SUSPEND ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_PREPARE_TO_SUSPEND ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"tpm_ibmvtpm_suspend failed rc=%d\n" , rc);
Signature · 6 lines
2.10.2 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot
ping?
Quoted 204 lines · On Fri, 24 Feb 2017 20:35:16 +0100 Michal Suchanek <[email protected]> wrote:
The crq is passed in registers and is the same on BE and LE hosts. However, current implementation allocates a structure on-stack to represent the crq, initializes the members swapping them to BE, and loads the structure swapping it from BE. This is pointless and causes GCC warnings about ununitialized members. Get rid of the structure and the warnings.
Signed-off-by Michal Suchanek <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>---
v2fix typos and spelling in comments
--- drivers/char/tpm/tpm_ibmvtpm.c | 96++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 36 deletions(-)
(quoted diff) +0
-0
b/drivers/char/tpm/tpm_ibmvtpm.cindex1b9d61ffe991..89027339d55f100644 ---a/drivers/char/tpm/tpm_ibmvtpm.c
+++b/drivers/char/tpm/tpm_ibmvtpm.cdrivers/char/tpm/tpm_ibmvtpm.c +23
-2@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);/** +* +* ibmvtpm_send_crq_word - Send a CRQ request +* @vdev: vio device struct +* @w1: pre-constructed first word of tpm crq (second word is reserved) +* +* Return: +* 0 - Success +* Non-zero - Failure +*/ +static int ibmvtpm_send_crq_word (struct vio_dev *vdev,u64 w1) +{ +return plpar_hcall_norets (H_SEND_CRQ , vdev->unit_address, w1, 0); +} + +/** +* * ibmvtpm_send_crq - Send a CRQ request * * @vdev: vio device struct -* @w1: first word -* @w2: second word +* @valid: Valid field +* @msg: Type field +* @len: Length field +* @data: Data field +* +* The ibmvtpm crq is defined as follows: +* +* Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
+ *
-----------------------------------------------------------------------
+ * Word0 | Valid | Type | Length | Data
+ *
-----------------------------------------------------------------------
+ * Word1 | Reserved
+ *
-----------------------------------------------------------------------
+ *
+ * Which matches the following structure (on bigendian host):
+ *
+ * structibmvtpm_crq{+ * u8 valid; + * u8 msg; + * __be16 len; + * __be32 data; + * __be64 reserved;+ * }
__attribute__((packed, aligned(8)));
+ *
+ * However, the value is passed in a register so just compute the numeric value
+ * to load into the register avoiding byteswap altogether. Endian only affects
+ * memory loads and stores - registers are internally represented the same. *
* Return:
- * 0 -Sucess
+ * 0 (H_SUCCESS) - Success
* Non-zero - Failure
*/drivers/char/tpm/tpm_ibmvtpm.c +2
-2-static int ibmvtpm_send_crq (struct vio_dev *vdev,u64 w1,u64 w2) +static int ibmvtpm_send_crq (struct vio_dev *vdev, +u8 valid,u8 msg,u16 len,u32 data) { - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,w1, w2);
(quoted diff) +1
-0+ u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len<< 32) |
drivers/char/tpm/tpm_ibmvtpm.c +2
-6+ (u64 )data; +return ibmvtpm_send_crq_word (vdev, w1); }/** @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(structtpm_chip *chip,u8 *buf,size_t count) {struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -__be64 *word = (__be64 *)&crq;int rc, sig;if (!ibmvtpm->rtce_buf) {@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock); ibmvtpm->res_len =0 ;memcpy ((void *)ibmvtpm->rtce_buf, (void *)buf, count); - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_TPM_COMMAND ; - crq.len =cpu_to_be16 (count); - crq.data =cpu_to_be32 (ibmvtpm->rtce_dma_handle);/* * set the processing flag before the Hcall, since we may get the @@ -148,8 +186,9 @@ static int
tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)*/drivers/char/tpm/tpm_ibmvtpm.c +3
-2ibmvtpm->tpm_processing_cmd = true; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]), -be64_to_cpu (word[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_TPM_COMMAND , + count, ibmvtpm->rtce_dma_handle);if (rc !=H_SUCCESS ) { dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failedrc=%d\n", rc); rc = 0;
drivers/char/tpm/tpm_ibmvtpm.c +2
-7@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip*chip) */ static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev *ibmvtpm) { -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_RTCE_BUFFER_SIZE ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_RTCE_BUFFER_SIZE ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_rtce_size failed rc=%d\n",rc); @@ -210,15 +244,10 @@ static int
ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)*/
static intibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +2
-7-struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_VERSION ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_VERSION ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_version failed rc=%d\n",rc); @@ -238,7 +267,7 @@ static int
ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +1
-1int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_COMP_CMD );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_send_init_complete failedrc=%d\n", rc); @@ -258,7 +287,7 @@ static int
ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +3
-8int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_CMD );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_send_init failed rc=%d\n" , rc);@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev);struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc =0 ; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_PREPARE_TO_SUSPEND ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_PREPARE_TO_SUSPEND ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"tpm_ibmvtpm_suspend failed rc=%d\n" , rc);
Ugh. I'll apply this. My apologies.
/Jarkko
Quoted 210 lines · msuchanek
ping?
Quoted 204 lines · On Fri, 24 Feb 2017 20:35:16 +0100 Michal Suchanek <[email protected]> wrote:
The crq is passed in registers and is the same on BE and LE hosts. However, current implementation allocates a structure on-stack to represent the crq, initializes the members swapping them to BE, and loads the structure swapping it from BE. This is pointless and causes GCC warnings about ununitialized members. Get rid of the structure and the warnings.
Signed-off-by Michal Suchanek <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>---
v2fix typos and spelling in comments
--- drivers/char/tpm/tpm_ibmvtpm.c | 96++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 36 deletions(-)
(quoted diff) +0
-0
b/drivers/char/tpm/tpm_ibmvtpm.cindex1b9d61ffe991..89027339d55f100644 ---a/drivers/char/tpm/tpm_ibmvtpm.c
+++b/drivers/char/tpm/tpm_ibmvtpm.cdrivers/char/tpm/tpm_ibmvtpm.c +23
-2@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);/** +* +* ibmvtpm_send_crq_word - Send a CRQ request +* @vdev: vio device struct +* @w1: pre-constructed first word of tpm crq (second word is reserved) +* +* Return: +* 0 - Success +* Non-zero - Failure +*/ +static int ibmvtpm_send_crq_word (struct vio_dev *vdev,u64 w1) +{ +return plpar_hcall_norets (H_SEND_CRQ , vdev->unit_address, w1, 0); +} + +/** +* * ibmvtpm_send_crq - Send a CRQ request * * @vdev: vio device struct -* @w1: first word -* @w2: second word +* @valid: Valid field +* @msg: Type field +* @len: Length field +* @data: Data field +* +* The ibmvtpm crq is defined as follows: +* +* Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
+ *
-----------------------------------------------------------------------
+ * Word0 | Valid | Type | Length | Data
+ *
-----------------------------------------------------------------------
+ * Word1 | Reserved
+ *
-----------------------------------------------------------------------
+ *
+ * Which matches the following structure (on bigendian host):
+ *
+ * structibmvtpm_crq{+ * u8 valid; + * u8 msg; + * __be16 len; + * __be32 data; + * __be64 reserved;+ * }
__attribute__((packed, aligned(8)));
+ *
+ * However, the value is passed in a register so just compute the numeric value
+ * to load into the register avoiding byteswap altogether. Endian only affects
+ * memory loads and stores - registers are internally represented the same. *
* Return:
- * 0 -Sucess
+ * 0 (H_SUCCESS) - Success
* Non-zero - Failure
*/drivers/char/tpm/tpm_ibmvtpm.c +2
-2-static int ibmvtpm_send_crq (struct vio_dev *vdev,u64 w1,u64 w2) +static int ibmvtpm_send_crq (struct vio_dev *vdev, +u8 valid,u8 msg,u16 len,u32 data) { - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,w1, w2);
(quoted diff) +1
-0+ u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len<< 32) |
drivers/char/tpm/tpm_ibmvtpm.c +2
-6+ (u64 )data; +return ibmvtpm_send_crq_word (vdev, w1); }/** @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(structtpm_chip *chip,u8 *buf,size_t count) {struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -__be64 *word = (__be64 *)&crq;int rc, sig;if (!ibmvtpm->rtce_buf) {@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock); ibmvtpm->res_len =0 ;memcpy ((void *)ibmvtpm->rtce_buf, (void *)buf, count); - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_TPM_COMMAND ; - crq.len =cpu_to_be16 (count); - crq.data =cpu_to_be32 (ibmvtpm->rtce_dma_handle);/* * set the processing flag before the Hcall, since we may get the @@ -148,8 +186,9 @@ static int
tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)*/drivers/char/tpm/tpm_ibmvtpm.c +3
-2ibmvtpm->tpm_processing_cmd = true; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]), -be64_to_cpu (word[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_TPM_COMMAND , + count, ibmvtpm->rtce_dma_handle);if (rc !=H_SUCCESS ) { dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failedrc=%d\n", rc); rc = 0;
drivers/char/tpm/tpm_ibmvtpm.c +2
-7@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip*chip) */ static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev *ibmvtpm) { -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_RTCE_BUFFER_SIZE ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_RTCE_BUFFER_SIZE ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_rtce_size failed rc=%d\n",rc); @@ -210,15 +244,10 @@ static int
ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)*/
static intibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +2
-7-struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_VERSION ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_VERSION ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_version failed rc=%d\n",rc); @@ -238,7 +267,7 @@ static int
ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +1
-1int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_COMP_CMD );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_send_init_complete failedrc=%d\n", rc); @@ -258,7 +287,7 @@ static int
ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +3
-8int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_CMD );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_send_init failed rc=%d\n" , rc);@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev);struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc =0 ; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_PREPARE_TO_SUSPEND ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_PREPARE_TO_SUSPEND ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"tpm_ibmvtpm_suspend failed rc=%d\n" , rc);
Jarkko Sakkinen
AppliedApplied. I'll put this to 4.14 PR.
/Jarkko
Quoted 215 lines · Jarkko Sakkinen
Ugh. I'll apply this. My apologies.
/Jarkko
Quoted 210 lines · msuchanek
ping?
Quoted 204 lines · On Fri, 24 Feb 2017 20:35:16 +0100 Michal Suchanek <[email protected]> wrote:
The crq is passed in registers and is the same on BE and LE hosts. However, current implementation allocates a structure on-stack to represent the crq, initializes the members swapping them to BE, and loads the structure swapping it from BE. This is pointless and causes GCC warnings about ununitialized members. Get rid of the structure and the warnings.
Signed-off-by Michal Suchanek <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>---
v2fix typos and spelling in comments
--- drivers/char/tpm/tpm_ibmvtpm.c | 96++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 36 deletions(-)
(quoted diff) +0
-0
b/drivers/char/tpm/tpm_ibmvtpm.cindex1b9d61ffe991..89027339d55f100644 ---a/drivers/char/tpm/tpm_ibmvtpm.c
+++b/drivers/char/tpm/tpm_ibmvtpm.cdrivers/char/tpm/tpm_ibmvtpm.c +23
-2@@ -39,19 +39,63 @@ static struct vio_device_id tpm_ibmvtpm_device_table[] = { MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);/** +* +* ibmvtpm_send_crq_word - Send a CRQ request +* @vdev: vio device struct +* @w1: pre-constructed first word of tpm crq (second word is reserved) +* +* Return: +* 0 - Success +* Non-zero - Failure +*/ +static int ibmvtpm_send_crq_word (struct vio_dev *vdev,u64 w1) +{ +return plpar_hcall_norets (H_SEND_CRQ , vdev->unit_address, w1, 0); +} + +/** +* * ibmvtpm_send_crq - Send a CRQ request * * @vdev: vio device struct -* @w1: first word -* @w2: second word +* @valid: Valid field +* @msg: Type field +* @len: Length field +* @data: Data field +* +* The ibmvtpm crq is defined as follows: +* +* Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
+ *
-----------------------------------------------------------------------
+ * Word0 | Valid | Type | Length | Data
+ *
-----------------------------------------------------------------------
+ * Word1 | Reserved
+ *
-----------------------------------------------------------------------
+ *
+ * Which matches the following structure (on bigendian host):
+ *
+ * structibmvtpm_crq{+ * u8 valid; + * u8 msg; + * __be16 len; + * __be32 data; + * __be64 reserved;+ * }
__attribute__((packed, aligned(8)));
+ *
+ * However, the value is passed in a register so just compute the numeric value
+ * to load into the register avoiding byteswap altogether. Endian only affects
+ * memory loads and stores - registers are internally represented the same. *
* Return:
- * 0 -Sucess
+ * 0 (H_SUCCESS) - Success
* Non-zero - Failure
*/drivers/char/tpm/tpm_ibmvtpm.c +2
-2-static int ibmvtpm_send_crq (struct vio_dev *vdev,u64 w1,u64 w2) +static int ibmvtpm_send_crq (struct vio_dev *vdev, +u8 valid,u8 msg,u16 len,u32 data) { - return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address,w1, w2);
(quoted diff) +1
-0+ u64 w1 = ((u64)valid << 56) | ((u64)msg << 48) | ((u64)len<< 32) |
drivers/char/tpm/tpm_ibmvtpm.c +2
-6+ (u64 )data; +return ibmvtpm_send_crq_word (vdev, w1); }/** @@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count) static int tpm_ibmvtpm_send(structtpm_chip *chip,u8 *buf,size_t count) {struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -__be64 *word = (__be64 *)&crq;int rc, sig;if (!ibmvtpm->rtce_buf) {@@ -137,10 +179,6 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) spin_lock(&ibmvtpm->rtce_lock); ibmvtpm->res_len =0 ;memcpy ((void *)ibmvtpm->rtce_buf, (void *)buf, count); - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_TPM_COMMAND ; - crq.len =cpu_to_be16 (count); - crq.data =cpu_to_be32 (ibmvtpm->rtce_dma_handle);/* * set the processing flag before the Hcall, since we may get the @@ -148,8 +186,9 @@ static int
tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)*/drivers/char/tpm/tpm_ibmvtpm.c +3
-2ibmvtpm->tpm_processing_cmd = true; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]), -be64_to_cpu (word[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_TPM_COMMAND , + count, ibmvtpm->rtce_dma_handle);if (rc !=H_SUCCESS ) { dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failedrc=%d\n", rc); rc = 0;
drivers/char/tpm/tpm_ibmvtpm.c +2
-7@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip*chip) */ static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev *ibmvtpm) { -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_RTCE_BUFFER_SIZE ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_RTCE_BUFFER_SIZE ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_rtce_size failed rc=%d\n",rc); @@ -210,15 +244,10 @@ static int
ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)*/
static intibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +2
-7-struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_GET_VERSION ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_GET_VERSION ,0 ,0 );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_get_version failed rc=%d\n",rc); @@ -238,7 +267,7 @@ static int
ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +1
-1int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_COMP_CMD );if (rc !=H_SUCCESS ) dev_err(ibmvtpm->dev, "ibmvtpm_crq_send_init_complete failedrc=%d\n", rc); @@ -258,7 +287,7 @@ static int
ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm){drivers/char/tpm/tpm_ibmvtpm.c +3
-8int rc; - rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 ); + rc =ibmvtpm_send_crq_word (ibmvtpm->vdev,INIT_CRQ_CMD );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"ibmvtpm_crq_send_init failed rc=%d\n" , rc);@@ -336,15 +365,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev) {struct tpm_chip *chip =dev_get_drvdata (dev);struct ibmvtpm_dev *ibmvtpm =dev_get_drvdata (&chip->dev); -struct ibmvtpm_crq crq; -u64 *buf = (u64 *) &crq;int rc =0 ; - crq.valid = (u8 )IBMVTPM_VALID_CMD ; - crq.msg = (u8 )VTPM_PREPARE_TO_SUSPEND ; - - rc =ibmvtpm_send_crq (ibmvtpm->vdev,cpu_to_be64 (buf[0 ]), -cpu_to_be64 (buf[1 ])); + rc =ibmvtpm_send_crq (ibmvtpm->vdev, +IBMVTPM_VALID_CMD ,VTPM_PREPARE_TO_SUSPEND ,0 ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev,"tpm_ibmvtpm_suspend failed rc=%d\n" , rc);
cover tpm: tpm_ibmvtpm: - style fix
Fix styling WARNINGs and Errors of tpm_ibmvtpm.c driver by using checkpatch.pl
SZ Lin (5):
Fix packed and aligned attribute warnings.
Fix "ERROR: code indent should use tabs where possible" Fix 'void function return statements are not generally useful' warning Remove unneccessary 'out of memory' message
Use __func__ instead of function name
drivers/char/tpm/tpm_ibmvtpm.c | 23 +++++++++-------------- drivers/char/tpm/tpm_ibmvtpm.h | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-)
--
2.13.3
PATCH 1/5 Fix packed and aligned attribute warnings.
WARNING: __packed is preferred over __attribute__((packed)) +} __attribute__((packed, aligned(8)));
WARNING: __aligned(size) is preferred over __attribute__((aligned(size))) +} __attribute__((packed, aligned(8)));
--- drivers/char/tpm/tpm_ibmvtpm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_ibmvtpm.h +1 -1
@@ -25,7 +25,7 @@ struct ibmvtpm_crq {__be16 len;__be32 data;__be64 reserved; -} __attribute__((packed, aligned(8))); +} __packed__aligned(8) ;struct ibmvtpm_crq_queue {struct ibmvtpm_crq *crq_addr;
Signature · 1 line
2.13.3
RE: [PATCH 1/5] Fix packed and aligned attribute warnings.
From: SZ Lin
Quoted 1 line
Sent: 29 July 2017 08:24
...
drivers/char/tpm/tpm_ibmvtpm.h struct ibmvtpm_crq { · line 28
Quoted 10 lines
drivers/char/tpm/tpm_ibmvtpm.h +1
-1@@ -25,7 +25,7 @@ struct ibmvtpm_crq {__be16 len;__be32 data;__be64 reserved; -} __attribute__((packed, aligned(8))); +} __packed__aligned(8) ;
You can't need __packed and __aligned(8) on that structure. There are no gaps and you are saying it is always aligned.
So just remove the pointless attributes.
David
PATCH 2/5 Fix "ERROR: code indent should use tabs where possible"
In reply to SZ LinERROR: code indent should use tabs where possible
+^I^I "Need to wait for TPM to finish\n");$
--- drivers/char/tpm/tpm_ibmvtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_ibmvtpm.c +1 -1
@@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)if (ibmvtpm->tpm_processing_cmd) {dev_info (ibmvtpm->dev, -"Need to wait for TPM to finish\n" ); +"Need to wait for TPM to finish\n" );/* wait for previous command to finish */ sig =wait_event_interruptible (ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);if (sig)
Signature · 1 line
2.13.3
Michael Ellerman
reviewerRe: [PATCH 2/5] Fix "ERROR: code indent should use tabs where possible"
Quoted 13 lines · SZ Lin
ERROR: code indent should use tabs where possible
+^I^I "Need to wait for TPM to finish\n");$Signed-off-by SZ Lin <[email protected]>--- drivers/char/tpm/tpm_ibmvtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/tpm/tpm_ibmvtpm.c +0
-0
drivers/char/tpm/tpm_ibmvtpm.c static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) · line 130
Quoted 5 lines
drivers/char/tpm/tpm_ibmvtpm.c +1
-1@@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)if (ibmvtpm->tpm_processing_cmd) {dev_info (ibmvtpm->dev, -"Need to wait for TPM to finish\n" ); +"Need to wait for TPM to finish\n" );
There's no reason for that to be on a separate line at all. Just make it a single line dev_info( ... );
cheers
PATCH 3/5 Fix 'void function return statements are not generally useful' warning
In reply to SZ LinWARNING: void function return statements are not generally useful
+ return;
+}
--- drivers/char/tpm/tpm_ibmvtpm.c | 1 - 1 file changed, 1 deletion(-)
drivers/char/tpm/tpm_ibmvtpm.c +0 -1
@@ -531,7 +531,6 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,return ; } } -return ; }/**
Signature · 1 line
2.13.3
PATCH 4/5 Remove unneccessary 'out of memory' message
In reply to SZ LinWARNING: Possible unnecessary 'out of memory' message
+ if (!ibmvtpm->rtce_buf) {
+ dev_err(ibmvtpm->dev, "Failed to allocate memory for rtce buffer\n");
WARNING: Possible unnecessary 'out of memory' message
+ if (!ibmvtpm) {
+ dev_err(dev, "kzalloc for ibmvtpm failed\n");
--- drivers/char/tpm/tpm_ibmvtpm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_ibmvtpm.c +2 -6
@@ -501,10 +501,8 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq, ibmvtpm->rtce_size =be16_to_cpu (crq->len); ibmvtpm->rtce_buf =kmalloc (ibmvtpm->rtce_size,GFP_ATOMIC ); -if (!ibmvtpm->rtce_buf) { -dev_err (ibmvtpm->dev,"Failed to allocate memory for rtce buffer\n" ); +if (!ibmvtpm->rtce_buf)return ; - } ibmvtpm->rtce_dma_handle = dma_map_single(ibmvtpm->dev, ibmvtpm->rtce_buf, ibmvtpm->rtce_size,
@@ -584,10 +582,8 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,return PTR_ERR (chip); ibmvtpm =kzalloc (sizeof (struct ibmvtpm_dev ),GFP_KERNEL ); -if (!ibmvtpm) { -dev_err (dev,"kzalloc for ibmvtpm failed\n" ); +if (!ibmvtpm) goto cleanup; - } ibmvtpm->dev = dev; ibmvtpm->vdev = vio_dev;
Signature · 1 line
2.13.3
PATCH 5/5 Use __func__ instead of function name
In reply to SZ LinFix following checkpatch.pl warning:
WARNING: Prefer using '"%s...", __func__' to using the function's name, in a string
--- drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_ibmvtpm.c +6 -6
@@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]),be64_to_cpu (word[1 ]));if (rc !=H_SUCCESS ) { -dev_err (ibmvtpm->dev,"tpm_ibmvtpm_send failed rc=%d\n" , rc); +dev_err (ibmvtpm->dev,"%s failed rc=%d\n" , __func__, rc); rc =0 ; ibmvtpm->tpm_processing_cmd = false; }else
@@ -193,7 +193,7 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_get_rtce_size failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }
@@ -221,7 +221,7 @@ static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_get_version failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }
@@ -241,7 +241,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_send_init_complete failed rc=%d\n" , rc); +"%s rc=%d\n" , __func__, rc);return rc; }
@@ -261,7 +261,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_send_init failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }
@@ -351,7 +351,7 @@ static int tpm_ibmvtpm_suspend(struct device *dev) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"tpm_ibmvtpm_suspend failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }
Signature · 1 line
2.13.3
Re: [PATCH 5/5] Use __func__ instead of function name
Quoted 14 lines · SZ Lin
Fix following checkpatch.pl warning:
WARNING: Prefer using '"%s...",__func__' to using the function's name, in a stringSigned-off-by SZ Lin <[email protected]>--- drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/char/tpm/tpm_ibmvtpm.c +0
-0
drivers/char/tpm/tpm_ibmvtpm.c static int tpm_ibmvtpm_send(struct tpm_chip *chip, · line 155
Quoted 6 lines
drivers/char/tpm/tpm_ibmvtpm.c +1
-1@@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]),be64_to_cpu (word[1 ]));if (rc !=H_SUCCESS ) { -dev_err (ibmvtpm->dev,"tpm_ibmvtpm_send failed rc=%d\n" , rc); +dev_err (ibmvtpm->dev,"%s failed rc=%d\n" , __func__, rc);
Can function name contain a %?
I would prefer dev_err(ibmvtpm->dev, __func__ " failed rc=%d\n", rc);
It's not what checkpatch advises in the above message, though.
Presumably with many messages from the same function using %s would save space but that is not the usual case.
Thanks
Michal
Michael Ellerman
reviewerRe: [PATCH 5/5] Use __func__ instead of function name
Quoted 16 lines · Michal Such=C3=A1nek <[email protected]> writes:
Quoted 15 lines · SZ Lin
Fix following checkpatch.pl warning:
WARNING: Prefer using '"%s...",__func__' to using the function's name, in a string
=20Signed-off-by SZ Lin <[email protected]>--- drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)=20
drivers/char/tpm/tpm_ibmvtpm.c +0
-0@@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip,
Quoted 8 lines
drivers/char/tpm/tpm_ibmvtpm.c static int tpm_ibmvtpm_send(struct tpm_chip *chip, · line 155
Quoted 6 lines
drivers/char/tpm/tpm_ibmvtpm.c +1
-1u8 *buf, size_t count) rc =3D ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),be64_to_cpu (word[1 ])); if (rc !=3D H_SUCCESS) { -dev_err (ibmvtpm->dev,"tpm_ibmvtpm_send failed rc=3D%d\n" , rc); +dev_err (ibmvtpm->dev,"%s failed rc=3D%d\n" , __func__, rc);Can function name contain a %?
Let's hope not.
$ git grep "%s.*__func__" | wc -l 16937
cheers
Re: [PATCH 5/5] Use __func__ instead of function name
In reply to SZ LinI guess below code would be better idea to gather more debug information.
drivers/char/tpm/tpm_ibmvtpm.c +0 -0
@@ -141,6 +141,11 @@ static int tpm_ibmvtpm_send(struct tpm_chip
*chip, u8 *buf, size_t count)
return -EIO;
}+ if (!buf) {
+ dev_err(ibmvtpm->dev, "%s buf null at %d \n",__func__,
rc, __LINE__);
+ return 0;
+ }
+
spin_lock(&ibmvtpm->rtce_lock);
memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
crq.valid = (u8)IBMVTPM_VALID_CMD;@@ -150,8 +155,9 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
be64_to_cpu(word[1]));
+
if (rc != H_SUCCESS) {
- dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
+ dev_err(ibmvtpm->dev, "%s failed rc=%d at %d
\n",__func__, rc, __LINE__);
rc = 0;
} else
rc = count;2017-07-29 16:24 GMT+09:00 SZ Lin <[email protected]>:
Quoted 70 lines
Fix following checkpatch.pl warning:
WARNING: Prefer using '"%s...",__func__' to using the function's name, in a stringSigned-off-by SZ Lin <[email protected]>--- drivers/char/tpm/tpm_ibmvtpm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/char/tpm/tpm_ibmvtpm.c +6
-7@@ -151,7 +151,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) rc =ibmvtpm_send_crq (ibmvtpm->vdev,be64_to_cpu (word[0 ]),be64_to_cpu (word[1 ]));if (rc !=H_SUCCESS ) { -dev_err (ibmvtpm->dev,"tpm_ibmvtpm_send failed rc=%d\n" , rc); +dev_err (ibmvtpm->dev,"%s failed rc=%d\n" , __func__, rc); rc =0 ; ibmvtpm->tpm_processing_cmd = false; }else @@ -193,7 +193,7 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_get_rtce_size failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }@@ -221,7 +221,7 @@ static int ibmvtpm_crq_get_version(struct ibmvtpm_dev *ibmvtpm) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_get_version failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }@@ -241,7 +241,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm) rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_COMP_CMD ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_send_init_complete failed rc=%d\n" , rc); +"%s rc=%d\n" , __func__, rc);return rc; }@@ -261,7 +261,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm) rc =ibmvtpm_send_crq (ibmvtpm->vdev,INIT_CRQ_CMD ,0 );if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"ibmvtpm_crq_send_init failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; }@@ -351,7 +351,7 @@ static int tpm_ibmvtpm_suspend(struct device *dev) cpu_to_be64(buf[1]));if (rc !=H_SUCCESS )dev_err (ibmvtpm->dev, -"tpm_ibmvtpm_suspend failed rc=%d\n" , rc); +"%s failed rc=%d\n" , __func__, rc);return rc; } --2.13.3
Re: [PATCH 0/5] tpm: tpm_ibmvtpm: - style fix
In reply to SZ LinQuoted 1 line · SZ Lin
Fix styling WARNINGs and Errors of
tpm_ibmvtpm.cdriver by using checkpatch.pl
Changes are great but you should revise the patch series so that you expain in each commit what goes wrong instead of copy paste of the checkpatch output and why your changes fixes the problem.
Quoted 8 lines
SZ Lin (5):
Fix packed and aligned attribute warnings.
Fix "ERROR: code indent should use tabs where possible" Fix 'void function return statements are not generally useful' warning Remove unneccessary 'out of memory' message
Use__func__instead of function name
Quoted 7 lines
drivers/char/tpm/tpm_ibmvtpm.c | 23 +++++++++-------------- drivers/char/tpm/tpm_ibmvtpm.h | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-)--
2.13.3
/Jarkko