Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/decompress: use designated initializers for struct compress_format

Switch 'compressed_formats[]' to the more modern and flexible designated
initializers. This improves readability and allows struct fields to be
reordered. Also use a more concise sentinel marker.

Remove the curly braces around the for loop while we're at it.

No functional changes intended.

Link: https://lkml.kernel.org/r/20250910232350.1308206-2-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Thorsten Blum and committed by
Andrew Morton
04ae01a8 5b86af1d

+10 -11
+10 -11
lib/decompress.c
··· 49 49 }; 50 50 51 51 static const struct compress_format compressed_formats[] __initconst = { 52 - { {0x1f, 0x8b}, "gzip", gunzip }, 53 - { {0x1f, 0x9e}, "gzip", gunzip }, 54 - { {0x42, 0x5a}, "bzip2", bunzip2 }, 55 - { {0x5d, 0x00}, "lzma", unlzma }, 56 - { {0xfd, 0x37}, "xz", unxz }, 57 - { {0x89, 0x4c}, "lzo", unlzo }, 58 - { {0x02, 0x21}, "lz4", unlz4 }, 59 - { {0x28, 0xb5}, "zstd", unzstd }, 60 - { {0, 0}, NULL, NULL } 52 + { .magic = {0x1f, 0x8b}, .name = "gzip", .decompressor = gunzip }, 53 + { .magic = {0x1f, 0x9e}, .name = "gzip", .decompressor = gunzip }, 54 + { .magic = {0x42, 0x5a}, .name = "bzip2", .decompressor = bunzip2 }, 55 + { .magic = {0x5d, 0x00}, .name = "lzma", .decompressor = unlzma }, 56 + { .magic = {0xfd, 0x37}, .name = "xz", .decompressor = unxz }, 57 + { .magic = {0x89, 0x4c}, .name = "lzo", .decompressor = unlzo }, 58 + { .magic = {0x02, 0x21}, .name = "lz4", .decompressor = unlz4 }, 59 + { .magic = {0x28, 0xb5}, .name = "zstd", .decompressor = unzstd }, 60 + { /* sentinel */ } 61 61 }; 62 62 63 63 decompress_fn __init decompress_method(const unsigned char *inbuf, long len, ··· 73 73 74 74 pr_debug("Compressed data magic: %#.2x %#.2x\n", inbuf[0], inbuf[1]); 75 75 76 - for (cf = compressed_formats; cf->name; cf++) { 76 + for (cf = compressed_formats; cf->name; cf++) 77 77 if (!memcmp(inbuf, cf->magic, 2)) 78 78 break; 79 79 80 - } 81 80 if (name) 82 81 *name = cf->name; 83 82 return cf->decompressor;