Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4966687pxb; Tue, 5 Oct 2021 14:25:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaLn+PqT7lJUR2Gj1gTsArIJppWJz6Ki/GWAi1bUldV50sNQqnEwkewtsZw9lwulVO+9GR X-Received: by 2002:a17:90a:c703:: with SMTP id o3mr6410903pjt.176.1633469139053; Tue, 05 Oct 2021 14:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633469139; cv=none; d=google.com; s=arc-20160816; b=sOk0/sgdq393rsEaGlqZxkt88jeeHSQwLx+GBWhyjmYzat9pDrrp7yn7x5hyGieJtG +LUc38IO2g3NQcLOEcwGJ6Fxw/twWpe94YkOv0cmJM+QO0TBSPBxRhuooFve6TJM9mYl Qmt0JalB4mg0/pIU9EYvKRrxXo8lYxN3/hGiSJP2fbsnOJVpZpUL14stDknoE4CkiUnX 80A6swUpqe9Mgr4mBtc2+OKWMFKE86TFqeX42FUtsDfJpWk7n3fuKzD+x4gzj9h2FOA7 VbqiXLdqaQdoSxydoNVFMZnaR1cw/uWJ+RvB9CpBjuyqpgRhoasl1/oPl/JrK5VyU6U8 Ru2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=/Pn+UyiSD3YjX2R11luTmPAbR3hgzQW0goRJ5PAaJSc=; b=L9VIB4f8DZP7aH36o/re7DRK0BpzXJP99lS8+WTk9iw+a3u8WBxaXRzn8ksFzPGpcI xJSyX6/RImJYTQ3mrbCx1+i29yi4bxff2xM2/hjnbznUu99MX/vAEF8Qh5Iq7ESz/0MG 54xxJk4VwZuG4mFtZQUKCgPPS3q+YjtAD7Cfq92gocvgUWMBnHYqPHUsRGIeoIhbSvAo tRk8xhXjHn32AdEUNTbF5XY0cMnsqUfwp8HTucO4U6PXowdzu9aUiswETRg7x7IVfp5c hJTmcKTtQIJ7BhzY9W4zCBwc60G9g0t8g3JxzzUJqODoJrTrP5QK4+PU/M/j4sSAaiO9 hAAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si27129675pgj.447.2021.10.05.14.25.25; Tue, 05 Oct 2021 14:25:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236281AbhJEV03 (ORCPT + 99 others); Tue, 5 Oct 2021 17:26:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:47766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235679AbhJEV03 (ORCPT ); Tue, 5 Oct 2021 17:26:29 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 917CE6120A; Tue, 5 Oct 2021 21:24:36 +0000 (UTC) Date: Tue, 5 Oct 2021 17:24:35 -0400 From: Steven Rostedt To: Jan Engelhardt Cc: Mathieu Desnoyers , Rasmus Villemoes , linux-kernel , Linus Torvalds , Paul , Josh Triplett , Lai Jiangshan , "Joel Fernandes, Google" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , rcu , netfilter-devel , coreteam , netdev Subject: Re: [RFC][PATCH] rcu: Use typeof(p) instead of typeof(*p) * Message-ID: <20211005172435.190c62d9@gandalf.local.home> In-Reply-To: References: <20211005094728.203ecef2@gandalf.local.home> <639278914.2878.1633457192964.JavaMail.zimbra@efficios.com> <826o327o-3r46-3oop-r430-8qr0ssp537o3@vanv.qr> <20211005144002.34008ea0@gandalf.local.home> <20211005154029.46f9c596@gandalf.local.home> <20211005163754.66552fb3@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Oct 2021 23:09:08 +0200 (CEST) Jan Engelhardt wrote: > 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" Basically (one alternative I was looking at) was simply passing around a void pointer. Not sure how the RCU macros would handle that. But to completely abstract it out, I was thinking of just returning void * and accepting void *, but I didn't want to do that because now we just lost any kind of type checking done by the compiler. The tricks I was playing was to keep some kind of type checking. > > >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. The above isn't exactly what I was suggesting. And really, not that I'm going to do this, I could have followed the rest of the kernel with: struct trace_pid_list { int max; [..] }; int *trace_pid_list_alloc(void) { struct trace_pid_list *pid_list; pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL); [..] return &pid_list->max; } void trace_pid_list_free(int *p) { struct trace_pid_list *pid_list = container_of(p, struct pid_list, max); [..] free(pid_list); } Because we do this all over the kernel. Talk about lying to the compiler ;-) -- Steve