Messages in this thread | | | Date | Tue, 27 Sep 2005 16:04:20 +0200 | From | Bartlomiej Zolnierkiewicz <> | Subject | Re: usage count in device driver and concurrency |
| |
On 8/30/05, Adeshara Tushar <adesharatushar@yahoo.com> wrote: > Hi, > I am wondering how to handle device usage count in > open and release call of device driver if hardware > need to be initialized on first open and shutdown on > last close. I have seen som code like > > int open() > { > /*some code*/ > device->usage++; > if(device->usage==1) > init_hardware(); > /*rest of code*/ > } > void release () > { > /*some code*/ > if(device->usage==1) > shutdown_hardware(); > device->usage--; > /*rest of code*/ > } > > > > However, it seems to me that this code can make > problem. > If device->usage=0, and two process A,B execute line > device->usage++; > concurretly, device->usage will become 2 when they > come to next line. This will result in hardware being > used without initialization. Same things can happen in > release call also, which will result in no shutdown of > hardware. > I have seen this type of code in > /linux-2.6.8/drivers/ide/ide-disk.c and > /linux-2.6.8/drivers/ide/ide-floppy.c > > Please let me know if its bug or not before I > start working on patches.
Not a bug: ->open() and ->release() for block devices are never called concurrently (because of bdev->bd_sem).
Bartlomiej - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |