mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Rodgman <dave.rodgman@arm.com>
To: Dave Rodgman <dave.rodgman@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"markus@oberhumer.com" <markus@oberhumer.com>,
	"minchan@kernel.org" <minchan@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: nd <nd@arm.com>
Subject: [PATCH] lib/lzo: fix alignment bug in lzo-rle
Date: Thu, 12 Sep 2019 14:55:08 +0000	[thread overview]
Message-ID: <20190912145502.35229-1-dave.rodgman@arm.com> (raw)

Fix an unaligned access which breaks on platforms where this is not
permitted (e.g., Sparc).

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
---
 lib/lzo/lzo1x_compress.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c
index 4525fb094844..3ea7b93596c6 100644
--- a/lib/lzo/lzo1x_compress.c
+++ b/lib/lzo/lzo1x_compress.c
@@ -82,17 +82,19 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
 					ALIGN((uintptr_t)ir, 4)) &&
 					(ir < limit) && (*ir == 0))
 				ir++;
-			for (; (ir + 4) <= limit; ir += 4) {
-				dv = *((u32 *)ir);
-				if (dv) {
+			if (IS_ALIGNED((uintptr_t)ir, 4)) {
+				for (; (ir + 4) <= limit; ir += 4) {
+					dv = *((u32 *)ir);
+					if (dv) {
 #  if defined(__LITTLE_ENDIAN)
-					ir += __builtin_ctz(dv) >> 3;
+						ir += __builtin_ctz(dv) >> 3;
 #  elif defined(__BIG_ENDIAN)
-					ir += __builtin_clz(dv) >> 3;
+						ir += __builtin_clz(dv) >> 3;
 #  else
 #    error "missing endian definition"
 #  endif
-					break;
+						break;
+					}
 				}
 			}
 #endif
-- 
2.23.0


                 reply	other threads:[~2019-09-12 14:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190912145502.35229-1-dave.rodgman@arm.com \
    --to=dave.rodgman@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus@oberhumer.com \
    --cc=minchan@kernel.org \
    --cc=nd@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®