Skip to content

Commit 04ae01a

Browse files
tobluxakpm00
authored andcommitted
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/[email protected] Signed-off-by: Thorsten Blum <[email protected]> Reviewed-by: Kuan-Wei Chiu <[email protected]> Cc: David Sterba <[email protected]> Cc: Nick Terrell <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5b86af1 commit 04ae01a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/decompress.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ struct compress_format {
4949
};
5050

5151
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 */ }
6161
};
6262

6363
decompress_fn __init decompress_method(const unsigned char *inbuf, long len,
@@ -73,11 +73,10 @@ decompress_fn __init decompress_method(const unsigned char *inbuf, long len,
7373

7474
pr_debug("Compressed data magic: %#.2x %#.2x\n", inbuf[0], inbuf[1]);
7575

76-
for (cf = compressed_formats; cf->name; cf++) {
76+
for (cf = compressed_formats; cf->name; cf++)
7777
if (!memcmp(inbuf, cf->magic, 2))
7878
break;
7979

80-
}
8180
if (name)
8281
*name = cf->name;
8382
return cf->decompressor;

0 commit comments

Comments
 (0)