linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zlib: define get_unaligned16() only when used
@ 2020-11-24 10:40 Lukas Bulwahn
  2020-11-24 11:08 ` Jann Horn
  0 siblings, 1 reply; 6+ messages in thread
From: Lukas Bulwahn @ 2020-11-24 10:40 UTC (permalink / raw)
  To: Jann Horn, Andrew Morton
  Cc: Arnd Bergmann, Tom Rix, Nathan Chancellor, Nick Desaulniers,
	clang-built-linux, kernel-janitors, linux-kernel, 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.

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.

Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
---
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(-)

diff --git a/lib/zlib_inflate/inffast.c b/lib/zlib_inflate/inffast.c
index ed1f3df27260..ca66d9008228 100644
--- a/lib/zlib_inflate/inffast.c
+++ b/lib/zlib_inflate/inffast.c
@@ -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
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] zlib: define get_unaligned16() only when used
  2020-11-24 10:40 [PATCH] zlib: define get_unaligned16() only when used Lukas Bulwahn
@ 2020-11-24 11:08 ` Jann Horn
  2020-11-24 11:50   ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: Jann Horn @ 2020-11-24 11:08 UTC (permalink / raw)
  To: Lukas Bulwahn
  Cc: Andrew Morton, Arnd Bergmann, Tom Rix, Nathan Chancellor,
	Nick Desaulniers, clang-built-linux, kernel-janitors,
	kernel list

On Tue, Nov 24, 2020 at 11:40 AM Lukas Bulwahn <lukas.bulwahn@gmail.com> wrote:
> 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.
>
> Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] zlib: define get_unaligned16() only when used
  2020-11-24 11:08 ` Jann Horn
@ 2020-11-24 11:50   ` Christoph Hellwig
  2020-11-24 11:56     ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2020-11-24 11:50 UTC (permalink / raw)
  To: Jann Horn
  Cc: Lukas Bulwahn, Andrew Morton, Arnd Bergmann, Tom Rix,
	Nathan Chancellor, Nick Desaulniers, clang-built-linux,
	kernel-janitors, kernel list

On Tue, Nov 24, 2020 at 12:08:40PM +0100, Jann Horn wrote:
> > 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.
> >
> > Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> 
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] zlib: define get_unaligned16() only when used
  2020-11-24 11:50   ` Christoph Hellwig
@ 2020-11-24 11:56     ` Arnd Bergmann
  2020-11-24 12:00       ` Lukas Bulwahn
  2020-11-24 13:31       ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2020-11-24 11:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jann Horn, Lukas Bulwahn, Andrew Morton, Arnd Bergmann, Tom Rix,
	Nathan Chancellor, Nick Desaulniers, clang-built-linux,
	kernel-janitors, kernel list

On Tue, Nov 24, 2020 at 12:51 PM Christoph Hellwig <hch@infradead.org> wrote:
> On Tue, Nov 24, 2020 at 12:08:40PM +0100, Jann Horn wrote:
> > > 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.
> > >
> > > Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> >
> > 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] zlib: define get_unaligned16() only when used
  2020-11-24 11:56     ` Arnd Bergmann
@ 2020-11-24 12:00       ` Lukas Bulwahn
  2020-11-24 13:31       ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Lukas Bulwahn @ 2020-11-24 12:00 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Christoph Hellwig, Jann Horn, Andrew Morton, Arnd Bergmann,
	Tom Rix, Nathan Chancellor, Nick Desaulniers, clang-built-linux,
	kernel-janitors, kernel list

On Tue, Nov 24, 2020 at 12:56 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> On Tue, Nov 24, 2020 at 12:51 PM Christoph Hellwig <hch@infradead.org> wrote:
> > On Tue, Nov 24, 2020 at 12:08:40PM +0100, Jann Horn wrote:
> > > > 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.
> > > >
> > > > Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> > >
> > > 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.
>

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

Lukas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] zlib: define get_unaligned16() only when used
  2020-11-24 11:56     ` Arnd Bergmann
  2020-11-24 12:00       ` Lukas Bulwahn
@ 2020-11-24 13:31       ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2020-11-24 13:31 UTC (permalink / raw)
  To: 'Arnd Bergmann', Christoph Hellwig
  Cc: Jann Horn, Lukas Bulwahn, Andrew Morton, Arnd Bergmann, Tom Rix,
	Nathan Chancellor, Nick Desaulniers, clang-built-linux,
	kernel-janitors, kernel list

From: Arnd Bergmann
> Sent: 24 November 2020 11:57
> 
> On Tue, Nov 24, 2020 at 12:51 PM Christoph Hellwig <hch@infradead.org> wrote:
> > On Tue, Nov 24, 2020 at 12:08:40PM +0100, Jann Horn wrote:
> > > > 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.
> > > >
> > > > Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> > >
> > > 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.

Plausibly it could include a different header that defined the required
items for those builds.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-24 13:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 10:40 [PATCH] zlib: define get_unaligned16() only when used Lukas Bulwahn
2020-11-24 11:08 ` Jann Horn
2020-11-24 11:50   ` Christoph Hellwig
2020-11-24 11:56     ` Arnd Bergmann
2020-11-24 12:00       ` Lukas Bulwahn
2020-11-24 13:31       ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).