[PATCH] drivers/pci/hotplug/*: fix polling loops

From: Marcin Slusarz <marcin.slusarz@gmail.com>

bug in drivers/pci/hotplug/ibmphp_hpc.c - CMD_COMPLETE_TOUT_SEC wasn't treated as seconds (timeout was 0.6s instead 60s as comment say)

Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

Index: linux-kj/drivers/pci/hotplug/ibmphp_hpc.c
===================================================================
--- linux-kj.orig/drivers/pci/hotplug/ibmphp_hpc.c	2006-01-18 02:21:26.000000000 +0300
+++ linux-kj/drivers/pci/hotplug/ibmphp_hpc.c	2006-01-18 16:46:04.000000000 +0300
@@ -150,11 +150,11 @@ void __init ibmphp_hpc_initvars (void)
 static u8 i2c_ctrl_read (struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 index)
 {
 	u8 status;
-	int i;
 	void __iomem *wpg_addr;	// base addr + offset
 	unsigned long wpg_data;	// data to/from WPG LOHI format
 	unsigned long ultemp;
 	unsigned long data;	// actual data HILO format
+	unsigned long end_time;
 
 	debug_polling ("%s - Entry WPGBbar[%p] index[%x] \n", __FUNCTION__, WPGBbar, index);
 
@@ -204,33 +204,31 @@ static u8 i2c_ctrl_read (struct controll
 
 	//--------------------------------------------------------------------
 	// READ - step 4 : wait until start operation bit clears
-	i = CMD_COMPLETE_TOUT_SEC;
-	while (i) {
+	end_time = jiffies + msecs_to_jiffies(CMD_COMPLETE_TOUT_SEC * 1000);
+	while (time_before(jiffies, end_time)) {
 		msleep(10);
 		wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET;
 		wpg_data = readl (wpg_addr);
 		data = swab32 (wpg_data);
 		if (!(data & WPG_I2CMCNTL_STARTOP_MASK))
 			break;
-		i--;
 	}
-	if (i == 0) {
+	if (data & WPG_I2CMCNTL_STARTOP_MASK) {
 		debug ("%s - Error : WPG timeout\n", __FUNCTION__);
 		return HPC_ERROR;
 	}
 	//--------------------------------------------------------------------
 	// READ - step 5 : read I2C status register
-	i = CMD_COMPLETE_TOUT_SEC;
-	while (i) {
+	end_time = jiffies + msecs_to_jiffies(CMD_COMPLETE_TOUT_SEC * 1000);
+	while (time_before(jiffies, end_time)) {
 		msleep(10);
 		wpg_addr = WPGBbar + WPG_I2CSTAT_OFFSET;
 		wpg_data = readl (wpg_addr);
 		data = swab32 (wpg_data);
 		if (HPC_I2CSTATUS_CHECK (data))
 			break;
-		i--;
 	}
-	if (i == 0) {
+	if (!(HPC_I2CSTATUS_CHECK (data))) {
 		debug ("ctrl_read - Exit Error:I2C timeout\n");
 		return HPC_ERROR;
 	}
@@ -315,34 +313,32 @@ static u8 i2c_ctrl_write (struct control
 
 	//--------------------------------------------------------------------
 	// WRITE - step 4 : wait until start operation bit clears
-	i = CMD_COMPLETE_TOUT_SEC;
-	while (i) {
+	end_time = jiffies + msecs_to_jiffies(CMD_COMPLETE_TOUT_SEC * 1000);
+	while (time_before(jiffies, end_time)) {
 		msleep(10);
 		wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET;
 		wpg_data = readl (wpg_addr);
 		data = swab32 (wpg_data);
 		if (!(data & WPG_I2CMCNTL_STARTOP_MASK))
 			break;
-		i--;
 	}
-	if (i == 0) {
+	if (data & WPG_I2CMCNTL_STARTOP_MASK) {
 		debug ("%s - Exit Error:WPG timeout\n", __FUNCTION__);
 		rc = HPC_ERROR;
 	}
 
 	//--------------------------------------------------------------------
 	// WRITE - step 5 : read I2C status register
-	i = CMD_COMPLETE_TOUT_SEC;
-	while (i) {
+	end_time = jiffies + msecs_to_jiffies(CMD_COMPLETE_TOUT_SEC * 1000);
+	while (time_before(jiffies, end_time)) {
 		msleep(10);
 		wpg_addr = WPGBbar + WPG_I2CSTAT_OFFSET;
 		wpg_data = readl (wpg_addr);
 		data = swab32 (wpg_data);
 		if (HPC_I2CSTATUS_CHECK (data))
 			break;
-		i--;
 	}
-	if (i == 0) {
+	if (!(HPC_I2CSTATUS_CHECK (data))) {
 		debug ("ctrl_read - Error : I2C timeout\n");
 		rc = HPC_ERROR;
 	}
Index: linux-kj/drivers/pci/hotplug/shpchp_hpc.c
===================================================================
--- linux-kj.orig/drivers/pci/hotplug/shpchp_hpc.c	2006-01-18 02:21:26.000000000 +0300
+++ linux-kj/drivers/pci/hotplug/shpchp_hpc.c	2006-01-18 16:46:04.000000000 +0300
@@ -300,7 +300,7 @@ static int shpc_write_cmd(struct slot *s
 	u16 cmd_status;
 	int retval = 0;
 	u16 temp_word;
-	int i;
+	unsigned long end_time;
 
 	DBG_ENTER_ROUTINE 
 	
@@ -309,7 +309,8 @@ static int shpc_write_cmd(struct slot *s
 		return -1;
 	}
 
-	for (i = 0; i < 10; i++) {
+	end_time = jiffies + msecs_to_jiffies(1000);
+	while (time_before(jiffies, end_time)) {
 		cmd_status = readw(php_ctlr->creg + CMD_STATUS);
 		
 		if (!(cmd_status & 0x1))
