lkml.org 
[lkml]   [2010]   [Feb]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 01/17] MTD: create lockless versions of {get,put}_mtd_device This will be used to resolve deadlock in block translation layer.
    From
    Date
    On Tue, 2010-02-09 at 18:14 +0100, Peter Zijlstra wrote: 
    > On Tue, 2010-02-09 at 18:57 +0200, Maxim Levitsky wrote:
    > > These functions can be used as long as we don't need access to global mtd table, but have
    > > a pointer to the mtd device.
    > >
    > > Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
    > > ---
    > > drivers/mtd/mtdcore.c | 60 ++++++++++++++++++++++++++++++----------------
    > > include/linux/mtd/mtd.h | 3 +-
    > > 2 files changed, 41 insertions(+), 22 deletions(-)
    >
    > > +int __get_mtd_device(struct mtd_info *mtd)
    > > +{
    > > + int err;
    > > +
    > > + if (!try_module_get(mtd->owner))
    > > + return -ENODEV;
    > > +
    > > + if (mtd->get_device) {
    > > +
    > > + err = mtd->get_device(mtd);
    > > +
    > > + if (err) {
    > > + module_put(mtd->owner);
    > > + return err;
    > > + }
    > > + }
    > > + mtd->usecount++;
    > > + return 0;
    > > }
    >
    > > +void __put_mtd_device(struct mtd_info *mtd)
    > > +{
    > > + --mtd->usecount;
    > > + BUG_ON(mtd->usecount < 0);
    > > +
    > > if (mtd->put_device)
    > > mtd->put_device(mtd);
    > >
    > > module_put(mtd->owner);
    > > }
    >
    > That's racy, use kref.
    >
    Couldn't agree with you more.

    However, these functions aren't intended for general use, and probably
    will be used by mtd translation layer only. I do have a lock that
    protects concurrent use of these functions.

    Thus, I better add a comment about this?

    Best regards,
    Maxim Levitsky



    \
     
     \ /
      Last update: 2010-02-09 18:25    [W:2.412 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site