All of lore.kernel.org
 help / color / mirror / Atom feed
* usage count in device driver and concurrency
@ 2005-08-30 14:22 Adeshara Tushar
  2005-09-27 14:04 ` Bartlomiej Zolnierkiewicz
  0 siblings, 1 reply; 2+ messages in thread
From: Adeshara Tushar @ 2005-08-30 14:22 UTC (permalink / raw)
  To: linux-kernel

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.


Regards,
Tushar

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: usage count in device driver and concurrency
  2005-08-30 14:22 usage count in device driver and concurrency Adeshara Tushar
@ 2005-09-27 14:04 ` Bartlomiej Zolnierkiewicz
  0 siblings, 0 replies; 2+ messages in thread
From: Bartlomiej Zolnierkiewicz @ 2005-09-27 14:04 UTC (permalink / raw)
  To: Adeshara Tushar; +Cc: linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-27 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-30 14:22 usage count in device driver and concurrency Adeshara Tushar
2005-09-27 14:04 ` Bartlomiej Zolnierkiewicz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.