All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] objtool: Fix calloc call for new -Walloc-size
@ 2023-11-07 20:55 Sam James
  2023-11-09 21:40 ` Josh Poimboeuf
  2023-11-20 14:44 ` [tip: objtool/core] " tip-bot2 for Sam James
  0 siblings, 2 replies; 4+ messages in thread
From: Sam James @ 2023-11-07 20:55 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra; +Cc: linux-kernel, Sam James

GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
like:
```
check.c: In function ‘cfi_alloc’:
check.c:294:33: error: allocation of insufficient size ‘1’ for type ‘struct cfi_state’ with size ‘320’ [-Werror=alloc-size]
  294 |         struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
      |                                 ^~~~~~
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the prototype, as
we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <sam@gentoo.org>
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e94756e09ca9..548ec3cd7c00 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -291,7 +291,7 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
 
 static struct cfi_state *cfi_alloc(void)
 {
-	struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
+	struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state));
 	if (!cfi) {
 		WARN("calloc failed");
 		exit(1);
-- 
2.42.1


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

* Re: [PATCH] objtool: Fix calloc call for new -Walloc-size
  2023-11-07 20:55 [PATCH] objtool: Fix calloc call for new -Walloc-size Sam James
@ 2023-11-09 21:40 ` Josh Poimboeuf
  2023-11-17  9:30   ` Peter Zijlstra
  2023-11-20 14:44 ` [tip: objtool/core] " tip-bot2 for Sam James
  1 sibling, 1 reply; 4+ messages in thread
From: Josh Poimboeuf @ 2023-11-09 21:40 UTC (permalink / raw)
  To: Sam James; +Cc: Peter Zijlstra, linux-kernel

On Tue, Nov 07, 2023 at 08:55:00PM +0000, Sam James wrote:
> GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
> like:
> ```
> check.c: In function ‘cfi_alloc’:
> check.c:294:33: error: allocation of insufficient size ‘1’ for type ‘struct cfi_state’ with size ‘320’ [-Werror=alloc-size]
>   294 |         struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
>       |                                 ^~~~~~
> ```
> 
> The calloc prototype is:
> ```
> void *calloc(size_t nmemb, size_t size);
> ```
> 
> So, just swap the number of members and size arguments to match the prototype, as
> we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
> doing anything wrong.
> 
> Signed-off-by: Sam James <sam@gentoo.org>
> ---
>  tools/objtool/check.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index e94756e09ca9..548ec3cd7c00 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -291,7 +291,7 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
>  
>  static struct cfi_state *cfi_alloc(void)
>  {
> -	struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
> +	struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state));
>  	if (!cfi) {
>  		WARN("calloc failed");
>  		exit(1);

Thanks!

Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>

Peter are you able to grab this or should I put it in my tree first?

-- 
Josh

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

* Re: [PATCH] objtool: Fix calloc call for new -Walloc-size
  2023-11-09 21:40 ` Josh Poimboeuf
@ 2023-11-17  9:30   ` Peter Zijlstra
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2023-11-17  9:30 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Sam James, linux-kernel

On Thu, Nov 09, 2023 at 01:40:30PM -0800, Josh Poimboeuf wrote:
> On Tue, Nov 07, 2023 at 08:55:00PM +0000, Sam James wrote:
> > GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
> > like:
> > ```
> > check.c: In function ‘cfi_alloc’:
> > check.c:294:33: error: allocation of insufficient size ‘1’ for type ‘struct cfi_state’ with size ‘320’ [-Werror=alloc-size]
> >   294 |         struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
> >       |                                 ^~~~~~
> > ```
> > 
> > The calloc prototype is:
> > ```
> > void *calloc(size_t nmemb, size_t size);
> > ```
> > 
> > So, just swap the number of members and size arguments to match the prototype, as
> > we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
> > doing anything wrong.
> > 
> > Signed-off-by: Sam James <sam@gentoo.org>
> > ---
> >  tools/objtool/check.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> > index e94756e09ca9..548ec3cd7c00 100644
> > --- a/tools/objtool/check.c
> > +++ b/tools/objtool/check.c
> > @@ -291,7 +291,7 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
> >  
> >  static struct cfi_state *cfi_alloc(void)
> >  {
> > -	struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
> > +	struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state));
> >  	if (!cfi) {
> >  		WARN("calloc failed");
> >  		exit(1);
> 
> Thanks!
> 
> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
> 
> Peter are you able to grab this or should I put it in my tree first?

Got it, thanks!

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

* [tip: objtool/core] objtool: Fix calloc call for new -Walloc-size
  2023-11-07 20:55 [PATCH] objtool: Fix calloc call for new -Walloc-size Sam James
  2023-11-09 21:40 ` Josh Poimboeuf
@ 2023-11-20 14:44 ` tip-bot2 for Sam James
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Sam James @ 2023-11-20 14:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sam James, Peter Zijlstra (Intel), Josh Poimboeuf, x86,
	linux-kernel

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

Commit-ID:     e2e13630f93d942d02f3b3f98660228a3545c60e
Gitweb:        https://git.kernel.org/tip/e2e13630f93d942d02f3b3f98660228a3545c60e
Author:        Sam James <sam@gentoo.org>
AuthorDate:    Tue, 07 Nov 2023 20:55:00 
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 17 Nov 2023 10:54:50 +01:00

objtool: Fix calloc call for new -Walloc-size

GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
like:
```
check.c: In function ‘cfi_alloc’:
check.c:294:33: error: allocation of insufficient size ‘1’ for type ‘struct cfi_state’ with size ‘320’ [-Werror=alloc-size]
  294 |         struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
      |                                 ^~~~~~
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the prototype, as
we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/20231107205504.1470006-1-sam@gentoo.org
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e94756e..548ec3c 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -291,7 +291,7 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
 
 static struct cfi_state *cfi_alloc(void)
 {
-	struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
+	struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state));
 	if (!cfi) {
 		WARN("calloc failed");
 		exit(1);

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

end of thread, other threads:[~2023-11-20 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-07 20:55 [PATCH] objtool: Fix calloc call for new -Walloc-size Sam James
2023-11-09 21:40 ` Josh Poimboeuf
2023-11-17  9:30   ` Peter Zijlstra
2023-11-20 14:44 ` [tip: objtool/core] " tip-bot2 for Sam James

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.