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 Tue, 5 Oct 2021 15:40:29 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> struct trace_pid_list {
> unsigned long ignore;
> };
>
> Rename the above struct trace_pid_list to struct trace_pid_internal.
>
> And internally have:
>
> union trace_pid_data {
> struct trace_pid_list external;
> struct trace_pid_internal internal;
> };
>
> Then use the internal version within the C file that modifies it, and just
> return a pointer to the external part.

So this has proved to be a PITA.

>
> That should follow the "C standard".

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.

That is, if I simply do:

In the header file:

struct trace_pid_list {
void *ignore;
};

struct trace_pid_list *trace_pid_list_alloc(void);
void trace_pid_list_free(struct trace_pid_list *pid_list);


And then in the C file:

struct pid_list {
[...]
};

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;
}

void trace_pid_list_free(struct trace_pid_list *list)
{
struct pid_list *pid_list = (struct pid_list *)list;

[..]
kfree(pid_list);
}

That should be perfectly fine for standard C. Right?

-- Steve

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