lkml.org 
[lkml]   [2013]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: sysfs: use a separate locking class for open files depending on mmap
    Hello,

    Can you please test whether this patch makes the lockdep warning go
    away?

    Thanks a lot!

    diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
    index b94f936..fccb645 100644
    --- a/fs/sysfs/file.c
    +++ b/fs/sysfs/file.c
    @@ -470,6 +470,9 @@ static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
    struct kobject *kobj = of->sd->s_parent->s_dir.kobj;
    int rc;

    + if (!(of->sd->s_flags & SYSFS_FLAG_HAS_MMAP))
    + return -ENODEV;
    +
    mutex_lock(&of->mutex);

    /* need of->sd for battr, its parent for kobj */
    @@ -477,9 +480,6 @@ static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
    if (!sysfs_get_active(of->sd))
    goto out_unlock;

    - if (!battr->mmap)
    - goto out_put;
    -
    rc = battr->mmap(file, kobj, battr, vma);
    if (rc)
    goto out_put;
    @@ -851,6 +851,14 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
    sd->s_attr.attr = (void *)attr;
    sysfs_dirent_init_lockdep(sd);

    + if (type == SYSFS_KOBJ_BIN_ATTR) {
    + const struct bin_attribute *battr =
    + container_of(attr, struct bin_attribute, attr);
    +
    + if (battr->mmap)
    + sd->s_flags |= SYSFS_FLAG_HAS_MMAP;
    + }
    +
    sysfs_addrm_start(&acxt);
    rc = sysfs_add_one(&acxt, sd, dir_sd);
    sysfs_addrm_finish(&acxt);
    diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
    index 0af09fb..27c1f7e 100644
    --- a/fs/sysfs/sysfs.h
    +++ b/fs/sysfs/sysfs.h
    @@ -96,6 +96,7 @@ struct sysfs_dirent {

    #define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK)
    #define SYSFS_FLAG_REMOVED 0x02000
    +#define SYSFS_FLAG_HAS_MMAP 0x04000

    static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
    {
    --
    tejun


    \
     
     \ /
      Last update: 2013-12-03 23:41    [W:4.233 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site