From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDCF5C77B6D for ; Tue, 28 Mar 2023 09:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232730AbjC1Jod (ORCPT ); Tue, 28 Mar 2023 05:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbjC1Jnt (ORCPT ); Tue, 28 Mar 2023 05:43:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A73619C; Tue, 28 Mar 2023 02:43:48 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679996626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZJUsCpyk++InuJD8c8lxndmlf4x2V623RySxbdpxX/k=; b=Uyj1ACFTSvJ37+qTPnzpaAJOMaiSAelVgF1p9i/ti4EZvOobjhHWGgYRRN5sMBjcETUXWR 1cMdDksX6+EgiwtW6YvmB/kfDTZoBXT7sZrUg01dFAEQ5SvSb0DPTwSla6hBQMI/PQKSWp F4eJdNhm2nnljlMOt+yub+n8x7paNu18P2CLLBfbcypP4ViRkic5BnZU4BBmM59Nk/9LZk Kksd2lf2VOoed6cIxk7ScVaSPVZmZUGEDFKrGQllQn8LxRbKrPA8ZDpbbkXDtpIO3NHn3n DDfIcE76WdRVye+lTkl0k+auwIijCwhdh19hUgAFbuZLFmLaWmELSRkabjZGzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679996626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZJUsCpyk++InuJD8c8lxndmlf4x2V623RySxbdpxX/k=; b=IplZafMHsF4nv815SX/K+f2hvIwBR0S2XIVpBTpNkVSGZYRCb/mxkvMLfvuGcxKOR0QBGZ s7+2n3ygmO8H4JDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org Subject: Re: union: was: Re: [PATCH printk v1 05/18] printk: Add non-BKL console basic infrastructure In-Reply-To: References: <20230302195618.156940-1-john.ogness@linutronix.de> <20230302195618.156940-6-john.ogness@linutronix.de> <87y1nip3a1.fsf@jogness.linutronix.de> Date: Tue, 28 Mar 2023 11:48:06 +0206 Message-ID: <87cz4tus9d.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-28, Petr Mladek wrote: >> A compilation check would be nice. Is that possible? > > I think the following might do the trick: > > static_assert(sizeof(struct cons_state) == sizeof(atomic_long_t)); I never realized the kernel code was allowed to have that. But it is everywhere! :-) Thanks. I've added and tested the following: /* * The nbcon_state struct is used to easily create and interpret values that * are stored in the console.nbcon_state variable. Make sure this struct stays * within the size boundaries of that atomic variable's underlying type in * order to avoid any accidental truncation. */ static_assert(sizeof(struct nbcon_state) <= sizeof(long)); Note that I am checking against sizeof(long), the underlying variable type. We probably shouldn't assume sizeof(atomic_long_t) is always sizeof(long). John