Skip to content

Commit 40b94ec

Browse files
shroffniaxboe
authored andcommitted
null_blk: fix kmemleak by releasing references to fault configfs items
When CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION is enabled, the null-blk driver sets up fault injection support by creating the timeout_inject, requeue_inject, and init_hctx_fault_inject configfs items as children of the top-level nullbX configfs group. However, when the nullbX device is removed, the references taken to these fault-config configfs items are not released. As a result, kmemleak reports a memory leak, for example: unreferenced object 0xc00000021ff25c40 (size 32): comm "mkdir", pid 10665, jiffies 4322121578 hex dump (first 32 bytes): 69 6e 69 74 5f 68 63 74 78 5f 66 61 75 6c 74 5f init_hctx_fault_ 69 6e 6a 65 63 74 00 88 00 00 00 00 00 00 00 00 inject.......... backtrace (crc 1a018c86): __kmalloc_node_track_caller_noprof+0x494/0xbd8 kvasprintf+0x74/0xf4 config_item_set_name+0xf0/0x104 config_group_init_type_name+0x48/0xfc fault_config_init+0x48/0xf0 0xc0080000180559e4 configfs_mkdir+0x304/0x814 vfs_mkdir+0x49c/0x604 do_mkdirat+0x314/0x3d0 sys_mkdir+0xa0/0xd8 system_call_exception+0x1b0/0x4f0 system_call_vectored_common+0x15c/0x2ec Fix this by explicitly releasing the references to the fault-config configfs items when dropping the reference to the top-level nullbX configfs group. Cc: [email protected] Reviewed-by: Chaitanya Kulkarni <[email protected]> Fixes: bb4c19e ("block: null_blk: make fault-injection dynamically configurable per device") Signed-off-by: Nilay Shroff <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ca22c56 commit 40b94ec

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

drivers/block/null_blk/main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,22 @@ static void nullb_add_fault_config(struct nullb_device *dev)
665665
configfs_add_default_group(&dev->init_hctx_fault_config.group, &dev->group);
666666
}
667667

668+
static void nullb_del_fault_config(struct nullb_device *dev)
669+
{
670+
config_item_put(&dev->init_hctx_fault_config.group.cg_item);
671+
config_item_put(&dev->requeue_config.group.cg_item);
672+
config_item_put(&dev->timeout_config.group.cg_item);
673+
}
674+
668675
#else
669676

670677
static void nullb_add_fault_config(struct nullb_device *dev)
671678
{
672679
}
673680

681+
static void nullb_del_fault_config(struct nullb_device *dev)
682+
{
683+
}
674684
#endif
675685

676686
static struct
@@ -702,7 +712,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
702712
null_del_dev(dev->nullb);
703713
mutex_unlock(&lock);
704714
}
705-
715+
nullb_del_fault_config(dev);
706716
config_item_put(item);
707717
}
708718

0 commit comments

Comments
 (0)