From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6031C81ACA; Wed, 5 Feb 2025 06:45:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738737955; cv=none; b=bKk1NzXg+8NayIKaNeq/R5VTuXJbwiKkYBeBcC1oGHTPU0wEM2Evs3V9QNhlexHifntxGvWTISzbyBFvqb0IL6MoBC275wN5uYkhnLBM9/L3jzOz+YpTN00HZ7PGqh2NJ1BvmLcDTF5rFZBPJ+vrIn1Jo6JAqp8vJLOkGSMgSU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738737955; c=relaxed/simple; bh=JZe+qR3eYb9BK90I3WJZEMYK56rpjR/pJ0ynrjG5oAc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nrPNusCfUZNgJhDeGWX4v5sHZHX9m8dZzw47p4x31GX7l3oMOpsAdINt/MnF/MmYxLfwB4olGslIJnA8KdP9e96Mlovsvnu4ySHXj8IYKxL4Ld2JelJbw4a6TkzYqA5DUActouPvoLMVEF710E0rYjLHGy4Kkknm+CBL4xuPq/w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XUxqglHW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XUxqglHW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B501FC4CEE5; Wed, 5 Feb 2025 06:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738737954; bh=JZe+qR3eYb9BK90I3WJZEMYK56rpjR/pJ0ynrjG5oAc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XUxqglHWNLI9hm7//VUDbOj2yyocxZaWgy9xqVaL0zoqOq0TPGpV8DABAQ89jKZsO Y418AEPOLyX7PmsgAEdRChb1Yyreu5IRCDludvls13gSKKWSEIXEiofzWMhX/GeftC k6pkU7xia2bc++PBzFWIq9ECDRe0gRhF+6r62J8IU7hBurXg0vqVxvKunPGjEEFpm8 MW8nFI3oKQqrt1EDhnNBFZiQvmb4/Sd2OXeYyS3TvInkIzqrd+oSBKoKTX0U1zA0bq dp1LIUH36KOdGg/3xJ3c97TXYOBzGfeyQX6plxVIKjd+gWPkrQ7oVo2Bw4Dgci1rsQ DFUe+tHV6m67w== Message-ID: Date: Wed, 5 Feb 2025 07:45:51 +0100 Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH][next] tty: tty_buffer: Avoid hundreds of -Wflex-array-member-not-at-end warnings To: Greg Kroah-Hartman , "Gustavo A. R. Silva" Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-hardening@vger.kernel.org References: <2025020503-unnamable-canopener-ac71@gregkh> Content-Language: en-US From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVL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GNqQrDk+gRNvKnGwFNeTkTKtJ0P8jYd7P1gZb9Fwj9YLx jhn/sVIhNmEBLBoI7PL+9fbILqJPHgAwW35rpnq4f/EYTykbk1sa13Tav6btJ+4QOgbcezWI wZ5w/JVfEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <2025020503-unnamable-canopener-ac71@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05. 02. 25, 6:36, Greg Kroah-Hartman wrote: > On Wed, Feb 05, 2025 at 03:51:35PM +1030, Gustavo A. R. Silva wrote: >> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are >> getting ready to enable it, globally. >> >> So, in order to avoid ending up with a flexible-array member in the >> middle of other structs, we use the `struct_group_tagged()` helper >> to create a new tagged `struct tty_buffer_hdr`. This structure >> groups together all the members of the flexible `struct tty_buffer` >> except the flexible array. >> >> As a result, the array is effectively separated from the rest of the >> members without modifying the memory layout of the flexible structure. >> We then change the type of the middle struct member currently causing >> trouble from `struct tty_buffer` to `struct tty_buffer_hdr`. >> >> We also want to ensure that when new members need to be added to the >> flexible structure, they are always included within the newly created >> tagged struct. For this, we use `static_assert()`. This ensures that the >> memory layout for both the flexible structure and the new tagged struct >> is the same after any changes. >> >> This approach avoids having to implement `struct tty_buffer_hdr` as a >> completely separate structure, thus preventing having to maintain two >> independent but basically identical structures, closing the door to >> potential bugs in the future. > > Why not just have a separate structure and embed that in the places it > is used? No duplication should be needed or am I missing something? > > I don't mind that, it would make this all much simpler and more obvious > over time, and the tty layer needs all the "simplification" it can get > :) +100. You can name the member hdr or even h. Another approach would be to get rid of sentinel completely. But that might be too hard. Have you looked into it? You should describe that above too. On the top of that: I remember I already looked into this when gcc14 was introduced and I was retracted by something else. Nevertheless, it took me quite a while to understand what the exact problem is and how you are doing the fix. Both from the patch (the main change in tty_bufhead is hidden behind whitespace changes) and especially from the description (you do not say the simple: tty_bufhead contains data[] in the middle due to embedded tty_buffer there). Both need to be improved. PS v2 was sent too early :P. thanks, -- js suse labs