From 15b4b4068540dd6bfbf9ffd0aef1173ba3630e7b Mon Sep 17 00:00:00 2001
From: Bartlomiej Zolnierkiewicz <bzolnier@trik.(none)>
Date: Fri, 29 Oct 2004 20:24:59 +0200
Subject: [PATCH] [ide] PIO bugfix

We need to k[un]map_atomic() the current page not the first page
of the scatterlist segment.  Fixes OOPS when using HIGHMEM.

Big thanks to Randy Dunlap for a lot of debugging/testing.

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-taskfile.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index eadcb964a0db..8d742b8d080d 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -274,14 +274,20 @@ static void ide_pio_sector(ide_drive_t *drive, unsigned int write)
 #ifdef CONFIG_HIGHMEM
 	unsigned long flags;
 #endif
+	unsigned int offset;
 	u8 *buf;
 
 	page = sg[hwif->cursg].page;
+	offset = sg[hwif->cursg].offset + hwif->cursg_ofs * SECTOR_SIZE;
+
+	/* get the current page and offset */
+	page = nth_page(page, (offset >> PAGE_SHIFT));
+	offset %= PAGE_SIZE;
+
 #ifdef CONFIG_HIGHMEM
 	local_irq_save(flags);
 #endif
-	buf = kmap_atomic(page, KM_BIO_SRC_IRQ) +
-	      sg[hwif->cursg].offset + (hwif->cursg_ofs * SECTOR_SIZE);
+	buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
 
 	hwif->nleft--;
 	hwif->cursg_ofs++;
-- 
2.30.9