public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH mmotm] fix broken bootup on 32-bit
@ 2011-03-05 12:42 Hugh Dickins
  2011-03-05 19:41 ` [PATCH] lib: vsprintf: 32-bit put_dec() fixes Michal Nazarewicz
       [not found] ` <AANLkTikDssqCD-f1E=i-HvKEAMnBMtD5qJq-k5Q3FJKC@mail.gmail.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Hugh Dickins @ 2011-03-05 12:42 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Nazarewicz, Douglas W. Jones, Denis Vlasenko, linux-kernel

mmotm 2011-03-02-16-52 is utterly broken on 32-bit: panics at boot
with "Couldn't register console driver", and preceding warnings don't
even print their line numbers... which leads to the vsprintf changes.

Comparing the 32-bit version of put_dec() against mod7_put_dec()
in tools/put-dec/put-dec-test.c (ah, it is useful after all!) shows
that someone has decided to invert the ordering of pairs of lines
in the kernel version of the algorithm, making a nonsense of it.

Switch them back, and put in the conditionals from mod7_put_dec()
(absent from mod6_put_dec??): my guess is that less work is better.

My testing has gone no further than booting up, and checking that
the numbers in /proc/partitions come out right (which they didn't
at my first attempt, when I thought just a one-liner was needed).

Signed-off-by: Hugh Dickins <hughd@google.com>
---
Diffed to go on the top of mmotm, but can be applied after
lib-vsprintf-optimised-put_dec-function-fix.patch

 lib/vsprintf.c |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

--- mmotm/lib/vsprintf.c	2011-03-03 15:43:57.000000000 -0800
+++ linux/lib/vsprintf.c	2011-03-05 03:37:14.000000000 -0800
@@ -310,22 +310,29 @@ char *put_dec(char *buf, unsigned long l
 
 	q  = 656 * d3 + 7296 * d2 + 5536 * d1 + (n & 0xFFFF);
 
-	q  = q / 10000;
 	buf = put_dec_full4(buf, q % 10000);
+	q  = q / 10000;
 
 	d1 = q + 7671 * d3 + 9496 * d2 + 6 * d1;
-	q  = d1 / 10000;
-	buf = put_dec_full4(buf, d1 % 10000);
-
-	d2 = q + 4749 * d3 + 42 * d2;
-	q  = d2 / 10000;
-	buf = put_dec_full4(buf, d2 % 10000);
-
-	d3 = q + 281 * d3;
-	q  = d3 / 10000;
-	buf = put_dec_full4(buf, d3 % 10000);
-
-	buf = put_dec_full4(buf, q);
+	if (d1) {
+		buf = put_dec_full4(buf, d1 % 10000);
+		q  = d1 / 10000;
+
+		d2 = q + 4749 * d3 + 42 * d2;
+		if (d2) {
+			buf = put_dec_full4(buf, d2 % 10000);
+			q  = d2 / 10000;
+
+			d3 = q + 281 * d3;
+			if (d3) {
+				buf = put_dec_full4(buf, d3 % 10000);
+				q  = d3 / 10000;
+
+				if (q)
+					buf = put_dec_full4(buf, q);
+			}
+		}
+	}
 
 	while (buf[-1] == '0')
 		--buf;

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

end of thread, other threads:[~2011-03-05 19:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-05 12:42 [PATCH mmotm] fix broken bootup on 32-bit Hugh Dickins
2011-03-05 19:41 ` [PATCH] lib: vsprintf: 32-bit put_dec() fixes Michal Nazarewicz
     [not found] ` <AANLkTikDssqCD-f1E=i-HvKEAMnBMtD5qJq-k5Q3FJKC@mail.gmail.com>
2011-03-05 19:49   ` [PATCH mmotm] fix broken bootup on 32-bit Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox