All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rene Herman <rene.herman@gmail.com>
To: Jeremy Fitzhardinge <jeremy@goop.org>, Andrew Morton <akpm@osdl.org>
Cc: Zachary Amsden <zach@vmware.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] romsignature/checksum cleanup
Date: Mon, 08 Jan 2007 03:48:43 +0100	[thread overview]
Message-ID: <45A1B10B.5080005@gmail.com> (raw)
In-Reply-To: <45A136CC.60007@goop.org>

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

On 01/07/2007 07:07 PM, Jeremy Fitzhardinge wrote:

> Rene Herman wrote:

>> Doing the set_fs() and pagefault_{disable,enable} calls for every
>> single byte during the checksum seems rather silly.
> 
> Why?

Because it makes for dumb code. But oh well, given that it all compiles 
to basically nothing I guess I'll stop objecting.

Andrew: The attached removes the assumption that if the first page of an 
ISA ROM is mapped, it'll all be mapped. This'll also stop people reading 
this code from wondering if they're looking at a bug.

This replaces "romsignature-checksum-cleanup.patch" in current -mm.

Signed-off-by: Rene Herman <rene.herman@gmail.com>
Not-strongly-objected-to-by: Jeremy Fitzhardinge <jeremy@goop.org>

Rene.

[-- Attachment #2: probe_kernel_address.diff --]
[-- Type: text/plain, Size: 2058 bytes --]

diff --git a/arch/i386/kernel/e820.c b/arch/i386/kernel/e820.c
index f391abc..8b8741f 100644
--- a/arch/i386/kernel/e820.c
+++ b/arch/i386/kernel/e820.c
@@ -156,29 +156,31 @@ static struct resource standard_io_resou
 	.flags	= IORESOURCE_BUSY | IORESOURCE_IO
 } };
 
-static int romsignature(const unsigned char *x)
+#define ROMSIGNATURE 0xaa55
+
+static int __init romsignature(const unsigned char *rom)
 {
+	const unsigned short * const ptr = (const unsigned short *)rom;
 	unsigned short sig;
-	int ret = 0;
-	if (probe_kernel_address((const unsigned short *)x, sig) == 0)
-		ret = (sig == 0xaa55);
-	return ret;
+	
+	return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
 }
 
-static int __init romchecksum(unsigned char *rom, unsigned long length)
+static int __init romchecksum(const unsigned char *rom, unsigned long length)
 {
-	unsigned char *p, sum = 0;
+	unsigned char sum, c;
 
-	for (p = rom; p < rom + length; p++)
-		sum += *p;
-	return sum == 0;
+	for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
+		sum += c;
+	return !length && !sum;
 }
 
 static void __init probe_roms(void)
 {
+	const unsigned char *rom;
 	unsigned long start, length, upper;
-	unsigned char *rom;
-	int	      i;
+	unsigned char c;
+	int i;
 
 	/* video rom */
 	upper = adapter_rom_resources[0].start;
@@ -189,8 +191,11 @@ static void __init probe_roms(void)
 
 		video_rom_resource.start = start;
 
+		if (probe_kernel_address(rom + 2, c) != 0)
+			continue;
+
 		/* 0 < length <= 0x7f * 512, historically */
-		length = rom[2] * 512;
+		length = c * 512;
 
 		/* if checksum okay, trust length byte */
 		if (length && romchecksum(rom, length))
@@ -224,8 +229,11 @@ static void __init probe_roms(void)
 		if (!romsignature(rom))
 			continue;
 
+		if (probe_kernel_address(rom + 2, c) != 0)
+			continue;
+
 		/* 0 < length <= 0x7f * 512, historically */
-		length = rom[2] * 512;
+		length = c * 512;
 
 		/* but accept any length that fits if checksum okay */
 		if (!length || start + length > upper || !romchecksum(rom, length))

      reply	other threads:[~2007-01-08  2:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-24 21:15 [PATCH] romsignature/checksum cleanup Rene Herman
2006-12-25  0:53 ` Rene Herman
2006-12-27  0:31   ` Rusty Russell
2006-12-27  0:45     ` Rene Herman
2006-12-28  0:32     ` Zachary Amsden
2007-01-02 20:01       ` Rene Herman
2007-01-05 23:22         ` Jeremy Fitzhardinge
2007-01-06  3:46           ` Rene Herman
2007-01-07  8:59             ` Jeremy Fitzhardinge
2007-01-07  9:02               ` Rene Herman
2007-01-07 10:20                 ` Jeremy Fitzhardinge
2007-01-07 10:47                   ` Rene Herman
2007-01-07 18:07                     ` Jeremy Fitzhardinge
2007-01-08  2:48                       ` Rene Herman [this message]

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=45A1B10B.5080005@gmail.com \
    --to=rene.herman@gmail.com \
    --cc=akpm@osdl.org \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=zach@vmware.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.