linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] tpm: Use kzalloc for allocating only one thing
@ 2020-12-29 13:51 Zheng Yongjun
  2020-12-29 16:23 ` James Bottomley
  0 siblings, 1 reply; 3+ messages in thread
From: Zheng Yongjun @ 2020-12-29 13:51 UTC (permalink / raw)
  To: peterhuewe, jarkko, linux-integrity, linux-kernel; +Cc: jgg, Zheng Yongjun

Use kzalloc rather than kcalloc(1,...)

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
@@

- kcalloc(1,
+ kzalloc(
          ...)
// </smpl>

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---
 drivers/char/tpm/tpm1-cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index ca7158fa6e6c..4d8415e3b778 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -794,7 +794,7 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr)
  */
 int tpm1_get_pcr_allocation(struct tpm_chip *chip)
 {
-	chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks),
+	chip->allocated_banks = kzalloc(sizeof(*chip->allocated_banks),
 					GFP_KERNEL);
 	if (!chip->allocated_banks)
 		return -ENOMEM;
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] tpm: Use kzalloc for allocating only one thing
  2020-12-29 13:51 [PATCH -next] tpm: Use kzalloc for allocating only one thing Zheng Yongjun
@ 2020-12-29 16:23 ` James Bottomley
  2021-01-05  5:59   ` Jarkko Sakkinen
  0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2020-12-29 16:23 UTC (permalink / raw)
  To: Zheng Yongjun, peterhuewe, jarkko, linux-integrity, linux-kernel; +Cc: jgg

On Tue, 2020-12-29 at 21:51 +0800, Zheng Yongjun wrote:
> Use kzalloc rather than kcalloc(1,...)
> 
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)

What's the reason for wanting to do this transformation?

>  drivers/char/tpm/tpm1-cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-
> cmd.c
> index ca7158fa6e6c..4d8415e3b778 100644
> --- a/drivers/char/tpm/tpm1-cmd.c
> +++ b/drivers/char/tpm/tpm1-cmd.c
> @@ -794,7 +794,7 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32
> tpm_suspend_pcr)
>   */
>  int tpm1_get_pcr_allocation(struct tpm_chip *chip)
>  {
> -	chip->allocated_banks = kcalloc(1, sizeof(*chip-
> >allocated_banks),
> +	chip->allocated_banks = kzalloc(sizeof(*chip->allocated_banks),
>  					GFP_KERNEL);
>  	if (!chip->allocated_banks)
>  		return -ENOMEM;

The reason tpm1 has this is because it mirrors the allocation in tpm2
so we retain code consistency.  It's a fairly minor advantage, so it
could be changed if you have a better rationale ... but what is it?

James



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] tpm: Use kzalloc for allocating only one thing
  2020-12-29 16:23 ` James Bottomley
@ 2021-01-05  5:59   ` Jarkko Sakkinen
  0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2021-01-05  5:59 UTC (permalink / raw)
  To: James Bottomley
  Cc: Zheng Yongjun, peterhuewe, linux-integrity, linux-kernel, jgg

On Tue, Dec 29, 2020 at 08:23:49AM -0800, James Bottomley wrote:
> On Tue, 2020-12-29 at 21:51 +0800, Zheng Yongjun wrote:
> > Use kzalloc rather than kcalloc(1,...)
> > 
> > The semantic patch that makes this change is as follows:
> > (http://coccinelle.lip6.fr/)
> 
> What's the reason for wanting to do this transformation?
> 
> >  drivers/char/tpm/tpm1-cmd.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-
> > cmd.c
> > index ca7158fa6e6c..4d8415e3b778 100644
> > --- a/drivers/char/tpm/tpm1-cmd.c
> > +++ b/drivers/char/tpm/tpm1-cmd.c
> > @@ -794,7 +794,7 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32
> > tpm_suspend_pcr)
> >   */
> >  int tpm1_get_pcr_allocation(struct tpm_chip *chip)
> >  {
> > -	chip->allocated_banks = kcalloc(1, sizeof(*chip-
> > >allocated_banks),
> > +	chip->allocated_banks = kzalloc(sizeof(*chip->allocated_banks),
> >  					GFP_KERNEL);
> >  	if (!chip->allocated_banks)
> >  		return -ENOMEM;
> 
> The reason tpm1 has this is because it mirrors the allocation in tpm2
> so we retain code consistency.  It's a fairly minor advantage, so it
> could be changed if you have a better rationale ... but what is it?

Yup, I neither understand this.

> James

/Jarkko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-05  6:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29 13:51 [PATCH -next] tpm: Use kzalloc for allocating only one thing Zheng Yongjun
2020-12-29 16:23 ` James Bottomley
2021-01-05  5:59   ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).