From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: Adeshara Tushar <adesharatushar@yahoo.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: usage count in device driver and concurrency
Date: Tue, 27 Sep 2005 16:04:20 +0200 [thread overview]
Message-ID: <58cb370e0509270704191629fb@mail.gmail.com> (raw)
In-Reply-To: <20050830142214.72958.qmail@web51802.mail.yahoo.com>
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
prev parent reply other threads:[~2005-09-27 14:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-30 14:22 Adeshara Tushar
2005-09-27 14:04 ` Bartlomiej Zolnierkiewicz [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58cb370e0509270704191629fb@mail.gmail.com \
--to=bzolnier@gmail.com \
--cc=adesharatushar@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®