Kevin O'Connor [Thu, 20 Jan 2022 00:07:47 +0000 (19:07 -0500)]
sercon: Fix missing GET_LOW() to access rx_bytes
The variable rx_bytes is marked VARLOW, but there was a missing
GET_LOW() to access rx_bytes. Fix by copying rx_bytes to a local
variable and avoid the repetitive segment memory accesses.
Reported-by: Gabe Black <gabe.black@gmail.com> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor [Wed, 19 Jan 2022 18:20:21 +0000 (13:20 -0500)]
nvme: Build the page list in the existing dma buffer
Commit 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists")
introduced multi-page requests using the NVMe PRP mechanism. To store the
list and "first page to write to" hints, it added fields to the NVMe
namespace struct.
Unfortunately, that struct resides in fseg which is read-only at runtime.
While KVM ignores the read-only part and allows writes, real hardware and
TCG adhere to the semantics and ignore writes to the fseg region. The net
effect of that is that reads and writes were always happening on address 0,
unless they went through the bounce buffer logic.
This patch builds the PRP maintenance data in the existing "dma bounce
buffer" and only builds it when needed.
Fixes: 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists") Reported-by: Matt DeVillier <matt.devillier@gmail.com> Signed-off-by: Alexander Graf <graf@amazon.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net> Reviewed-by: Alexander Graf <graf@amazon.com>
Gerd Hoffmann [Thu, 16 Dec 2021 07:20:58 +0000 (08:20 +0100)]
svgamodes: add standard 4k modes
Add all three 4k modes. Computer monitors typically use
the first one (3840x2160).
Add 16 and 32 bpp variants. 24bpp is dead these days, and
software which is so old that still uses those modes most
likely doesn't even know what 4k is.
Igor Mammedov [Mon, 29 Nov 2021 11:48:12 +0000 (06:48 -0500)]
pci: let firmware reserve IO for pcie-pci-bridge
With [1] patch hotplug of rtl8139 succeeds, with caveat that it
fails to initialize IO bar, which is caused by [2] that makes
firmware skip IO reservation for any PCIe device, which isn't
correct in case of pcie-pci-bridge.
Fix it by exposing hotplug type and making IO resource optional
only if PCIe hotplug is in use.
[1]
"pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35"
[2] Fixes: 76327b9f32a ("fw/pci: do not automatically allocate IO region for PCIe bridges") Signed-off-by: Igor Mammedov imammedo@redhat.com Tested-by: Laurent Vivier <lvivier@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> CC: mapfelba@redhat.com CC: kraxel@redhat.com CC: mst@redhat.com CC: lvivier@redhat.com CC: jusual@redhat.com
Igor Mammedov [Mon, 29 Nov 2021 11:48:11 +0000 (06:48 -0500)]
pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35
If QEMU is started with unpopulated pcie-pci-bridge with ACPI PCI
hotplug enabled (default since QEMU-6.1), hotplugging a PCI device
into one of the bridge slots fails due to lack of resources.
once linux guest is booted (test used Fedora 34), hotplug NIC from
QEMU monitor:
(qemu) device_add rtl8139,bus=pcie-pci-bridge-0,addr=0x2
guest fails hotplug with:
pci 0000:01:02.0: [10ec:8139] type 00 class 0x020000
pci 0000:01:02.0: reg 0x10: [io 0x0000-0x00ff]
pci 0000:01:02.0: reg 0x14: [mem 0x00000000-0x000000ff]
pci 0000:01:02.0: reg 0x30: [mem 0x00000000-0x0003ffff pref]
pci 0000:01:02.0: BAR 6: no space for [mem size 0x00040000 pref]
pci 0000:01:02.0: BAR 6: failed to assign [mem size 0x00040000 pref]
pci 0000:01:02.0: BAR 0: no space for [io size 0x0100]
pci 0000:01:02.0: BAR 0: failed to assign [io size 0x0100]
pci 0000:01:02.0: BAR 1: no space for [mem size 0x00000100]
pci 0000:01:02.0: BAR 1: failed to assign [mem size 0x00000100]
8139cp: 8139cp: 10/100 PCI Ethernet driver v1.3 (Mar 22, 2004)
PCI Interrupt Link [GSIG] enabled at IRQ 22
8139cp 0000:01:02.0: no MMIO resource
8139cp: probe of 0000:01:02.0 failed with error -5
Reason for this is that commit [1] didn't take into account
pcie-pci-bridge, marking bridge as non hotpluggable instead of
handling it as possibly SHPC capable bridge.
Fix issue by checking if pcie-pci-bridge is SHPC capable and
if it is mark it as hotpluggable.
Fixes regression in QEMU-6.1 and later, since it was switched
to ACPI based PCI hotplug on Q35 by default at that time.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2001732
[1] Fixes: 3aa31d7d637 ("hw/pci: reserve IO and mem for pci express downstream ports with no devices attached") Signed-off-by: Igor Mammedov imammedo@redhat.com Acked-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Laurent Vivier <lvivier@redhat.com> CC: mapfelba@redhat.com CC: kraxel@redhat.com CC: mst@redhat.com CC: lvivier@redhat.com CC: jusual@redhat.com
Eduardo Habkost [Thu, 10 Dec 2020 19:07:16 +0000 (14:07 -0500)]
smbios: Make smbios_build_tables() ready for 64-bit tables
Make smbios_build_tables() get u64 address and u32 length
arguments, making it usable for SMBIOS 3.0. Adapt
smbios_21_setup_entry_point() to use intermediate variables when
calling smbios_build_tables().
Eduardo Habkost [Thu, 10 Dec 2020 18:10:15 +0000 (13:10 -0500)]
smbios: Make smbios_build_tables() more generic
Instead of taking a SMBIOS 2.1 entry point as argument, make
smbios_build_tables() take pointers to the fields it actually
changes. This will allow us to reuse the function for SMBIOS 3.0
later.
Eduardo Habkost [Thu, 10 Dec 2020 18:05:17 +0000 (13:05 -0500)]
smbios: Extract SMBIOS table building code to separate function
Move the code that builds the SMBIOS tables to a separate
smbios_build_tables() function, to keep it isolated from the code
that initializes the SMBIOS entry point.
Thew new function will still take a smbios_21_entry_point
argument to make code review easier, but this will be changed by
the next commits.
Eduardo Habkost [Thu, 10 Dec 2020 17:32:37 +0000 (12:32 -0500)]
smbios: Use smbios_next() at smbios_romfile_setup()
Use smbios_next() instead of smbios_21_next(), to make the code
more generic and reusable for SMBIOS 3.0 support.
Note that `qtables_len` is initialized to `ftables->size` instead
of `ep.structure_table_length` now, but both fields are
guaranteed to have exactly the same value.
Eduardo Habkost [Thu, 10 Dec 2020 20:18:28 +0000 (15:18 -0500)]
tpm: Use smbios_get_tables()
Instead of using the SMBios21Addr global variable, use the
smbios_get_tables() helper. This doesn't change any behavior
yet, but it will be useful when we start supporting SMBIOS 3.0
entry points.
Stefan Berger [Mon, 14 Jun 2021 17:35:49 +0000 (13:35 -0400)]
tcgbios: Use The proper sha function for each PCR bank
Instead of just using sha1 for all PCR banks (and truncating
the value or zero-padding it) use the proper hash function for
each one of the banks. For unimplemented hashes, fill the buffer
with 0xff.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Volker Rümelin [Fri, 4 Jun 2021 18:01:20 +0000 (20:01 +0200)]
stacks: call check_irqs() after switch_next()
In function run_thread() the function check_irqs() gets called
after the thread switch for atomic handoff reasons. In yield()
it's the other way round.
If check_irqs() is called after run_thread() and check_irqs()
is called before switch_next() in yield(), it can happen in a
constructed case that a background thread runs twice without
a check_irqs() call in between. Call check_irqs() after
switch_next() in yield() to prevent this.
Volker Rümelin [Fri, 4 Jun 2021 18:01:19 +0000 (20:01 +0200)]
stacks: call check_irqs() in run_thread()
The comment above the yield() function suggests that yield()
allows interrupts for a short time. But yield() only briefly
enables interrupts if seabios was built without CONFIG_THREADS
or if yield() is called from the main thread. In order to
guarantee that the interrupts were enabled once before yield()
returns in a background thread, the main thread must call
check_irqs() before or after every thread switch. The function
run_thread() also switches threads, but the call to check_irqs()
was forgotten. Add the missing check_irqs() call.
This fixes PS/2 keyboard initialization failures.
The code in src/hw/ps2port.c relies on yield() to briefly enable
interrupts. There is a comment above the yield() function in
__ps2_command(), where the author left a remark why the call to
yield() is actually needed.
Here is one of the call sequences leading to a PS/2 keyboard
initialization failure.
ps2_keyboard_setup()
|
ret = i8042_command(I8042_CMD_CTL_TEST, param);
# This command will register an interrupt if the PS/2 device
# controller raises interrupts for replies to a controller
# command.
|
ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param);
|
ps2_command(0, command, param);
|
ret = __ps2_command(aux, command, param);
|
// Flush any interrupts already pending.
yield();
# yield() doesn't flush interrupts if the main thread
# hasn't reached wait_threads().
|
ret = ps2_sendbyte(aux, command, 1000);
# Reset the PS/2 keyboard controller and wait for
# PS2_RET_ACK.
|
ret = ps2_recvbyte(aux, 0, 4000);
|
for (;;) {
|
status = inb(PORT_PS2_STATUS);
# I8042_STR_OBF isn't set because the keyboard self
# test reply is still on wire.
|
yield();
# After a few yield()s the keyboard interrupt fires
# and clears the I8042_STR_OBF status bit. If the
# keyboard self test reply arrives before the
# interrupt fires the keyboard reply is lost and
# ps2_recvbyte() returns after the timeout.
}
BUILD_MIN_BIOSTABLE reserves space in the f-segment. Some data
structures -- for example disk drives known to seabios -- must be
stored there, so the space available here limits the number of
devices seabios is able to manage.
This patch sets BUILD_MIN_BIOSTABLE to 8k for bios images being 256k or
larger in size. 32bit code is moved off in that case, so we have more
room in the f-segment then.
Gerd Hoffmann [Wed, 26 May 2021 07:32:10 +0000 (09:32 +0200)]
nvme: improve namespace allocation
Instead of allocating a big array upfront go probe the namespaces and
only allocate an nvme_namespace struct for those namespaces which are
actually active.
Modern binutils unconditionally tracks x86_64 ISA levels in intermediate
files in .note.gnu.property. Custom liker script does not handle the
section and complains about it:
Mike Banon [Thu, 3 Dec 2020 04:06:59 +0000 (07:06 +0300)]
Support booting USB drives with a write protect switch enabled
At least some USB drives with a write protect switch (e.g. Netac U335)
could report "MEDIUM NOT PRESENT" for a while if a write protection is
enabled. Instead of stopping the initialization attempts immediately,
stop only after getting this report for 3 times, to ensure the
successful initialization of such a "broken hardware".
David Woodhouse [Thu, 5 Nov 2020 16:09:32 +0000 (16:09 +0000)]
nvme: Clean up nvme_cmd_readwrite()
This ended up with an odd mix of recursion (albeit *mostly*
tail-recursion) and interation that could have been prettier. In
addition, while recursing it potentially adjusted op->count which is
used by callers to see the amount of I/O actually performed.
Fix it by bringing nvme_build_prpl() into the normal loop using 'i'
as the offset in the op.
Fixes: 94f0510dc ("nvme: Split requests by maximum allowed size") Reviewed-by: Alexander Graf <graf@amazon.com> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Alexander Graf [Wed, 30 Sep 2020 21:10:56 +0000 (23:10 +0200)]
nvme: Split requests by maximum allowed size
Some NVMe controllers only support small maximum request sizes, such as
the AWS EBS NVMe implementation which only supports NVMe requests of up
to 32 pages (256kb) at once.
BIOS callers can exceed those request sizes by defining sector counts
above this threshold. Currently we fall back to the bounce buffer
implementation for those. This is slow.
This patch introduces splitting logic to the NVMe I/O request code so
that every NVMe I/O request gets handled in a chunk size that is
consumable by the NVMe adapter, while maintaining the fast path PRPL
logic we just introduced.
Alexander Graf [Wed, 30 Sep 2020 21:10:55 +0000 (23:10 +0200)]
nvme: Pass large I/O requests as PRP lists
Today, we split every I/O request into at most 4kb chunks and wait for these
requests to finish. We encountered issues where the backing storage is network
based, so every I/O request needs to go over the network with associated
latency cost. A few ms of latency when loading 100MB initrd in 4kb chunks
does add up.
NVMe implements a feature to allow I/O requests spanning multiple pages,
called PRP lists. This patch takes larger I/O operations and checks if
they can be directly passed to the NVMe backing device as PRP list.
At least for grub, read operations can always be mapped directly into
PRP list items.
This reduces the number of I/O operations required during a typical boot
path by roughly a factor of 5.
Alexander Graf [Wed, 30 Sep 2020 21:10:54 +0000 (23:10 +0200)]
nvme: Allow to set PRP2
When creating a PRP based I/O request, we pass in the pointer to operate
on. Going forward, we will want to be able to pass additional pointers
though for mappings above 4k.
This patch adds a parameter to nvme_get_next_sqe() to pass in the PRP2
value of an NVMe I/O request, paving the way for a future patch to
implement PRP lists.
Signed-off-by: Alexander Graf <graf@amazon.com> Reviewed-by: Filippo Sironi <sironi@amazon.de>
Alexander Graf [Wed, 30 Sep 2020 21:10:53 +0000 (23:10 +0200)]
nvme: Record maximum allowed request size
NVMe has a limit on how many sectors it can handle at most within a single
request. Remember that number, so that in a follow-up patch, we can verify
that we don't exceed it.
usb/xhci: add support for mmio host adapters (via acpi).
Add xhci_controller_setup_acpi() function to initialize usb host
adapters declared in the DSDT table. Search the acpi devices list
for xhci controllers.
usb/xhci: split xhci setup into generic and pci parts
Split the pci-specific code into a separate xhci_controller_setup_pci()
function, turn xhci_controller_setup() to a generic xhci setup function
which only needs the mmio address if the control registers.
USB:Fix xHCI initail fail by using longer reset and CNR clear timeout value
Some xHCI controller's reset time than 100ms,such as 120ms.
On the on hand, xHCI spec has not specified a timeout value.
Maybe setting xHCI HCRST and CNR bit clear timeout value larger
is a nice thing.As a compromise between compatibility and
latency,we can take 1000ms as a timeout value.
Matt DeVillier [Fri, 11 Sep 2020 17:54:21 +0000 (12:54 -0500)]
usb.c: Fix devices using non-primary interface descriptor
A fair number of USB devices (keyboards in particular) use an
interface descriptor
other than the first available, making them non-functional currently.
To correct this, iterate through all available interface descriptors
until one with the correct class/subclass is found, then proceed to set the
configuration and setup the driver.
Tested on an ultimate hacking keyboard (UHK 60)
Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
smbios: avoid integer overflow when adding SMBIOS type 0 table
SeaBIOS implements the SMBIOS 2.1 entry point which is limited to a
maximum length of 0xffff. If the SMBIOS data received from QEMU is large
enough, then adding the type 0 table will cause integer overflow. This
results in fun behaviour such as KVM crash, or hangs in SeaBIOS.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Stefan Reiter [Mon, 27 Jul 2020 13:14:15 +0000 (15:14 +0200)]
virtio-scsi: fix boot prio detection by using correct lun
Commits
d6bdb85eb0 virtio-scsi: skip initializing non-bootable devices f82e82a5ab2 virtio-mmio: add support for scsi devices.
both use the lun value from tmpl_drv, which is always 0, instead of the
correct one passed as a separate parameter. This causes systems where
LUNs other than 0 are set as bootable, but 0 is not, to not boot.
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
Kevin O'Connor [Wed, 22 Jul 2020 15:31:40 +0000 (11:31 -0400)]
ldnoexec: Add script to remove ET_EXEC flag from intermediate build objects
Add a script to remove the ET_EXEC flag from the 16bit and "32bit
segmented" intermediate objects. This avoids build failures with some
linkers that will not allow linking these objects again.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Roman Bolshakov [Fri, 26 Jun 2020 18:06:58 +0000 (21:06 +0300)]
timer: Handle decrements of PIT counter
There's a fallback to PIT if TSC is not present but it doesn't work
properly. It prevents boot from floppy on isapc and 486 cpu [1][2].
SeaBIOS configures PIT in Mode 2. PIT counter is decremented in the mode
but timer_adjust_bits() thinks that the counter overflows and increases
32-bit tick counter on each detected "overflow". Invalid overflow
detection results in 55ms time advance (1 / 18.2Hz) on each read from
PIT counter. So all timers expire much faster and 5-second floppy
timeout expires in 83 real microseconds (or just a bit longer).
It can be fixed by making the counter recieved from PIT an increasing
value so it can be passed to timer_adjust_bits():
0, 1, 2 and up to 65535 and then the counter is re-loaded with 0.
Fixes: eac11944019 ("Unify pmtimer_read() and pittimer_read() code.") Reported-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Jason Andryuk [Wed, 24 Jun 2020 14:25:13 +0000 (10:25 -0400)]
serialio: Preserve Xen DebugOutputPort
xen_preinit() runs early and changes DebugOutputPort. qemu_preinit() runs
soon after. inb on DebugOutputPort doesn't work on Xen, so the check
will always fail and DebugOutputPort will be cleared to 0 disabling
output.
Quick exit the function when running on Xen to preserve the modified
DebugOutputPort.
Gerd Hoffmann [Mon, 25 May 2020 09:06:27 +0000 (11:06 +0200)]
pci: fix mmconfig support
The MODESEGMENT condition is backwards, with the effect that
mmconfig mode is not used to configure pci bars during POST.
Oops. Fix it.
The only real mode pci config space access seems to come from the
ipxe option rom initialiation. Which happens to work via mmconfig
because it runs in big real mode so this went unnoticed ...
Matt DeVillier [Sun, 24 May 2020 22:45:34 +0000 (17:45 -0500)]
boot: Fix logic for boot menu display
Commit c61193d3 [boot: Extend `etc/show-boot-menu`...] changed the
logic surrounding the use of show_boot_menu incorrectly, leading the
boot menu to be skipped by default with no way to override. Correct
the logic error so that show_boot_menu works as documented.
Test: build/boot SeaBIOS, verify boot menu option shown by default.
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Paul Menzel [Tue, 19 May 2020 21:39:42 +0000 (23:39 +0200)]
boot: Extend `etc/show-boot-menu` to configure skipping boot menu with only one device
Concerns were raised, that skipping the boot menu, if only one device is
present, might make debugging issues more difficult. So, extend the
current runtime configuration option `etc/show-boot-menu` to enable this
feature by setting it to 2.
Fixes: 29ee1fb8 ("Skip boot menu and timeout with only one boot device") Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Gerd Hoffmann [Tue, 24 Mar 2020 11:13:32 +0000 (12:13 +0100)]
acpi: add dsdt parser
Create a list of devices found in the DSDT table. Add helper functions
to find devices, walk the list and figure device informations like mmio
ranges and irqs.
Gerd Hoffmann [Fri, 6 Mar 2020 18:44:47 +0000 (19:44 +0100)]
virtio-mmio: add support to vp_*() functions
Add support for virtio-mmio to the vp_*() helper functions.
Both legacy and 1.0 virto-mmio versions are supported. They
are very simliar anyway, only the virtqueue initialization
is slightly different.
Gerd Hoffmann [Fri, 6 Mar 2020 13:34:18 +0000 (14:34 +0100)]
virtio-mmio: device probing and initialization.
Add virtio_mmio_setup_one() to setup virtio mmio devices. Add
vp_init_mmio() to initialize device struct. Because virtio-pci and
virtio-mmio are quite simliar we reuse the infrastructure we already
have for virtio-pci and just setup struct vp_cap for virtio-mmio.
Gerd Hoffmann [Thu, 7 May 2020 11:53:26 +0000 (13:53 +0200)]
qemu: check rtc presence before reading cpu count from cmos
Read month register which should never have a value larger than 12.
In case the read returns 0xff assume the rtc isn't there.
Don't try to read the cpu count from cmos without rtc.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Gerd Hoffmann [Fri, 8 May 2020 10:22:53 +0000 (12:22 +0200)]
qemu: rework e820 detection
Read e820 table from fw_cfg early. This avoids reading the cmos for ram
detection on modern qemu. It also simplifies the ram detection logic.
We stop doing ram detecion in two steps, so we don't have to worry about
the second step overwriting the setup done by the first step.
Some hardened gcc v9 compilers (such as the one in Ubuntu)
default this option which for seabios leads to emulation errors
when running in KVM (does not trigger in TCG) on older intel
chips of the Penryn generation (~2006-2008).
Stefan Berger [Mon, 30 Mar 2020 11:55:55 +0000 (07:55 -0400)]
tcgbios: Only write logs for PCRs that are in active PCR banks
Only write the logs for those PCRs that are in active PCR banks.
A PCR banks is assumed to be active if any of the BIOS relevant
PCRs 0 - 7 is enabled, thus pcrSelect[0] != 0.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Gerd Hoffmann [Mon, 23 Mar 2020 14:59:11 +0000 (15:59 +0100)]
pci: add mmconfig support
Add support for pci config space access via mmconfig bar. Enable for
qemu q35 chipset. Main advantage is that we need only one instead of
two io operations per config space access, which translates to one
instead of two vmexits for virtualization.
Paul Menzel [Wed, 4 Mar 2020 13:51:27 +0000 (14:51 +0100)]
std/tcg: Replace zero-length array with flexible-array member
GCC 10 gives the warnings below:
In file included from out/ccode32flat.o.tmp.c:54:
./src/tcgbios.c: In function 'tpm20_write_EfiSpecIdEventStruct':
./src/tcgbios.c:290:30: warning: array subscript '(<unknown>) + 4294967295' is outside the bounds of an interior zero-length array 'struct TCG_EfiSpecIdEventAlgorithmSize[0]' [-Wzero-length-bounds]
290 | event.hdr.digestSizes[count].algorithmId = be16_to_cpu(sel->hashAlg);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from ./src/tcgbios.c:22,
from out/ccode32flat.o.tmp.c:54:
./src/std/tcg.h:527:7: note: while referencing 'digestSizes'
527 | } digestSizes[0];
| ^~~~~~~~~~~
In file included from out/ccode32flat.o.tmp.c:54:
./src/tcgbios.c:291:30: warning: array subscript '(<unknown>) + 4294967295' is outside the bounds of an interior zero-length array 'struct TCG_EfiSpecIdEventAlgorithmSize[0]' [-Wzero-length-bounds]
291 | event.hdr.digestSizes[count].digestSize = hsize;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from ./src/tcgbios.c:22,
from out/ccode32flat.o.tmp.c:54:
./src/std/tcg.h:527:7: note: while referencing 'digestSizes'
527 | } digestSizes[0];
| ^~~~~~~~~~~
[Description copied from Gustavo A. R. Silva <gustavo@embeddedor.com>
from his Linux kernel commits.]
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array
member [1][2], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.
Also, notice that, dynamic memory allocations won't be affected by
this change:
"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]