mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
@ 2026-08-01  0:10 kernel test robot
  2026-08-01  0:28 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2026-08-01  0:10 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: oe-kbuild-all, linux-kernel

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   8ba098e6b6ff0db8edf28528d1552be261af30d4
commit: b1e7a590a0133606d3efd41aee38cdeac630b52f ring-buffer: Add helper functions for allocations
date:   8 months ago
config: openrisc-randconfig-r062-20260801 (https://download.01.org/0day-ci/archive/20260801/202608010824.vc7vATf0-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 9.5.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Fixes: b1e7a590a013 ("ring-buffer: Add helper functions for allocations")
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608010824.vc7vATf0-lkp@intel.com/

cocci warnings: (new ones prefixed by >>)
>> kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
>> kernel/trace/ring_buffer.c:408:31-57: WARNING: casting value returned by memory allocation function to (struct ring_buffer_per_cpu *) is useless.

vim +412 kernel/trace/ring_buffer.c

   403	
   404	/*
   405	 * For best performance, allocate cpu buffer data cache line sized
   406	 * and per CPU.
   407	 */
 > 408	#define alloc_cpu_buffer(cpu) (struct ring_buffer_per_cpu *)		\
   409		kzalloc_node(ALIGN(sizeof(struct ring_buffer_per_cpu),		\
   410				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
   411	
 > 412	#define alloc_cpu_page(cpu) (struct buffer_page *)			\
   413		kzalloc_node(ALIGN(sizeof(struct buffer_page),			\
   414				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
   415	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
  2026-08-01  0:10 kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless kernel test robot
@ 2026-08-01  0:28 ` Steven Rostedt
  2026-08-01  7:05   ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2026-08-01  0:28 UTC (permalink / raw)
  To: kernel test robot; +Cc: oe-kbuild-all, linux-kernel, Julia Lawall

On Sat, 01 Aug 2026 08:10:14 +0800
kernel test robot <lkp@intel.com> wrote:

> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   8ba098e6b6ff0db8edf28528d1552be261af30d4
> commit: b1e7a590a0133606d3efd41aee38cdeac630b52f ring-buffer: Add helper functions for allocations
> date:   8 months ago
> config: openrisc-randconfig-r062-20260801 (https://download.01.org/0day-ci/archive/20260801/202608010824.vc7vATf0-lkp@intel.com/config)
> compiler: or1k-linux-gcc (GCC) 9.5.0
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Fixes: b1e7a590a013 ("ring-buffer: Add helper functions for allocations")
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202608010824.vc7vATf0-lkp@intel.com/
> 
> cocci warnings: (new ones prefixed by >>)
> >> kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
> >> kernel/trace/ring_buffer.c:408:31-57: WARNING: casting value returned by memory allocation function to (struct ring_buffer_per_cpu *) is useless.  

No, whatever Coccinelle script that reported this is broken.

The typecast is in a macro. The macro is adding the typecast to make
sure that what it is being assigned to is of the proper type.

Hence, it is very *useful*!

-- Steve


> 
> vim +412 kernel/trace/ring_buffer.c
> 
>    403	
>    404	/*
>    405	 * For best performance, allocate cpu buffer data cache line sized
>    406	 * and per CPU.
>    407	 */
>  > 408	#define alloc_cpu_buffer(cpu) (struct ring_buffer_per_cpu *)		\  
>    409		kzalloc_node(ALIGN(sizeof(struct ring_buffer_per_cpu),		\
>    410				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
>    411	
>  > 412	#define alloc_cpu_page(cpu) (struct buffer_page *)			\  
>    413		kzalloc_node(ALIGN(sizeof(struct buffer_page),			\
>    414				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
>    415	
> 
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki


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

* Re: kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
  2026-08-01  0:28 ` Steven Rostedt
@ 2026-08-01  7:05   ` Julia Lawall
  2026-08-05 18:18     ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2026-08-01  7:05 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: kernel test robot, oe-kbuild-all, linux-kernel



On Fri, 31 Jul 2026, Steven Rostedt wrote:

> On Sat, 01 Aug 2026 08:10:14 +0800
> kernel test robot <lkp@intel.com> wrote:
>
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head:   8ba098e6b6ff0db8edf28528d1552be261af30d4
> > commit: b1e7a590a0133606d3efd41aee38cdeac630b52f ring-buffer: Add helper functions for allocations
> > date:   8 months ago
> > config: openrisc-randconfig-r062-20260801 (https://download.01.org/0day-ci/archive/20260801/202608010824.vc7vATf0-lkp@intel.com/config)
> > compiler: or1k-linux-gcc (GCC) 9.5.0
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Fixes: b1e7a590a013 ("ring-buffer: Add helper functions for allocations")
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202608010824.vc7vATf0-lkp@intel.com/
> >
> > cocci warnings: (new ones prefixed by >>)
> > >> kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
> > >> kernel/trace/ring_buffer.c:408:31-57: WARNING: casting value returned by memory allocation function to (struct ring_buffer_per_cpu *) is useless.
>
> No, whatever Coccinelle script that reported this is broken.
>
> The typecast is in a macro. The macro is adding the typecast to make
> sure that what it is being assigned to is of the proper type.
>
> Hence, it is very *useful*!

Thanks for the report.  I will remove the warning in the case of a macro
body.

Is there some reason why it is not an inline function?

julia

>
> -- Steve
>
>
> >
> > vim +412 kernel/trace/ring_buffer.c
> >
> >    403
> >    404	/*
> >    405	 * For best performance, allocate cpu buffer data cache line sized
> >    406	 * and per CPU.
> >    407	 */
> >  > 408	#define alloc_cpu_buffer(cpu) (struct ring_buffer_per_cpu *)		\
> >    409		kzalloc_node(ALIGN(sizeof(struct ring_buffer_per_cpu),		\
> >    410				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
> >    411
> >  > 412	#define alloc_cpu_page(cpu) (struct buffer_page *)			\
> >    413		kzalloc_node(ALIGN(sizeof(struct buffer_page),			\
> >    414				   cache_line_size()), GFP_KERNEL, cpu_to_node(cpu));
> >    415
> >
> > --
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
>
>

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

* Re: kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless.
  2026-08-01  7:05   ` Julia Lawall
@ 2026-08-05 18:18     ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2026-08-05 18:18 UTC (permalink / raw)
  To: Julia Lawall; +Cc: kernel test robot, oe-kbuild-all, linux-kernel

On Sat, 1 Aug 2026 09:05:10 +0200 (CEST)
Julia Lawall <julia.lawall@inria.fr> wrote:

> Thanks for the report.  I will remove the warning in the case of a macro
> body.
> 
> Is there some reason why it is not an inline function?

Hmm, probably nothing more than they looked better as macros?

-- Steve

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

end of thread, other threads:[~2026-08-05 18:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-01  0:10 kernel/trace/ring_buffer.c:412:29-47: WARNING: casting value returned by memory allocation function to (struct buffer_page *) is useless kernel test robot
2026-08-01  0:28 ` Steven Rostedt
2026-08-01  7:05   ` Julia Lawall
2026-08-05 18:18     ` Steven Rostedt

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

all inboxes | Powered by JetHome®