public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()
@ 2020-06-17 21:17 Gustavo A. R. Silva
  2020-06-17 21:29 ` Luck, Tony
  2020-06-18 11:35 ` [tip: ras/core] " tip-bot2 for Gustavo A. R. Silva
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-17 21:17 UTC (permalink / raw)
  To: Tony Luck, Borislav Petkov, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin
  Cc: x86, linux-edac, linux-kernel, Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

This code was detected with the help of Coccinelle and, audited and
fixed manually.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index 43c466020ed5..03e51053592a 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
 	int err;
 
 	mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
-	mcelog = kzalloc(sizeof(*mcelog) + mce_log_len * sizeof(struct mce), GFP_KERNEL);
+	mcelog = kzalloc(struct_size(mcelog, entry, mce_log_len), GFP_KERNEL);
 	if (!mcelog)
 		return -ENOMEM;
 
-- 
2.27.0


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

* Re: [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()
  2020-06-17 21:17 [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
@ 2020-06-17 21:29 ` Luck, Tony
  2020-06-18 11:35 ` [tip: ras/core] " tip-bot2 for Gustavo A. R. Silva
  1 sibling, 0 replies; 3+ messages in thread
From: Luck, Tony @ 2020-06-17 21:29 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Borislav Petkov, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	x86, linux-edac, linux-kernel, Gustavo A. R. Silva

On Wed, Jun 17, 2020 at 04:17:34PM -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
> 
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Acked-by: Tony Luck <tony.luck@intel.com>

> ---
>  arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> index 43c466020ed5..03e51053592a 100644
> --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
> +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> @@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
>  	int err;
>  
>  	mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
> -	mcelog = kzalloc(sizeof(*mcelog) + mce_log_len * sizeof(struct mce), GFP_KERNEL);
> +	mcelog = kzalloc(struct_size(mcelog, entry, mce_log_len), GFP_KERNEL);
>  	if (!mcelog)
>  		return -ENOMEM;
>  
> -- 
> 2.27.0
> 

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

* [tip: ras/core] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()
  2020-06-17 21:17 [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
  2020-06-17 21:29 ` Luck, Tony
@ 2020-06-18 11:35 ` tip-bot2 for Gustavo A. R. Silva
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Gustavo A. R. Silva @ 2020-06-18 11:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Gustavo A. R. Silva, Borislav Petkov, Tony Luck, x86, LKML

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     5ba7821bcf7d82e35582fce8fe65cd160a6954b4
Gitweb:        https://git.kernel.org/tip/5ba7821bcf7d82e35582fce8fe65cd160a6954b4
Author:        Gustavo A. R. Silva <gustavoars@kernel.org>
AuthorDate:    Wed, 17 Jun 2020 16:17:34 -05:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Thu, 18 Jun 2020 13:24:23 +02:00

x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

This code was detected with the help of Coccinelle and, audited and
fixed manually.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200617211734.GA9636@embeddedor
---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index 43c4660..03e5105 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
 	int err;
 
 	mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
-	mcelog = kzalloc(sizeof(*mcelog) + mce_log_len * sizeof(struct mce), GFP_KERNEL);
+	mcelog = kzalloc(struct_size(mcelog, entry, mce_log_len), GFP_KERNEL);
 	if (!mcelog)
 		return -ENOMEM;
 

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

end of thread, other threads:[~2020-06-18 11:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-17 21:17 [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2020-06-17 21:29 ` Luck, Tony
2020-06-18 11:35 ` [tip: ras/core] " tip-bot2 for Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox