Re: [PATCH] ide_open is too permissive

Andries.Brouwer@cwi.nl
Mon, 17 May 1999 14:15:29 +0200 (MET DST)


Ak, why am I so quick in responding?

> it looks like drive->usage was never decremented again in case
> the driver open failed.

Looking at the code I see that the open routine itself does
the decrement of drive->usage. Revised version:

--- /g1/linux/linux-2.3.2/linux/drivers/block/ide.c Sat May 15 21:10:22 1999
+++ ide.c Mon May 17 14:07:34 1999
@@ -1690,15 +1691,28 @@
while (drive->busy)
sleep_on(&drive->wqueue);
drive->usage++;
+ rc = 0;
if (drive->driver != NULL) {
- if ((rc = DRIVER(drive)->open(inode, filp, drive)))
+ if ((rc = DRIVER(drive)->open(inode, filp, drive))) {
MOD_DEC_USE_COUNT;
- return rc;
+ return rc;
+ }
+ } else {
+ printk ("%s: driver not present\n", drive->name);
+ rc = -ENXIO;
}
- printk ("%s: driver not present\n", drive->name);
- drive->usage--;
- MOD_DEC_USE_COUNT;
- return -ENXIO;
+
+ if (rc == 0 && drive->media == ide_disk) {
+ int minor = (MINOR(inode->i_rdev) & PARTN_MASK);
+ if (drive->part[minor].nr_sects == 0)
+ rc = -ENXIO;
+ }
+
+ if (rc) {
+ drive->usage--;
+ MOD_DEC_USE_COUNT;
+ }
+ return rc;
}

/*

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/