Skip to content

Commit 31720a2

Browse files
z00467499hubcapsc
authored andcommitted
orangefs: Fix kmemleak in orangefs_{kernel,client}_debug_init()
When insert and remove the orangefs module, there are memory leaked as below: unreferenced object 0xffff88816b0cc000 (size 2048): comm "insmod", pid 783, jiffies 4294813439 (age 65.512s) hex dump (first 32 bytes): 6e 6f 6e 65 0a 00 00 00 00 00 00 00 00 00 00 00 none............ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000031ab7788>] kmalloc_trace+0x27/0xa0 [<000000005b405fee>] orangefs_debugfs_init.cold+0xaf/0x17f [<00000000e5a0085b>] 0xffffffffa02780f9 [<000000004232d9f7>] do_one_initcall+0x87/0x2a0 [<0000000054f22384>] do_init_module+0xdf/0x320 [<000000003263bdea>] load_module+0x2f98/0x3330 [<0000000052cd4153>] __do_sys_finit_module+0x113/0x1b0 [<00000000250ae02b>] do_syscall_64+0x35/0x80 [<00000000f11c03c7>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 Use the golbal variable as the buffer rather than dynamic allocate to slove the problem. Signed-off-by: Zhang Xiaoxu <[email protected]> Signed-off-by: Mike Marshall <[email protected]>
1 parent 1f2c0e8 commit 31720a2

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

fs/orangefs/orangefs-debugfs.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,10 @@ void orangefs_debugfs_init(int debug_mask)
194194
*/
195195
static void orangefs_kernel_debug_init(void)
196196
{
197-
int rc = -ENOMEM;
198-
char *k_buffer = NULL;
197+
static char k_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
199198

200199
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
201200

202-
k_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
203-
if (!k_buffer)
204-
goto out;
205-
206201
if (strlen(kernel_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
207202
strcpy(k_buffer, kernel_debug_string);
208203
strcat(k_buffer, "\n");
@@ -213,9 +208,6 @@ static void orangefs_kernel_debug_init(void)
213208

214209
debugfs_create_file(ORANGEFS_KMOD_DEBUG_FILE, 0444, debug_dir, k_buffer,
215210
&kernel_debug_fops);
216-
217-
out:
218-
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
219211
}
220212

221213

@@ -299,18 +291,13 @@ static int help_show(struct seq_file *m, void *v)
299291
/*
300292
* initialize the client-debug file.
301293
*/
302-
static int orangefs_client_debug_init(void)
294+
static void orangefs_client_debug_init(void)
303295
{
304296

305-
int rc = -ENOMEM;
306-
char *c_buffer = NULL;
297+
static char c_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
307298

308299
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
309300

310-
c_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
311-
if (!c_buffer)
312-
goto out;
313-
314301
if (strlen(client_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
315302
strcpy(c_buffer, client_debug_string);
316303
strcat(c_buffer, "\n");
@@ -324,13 +311,6 @@ static int orangefs_client_debug_init(void)
324311
debug_dir,
325312
c_buffer,
326313
&kernel_debug_fops);
327-
328-
rc = 0;
329-
330-
out:
331-
332-
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
333-
return rc;
334314
}
335315

336316
/* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/

0 commit comments

Comments
 (0)