Skip to contentSkip to conversation

zlib: define get_unaligned16() only when used

PATCH In review Lukas Bulwahn 5 participants 6 messages Nov 24, 2020 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zlib: define get_unaligned16() only when used

Since commit acaab7335bd6 ("lib/zlib: remove outdated and incorrect pre-increment optimization"), get_unaligned16() is only used when !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Hence, make CC=clang W=1 warns:

lib/zlib_inflate/inffast.c:20:1:
warning: unused function 'get_unaligned16' [-Wunused-function]

Define get_unaligned16() only when it is actually used.

---
applies cleanly on current master and next-20201124

Jann, please ack.
Andrew, please pick this minor non-urgent clean-up patch.

 lib/zlib_inflate/inffast.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/zlib_inflate/inffast.c +3 -1
index ed1f3df27260..ca66d9008228 100644
@@ -15,7 +15,8 @@ union uu {
 	unsigned char b[2];
 };
 
-/* Endian independed version */
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+/* Endian independent version */
 static inline unsigned short
 get_unaligned16(const unsigned short *p)
 {
@@ -26,6 +27,7 @@ get_unaligned16(const unsigned short *p)
 	mm.b[1] = b[1];
 	return mm.us;
 }
+#endif
 
 /*
    Decode literal, length, and distance codes and write out the resulting
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Lukas Bulwahn

Since commit acaab7335bd6 ("lib/zlib: remove outdated and incorrect pre-increment optimization"), get_unaligned16() is only used when !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Quoted 8 lines

Hence, make CC=clang W=1 warns:

lib/zlib_inflate/inffast.c:20:1:
warning: unused function 'get_unaligned16' [-Wunused-function]

Define get_unaligned16() only when it is actually used.

AFAICS a nicer option would be to "#include <asm/unaligned.h>" and then use "get_unaligned", which should automatically do the right thing everywhere and remove the need for defining get_unaligned16() and checking CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS entirely?

#2 lore raw
Quoted 9 lines · Jann Horn
Quoted 9 lines

Since commit acaab7335bd6 ("lib/zlib: remove outdated and incorrect pre-increment optimization"), get_unaligned16() is only used when !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Hence, make CC=clang W=1 warns:

lib/zlib_inflate/inffast.c:20:1:
warning: unused function 'get_unaligned16' [-Wunused-function]

Quoted 8 lines
Quoted 3 lines

Define get_unaligned16() only when it is actually used.

AFAICS a nicer option would be to "#include <asm/unaligned.h>" and then use "get_unaligned", which should automatically do the right thing everywhere and remove the need for defining get_unaligned16() and checking CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS entirely?

Yes, that is the right thing to do.

#3 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Jann Horn
Quoted 11 lines

Since commit acaab7335bd6 ("lib/zlib: remove outdated and incorrect pre-increment optimization"), get_unaligned16() is only used when !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Hence, make CC=clang W=1 warns:

lib/zlib_inflate/inffast.c:20:1:
warning: unused function 'get_unaligned16' [-Wunused-function]

Define get_unaligned16() only when it is actually used.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

AFAICS a nicer option would be to "#include <asm/unaligned.h>" and then use "get_unaligned", which should automatically do the right thing everywhere and remove the need for defining get_unaligned16() and checking CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS entirely?

Yes, that is the right thing to do.

It's possible that this didn't work when the code was originally added:
The decompressor functions are called from the compressed boot path, which is a bit limited regarding which headers it can include, at least on some architectures.

I would recommend test-building this for all architectures that include ../../../../lib/decompress_inflate.c from their boot code.

Arnd

#4 lore raw
Quoted 23 lines · Arnd Bergmann
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Jann Horn
Quoted 11 lines

Since commit acaab7335bd6 ("lib/zlib: remove outdated and incorrect pre-increment optimization"), get_unaligned16() is only used when !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Hence, make CC=clang W=1 warns:

lib/zlib_inflate/inffast.c:20:1:
warning: unused function 'get_unaligned16' [-Wunused-function]

Define get_unaligned16() only when it is actually used.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

AFAICS a nicer option would be to "#include <asm/unaligned.h>" and then use "get_unaligned", which should automatically do the right thing everywhere and remove the need for defining get_unaligned16() and checking CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS entirely?

Yes, that is the right thing to do.

Quoted 8 lines

It's possible that this didn't work when the code was originally added:
The decompressor functions are called from the compressed boot path, which is a bit limited regarding which headers it can include, at least on some architectures.

I would recommend test-building this for all architectures that include ../../../../lib/decompress_inflate.c from their boot code.

Jann, Christoph, Arnd, thanks for the advice. I will start to look into this immediately.

Lukas

#5 lore raw
In reply to Arnd Bergmann

RnJvbTogQXJuZCBCZXJnbWFubg0KPiBTZW50OiAyNCBOb3ZlbWJlciAyMDIwIDExOjU3DQo+IA0K PiBPbiBUdWUsIE5vdiAyNCwgMjAyMCBhdCAxMjo1MSBQTSBDaHJpc3RvcGggSGVsbHdpZyA8aGNo QGluZnJhZGVhZC5vcmc+IHdyb3RlOg0KPiA+IE9uIFR1ZSwgTm92IDI0LCAyMDIwIGF0IDEyOjA4 OjQwUE0gKzAxMDAsIEphbm4gSG9ybiB3cm90ZToNCj4gPiA+ID4gU2luY2UgY29tbWl0IGFjYWFi NzMzNWJkNiAoImxpYi96bGliOiByZW1vdmUgb3V0ZGF0ZWQgYW5kIGluY29ycmVjdA0KPiA+ID4g PiBwcmUtaW5jcmVtZW50IG9wdGltaXphdGlvbiIpLCBnZXRfdW5hbGlnbmVkMTYoKSBpcyBvbmx5 IHVzZWQgd2hlbg0KPiA+ID4gPiAhQ09ORklHX0hBVkVfRUZGSUNJRU5UX1VOQUxJR05FRF9BQ0NF U1MuDQo+ID4gPiA+DQo+ID4gPiA+IEhlbmNlLCBtYWtlIENDPWNsYW5nIFc9MSB3YXJuczoNCj4g PiA+ID4NCj4gPiA+ID4gICBsaWIvemxpYl9pbmZsYXRlL2luZmZhc3QuYzoyMDoxOg0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