lkml.org 
[lkml]   [2021]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH] rcu: Use typeof(p) instead of typeof(*p) *

On Tuesday 2021-10-05 22:37, Steven Rostedt wrote:
>
>Really, thinking about abstraction, I don't believe there's anything wrong
>with returning a pointer of one type, and then typecasting it to a pointer
>of another type. Is there? As long as whoever uses the returned type does
>nothing with it.

Illegal.
https://en.cppreference.com/w/c/language/conversion
subsection "Pointer conversion"
"No other guarantees are offered"

>struct trace_pid_list *trace_pid_list_alloc(void)
>{
> struct pid_list *pid_list;
>
> pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL);
> [..]
>
> return (struct trace_pid_list *)pid_list;
>}

struct trace_pid_list { void *pid_list; };
struct trace_pid_list trace_pid_list_alloc(void)
{
struct trace_pid_list t;
t.pid_list = kmalloc(sizeof(t.orig), GFP_KERNEL);
return t;
}
void freethat(struct strace_pid_list x)
{
kfree(x.pid_list);
}

Might run afoul of -Waggregate-return in C.

\
 
 \ /
  Last update: 2021-10-05 23:11    [W:0.168 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site