Skip to content

Commit dbc6e7d

Browse files
sunnanyongtorvalds
authored andcommitted
nilfs2: fix NULL pointer in nilfs_##name##_attr_release
In nilfs_##name##_attr_release, kobj->parent should not be referenced because it is a NULL pointer. The release() method of kobject is always called in kobject_put(kobj), in the implementation of kobject_put(), the kobj->parent will be assigned as NULL before call the release() method. So just use kobj to get the subgroups, which is more efficient and can fix a NULL pointer reference problem. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Nanyong Sun <[email protected]> Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5f5dec0 commit dbc6e7d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

fs/nilfs2/sysfs.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ static const struct sysfs_ops nilfs_##name##_attr_ops = { \
5151
#define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \
5252
static void nilfs_##name##_attr_release(struct kobject *kobj) \
5353
{ \
54-
struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
55-
struct the_nilfs *nilfs = container_of(kobj->parent, \
56-
struct the_nilfs, \
57-
ns_##parent_name##_kobj); \
58-
subgroups = nilfs->ns_##parent_name##_subgroups; \
54+
struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \
55+
struct nilfs_sysfs_##parent_name##_subgroups, \
56+
sg_##name##_kobj); \
5957
complete(&subgroups->sg_##name##_kobj_unregister); \
6058
} \
6159
static struct kobj_type nilfs_##name##_ktype = { \

0 commit comments

Comments
 (0)