Skip to contentSkip to conversation

never called printk statement in ide-taskfile.c::wait_drive_not_busy

PATCH In review Masatake YAMATO 3 participants 6 messages Jun 5, 2007 – Jun 21, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 never called printk statement in ide-taskfile.c::wait_drive_not_busy

Hi,

Patches appended to this mail fixes a bug explained below. There are two ways to fix the bug. PLEASE CHOOSE BETTER ONE.

Look at wait_drive_not_busy in drivers/ide/ide-taskfile.c:

    static u8 wait_drive_not_busy(ide_drive_t *drive)
    {
	    ide_hwif_t *hwif = HWIF(drive);
	    int retries = 100;
	    u8 stat;

	    /*
	     * Last sector was transfered, wait until drive is ready.
	     * This can take up to 10 usec, but we will wait max 1 ms
	     * (drive_cmd_intr() waits that long).
	     */
	    while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
		    udelay(10);

	    if (!retries)
		    printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);

	    return stat;
    }

printk' is never called because retries' never holds zero at the outside of while' loop: when retries' holds zero at the while's loop condition, `retries' will hold -1 at the if condition.

I'm not on this mailing list, so add my address to Cc: when you reply to me.

drivers/ide/ide-taskfile.c +1 -1
index 30175c7..a74df05 100644
@@ -246,7 +246,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	 * This can take up to 10 usec, but we will wait max 1 ms
 	 * (drive_cmd_intr() waits that long).
 	 */
-	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
+	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && --retries)
 		udelay(10);
 
 	if (!retries)
drivers/ide/ide-taskfile.c +1 -1
index 30175c7..5e05311 100644
@@ -249,7 +249,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
 		udelay(10);
 
-	if (!retries)
+	if (retries < 0)
 		printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
 
 	return stat;
#1 lore raw

drivers/ide/ide-taskfile.c static u8 wait_drive_not_busy(ide_drive_t *drive) · line 252

Quoted 10 lines · Masatake YAMATO
drivers/ide/ide-taskfile.c +1 -1
index 30175c7..5e05311 100644
@@ -249,7 +249,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
 		udelay(10);
 
-	if (!retries)
+	if (retries < 0)

if (stat & BUSY_STAT)

Quoted 3 lines
drivers/ide/ide-taskfile.c +0 -0
 		printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
 
 	return stat;
#2 lore raw
Quoted 9 lines · Masatake YAMATO
Quoted 8 lines
drivers/ide/ide-taskfile.c +0 -0
index 30175c7..5e05311 100644
@@ -249,7 +249,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
 		udelay(10);
 
Quoted 7 lines

drivers/ide/ide-taskfile.c static u8 wait_drive_not_busy(ide_drive_t *drive) · line 252

Quoted 2 lines
drivers/ide/ide-taskfile.c +1 -1
-	if (!retries)
+	if (retries < 0)

if (stat & BUSY_STAT)

Quoted 2 lines
drivers/ide/ide-taskfile.c +0 -0
 		printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
 

Oh, yes.
Giving `retries' both roles: loop counter and condition flag for logging may not good.

    for (retries = 0; retries < 100; retries++)
    {
	    if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT)
	       break;

	    udelay(10);
    }


    if (stat & BUSY_STAT)
	    printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);

Masatake YAMATO

#3 lore raw

Hi,

Quoted 22 lines · Masatake YAMATO
Quoted 9 lines · Masatake YAMATO
Quoted 8 lines
drivers/ide/ide-taskfile.c +0 -0
index 30175c7..5e05311 100644
@@ -249,7 +249,7 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
 		udelay(10);
 
Quoted 7 lines

drivers/ide/ide-taskfile.c static u8 wait_drive_not_busy(ide_drive_t *drive) · line 252

Quoted 2 lines
drivers/ide/ide-taskfile.c +1 -1
-	if (!retries)
+	if (retries < 0)

if (stat & BUSY_STAT)

Quoted 2 lines
drivers/ide/ide-taskfile.c +0 -0
 		printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
 

Oh, yes.
Giving `retries' both roles: loop counter and condition flag for logging may not good.

Quoted 11 lines
    for (retries = 0; retries < 100; retries++)
    {
	    if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT)
	       break;

	    udelay(10);
    }


    if (stat & BUSY_STAT)
	    printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);

Please re-submit this fix in the form of a patch so I can merge it.

Thanks,
Bart

#4 lore raw
Quoted 1 line

Please re-submit this fix in the form of a patch so I can merge it.

Here it is.

drivers/ide/ide-taskfile.c +8 -4
index 30175c7..aa06daf 100644
@@ -238,7 +238,7 @@ EXPORT_SYMBOL(task_no_data_intr);
 static u8 wait_drive_not_busy(ide_drive_t *drive)
 {
 	ide_hwif_t *hwif = HWIF(drive);
-	int retries = 100;
+	int retries;
 	u8 stat;
 
 	/*
@@ -246,10 +246,14 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
 	 * This can take up to 10 usec, but we will wait max 1 ms
 	 * (drive_cmd_intr() waits that long).
 	 */
-	while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
-		udelay(10);
+	for (retries = 0; retries < 100; retries++) {
+		if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT)
+			udelay(10);
+		else
+			break;
+	}
 
-	if (!retries)
+	if (stat & BUSY_STAT)
 		printk(KERN_ERR "%s: drive still BUSY!\n", drive->name);
 
 	return stat;
#5 lore raw
Quoted 3 lines · Masatake YAMATO
Quoted 1 line

Please re-submit this fix in the form of a patch so I can merge it.

Here it is.

Applied but please remember to always include patch description when sending the improved version of the patch. This time I fixed it manually to speed up the procedure.

Thanks,
Bart