Skip to content

Commit d15b774

Browse files
committed
dm: fix idr leak on module removal
Destroy _minor_idr when unloading the core dm module. (Found by kmemleak.) Cc: [email protected] Signed-off-by: Alasdair G Kergon <[email protected]>
1 parent bb91bc7 commit d15b774

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/md/dm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static const char *_name = DM_NAME;
3737
static unsigned int major = 0;
3838
static unsigned int _major = 0;
3939

40+
static DEFINE_IDR(_minor_idr);
41+
4042
static DEFINE_SPINLOCK(_minor_lock);
4143
/*
4244
* For bio-based dm.
@@ -313,6 +315,12 @@ static void __exit dm_exit(void)
313315

314316
while (i--)
315317
_exits[i]();
318+
319+
/*
320+
* Should be empty by this point.
321+
*/
322+
idr_remove_all(&_minor_idr);
323+
idr_destroy(&_minor_idr);
316324
}
317325

318326
/*
@@ -1705,8 +1713,6 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
17051713
/*-----------------------------------------------------------------
17061714
* An IDR is used to keep track of allocated minor numbers.
17071715
*---------------------------------------------------------------*/
1708-
static DEFINE_IDR(_minor_idr);
1709-
17101716
static void free_minor(int minor)
17111717
{
17121718
spin_lock(&_minor_lock);

0 commit comments

Comments
 (0)