Skip to content

Commit c7f396f

Browse files
committed
Merge tag 'dlm-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm
Pull dlm updates from David Teigland: "This set includes a bunch of minor code cleanups that have accumulated, probably from code analyzers people like to run. There is one nice fix that avoids some socket leaks by switching to use sock_create_lite()" * tag 'dlm-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm: dlm: use sock_create_lite inside tcp_accept_from_sock uapi linux/dlm_netlink.h: include linux/dlmconstants.h dlm: avoid double-free on error path in dlm_device_{register,unregister} dlm: constify kset_uevent_ops structure dlm: print log message when cluster name is not set dlm: Delete an unnecessary variable initialisation in dlm_ls_start() dlm: Improve a size determination in two functions dlm: Use kcalloc() in two functions dlm: Use kmalloc_array() in make_member_array() dlm: Delete an error message for a failed memory allocation in dlm_recover_waiters_pre() dlm: Improve a size determination in dlm_recover_waiters_pre() dlm: Use kcalloc() in dlm_scan_waiters() dlm: Improve a size determination in table_seq_start() dlm: Add spaces for better code readability dlm: Replace six seq_puts() calls by seq_putc() dlm: Make dismatch error message more clear dlm: Fix kernel memory disclosure
2 parents be6297e + 1c24285 commit c7f396f

File tree

7 files changed

+36
-30
lines changed

7 files changed

+36
-30
lines changed

fs/dlm/debug_fs.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
6868
if (lkb->lkb_wait_type)
6969
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
7070

71-
seq_puts(s, "\n");
71+
seq_putc(s, '\n');
7272
}
7373

7474
static void print_format1(struct dlm_rsb *res, struct seq_file *s)
@@ -111,7 +111,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
111111
}
112112
if (rsb_flag(res, RSB_VALNOTVALID))
113113
seq_puts(s, " (INVALID)");
114-
seq_puts(s, "\n");
114+
seq_putc(s, '\n');
115115
if (seq_has_overflowed(s))
116116
goto out;
117117
}
@@ -156,7 +156,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
156156
lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
157157
if (lkb->lkb_wait_type)
158158
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
159-
seq_puts(s, "\n");
159+
seq_putc(s, '\n');
160160
if (seq_has_overflowed(s))
161161
goto out;
162162
}
@@ -287,7 +287,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
287287
else
288288
seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
289289
}
290-
seq_puts(s, "\n");
290+
seq_putc(s, '\n');
291291
if (seq_has_overflowed(s))
292292
goto out;
293293

@@ -298,7 +298,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
298298

299299
for (i = 0; i < lvblen; i++)
300300
seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
301-
seq_puts(s, "\n");
301+
seq_putc(s, '\n');
302302
if (seq_has_overflowed(s))
303303
goto out;
304304

@@ -361,8 +361,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s)
361361
else
362362
seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
363363
}
364-
seq_puts(s, "\n");
365-
364+
seq_putc(s, '\n');
366365
unlock_rsb(r);
367366
}
368367

@@ -436,7 +435,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos)
436435
if (bucket >= ls->ls_rsbtbl_size)
437436
return NULL;
438437

439-
ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS);
438+
ri = kzalloc(sizeof(*ri), GFP_NOFS);
440439
if (!ri)
441440
return NULL;
442441
if (n == 0)
@@ -742,7 +741,7 @@ void dlm_delete_debug_file(struct dlm_ls *ls)
742741

743742
int dlm_create_debug_file(struct dlm_ls *ls)
744743
{
745-
char name[DLM_LOCKSPACE_LEN+8];
744+
char name[DLM_LOCKSPACE_LEN + 8];
746745

747746
/* format 1 */
748747

@@ -757,7 +756,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
757756
/* format 2 */
758757

759758
memset(name, 0, sizeof(name));
760-
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name);
759+
snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name);
761760

762761
ls->ls_debug_locks_dentry = debugfs_create_file(name,
763762
S_IFREG | S_IRUGO,
@@ -770,7 +769,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
770769
/* format 3 */
771770

772771
memset(name, 0, sizeof(name));
773-
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name);
772+
snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_all", ls->ls_name);
774773

775774
ls->ls_debug_all_dentry = debugfs_create_file(name,
776775
S_IFREG | S_IRUGO,
@@ -783,7 +782,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
783782
/* format 4 */
784783

785784
memset(name, 0, sizeof(name));
786-
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_toss", ls->ls_name);
785+
snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_toss", ls->ls_name);
787786

788787
ls->ls_debug_toss_dentry = debugfs_create_file(name,
789788
S_IFREG | S_IRUGO,
@@ -794,7 +793,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
794793
goto fail;
795794

796795
memset(name, 0, sizeof(name));
797-
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name);
796+
snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
798797

799798
ls->ls_debug_waiters_dentry = debugfs_create_file(name,
800799
S_IFREG | S_IRUGO,

fs/dlm/lock.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ void dlm_scan_waiters(struct dlm_ls *ls)
14261426

14271427
if (!num_nodes) {
14281428
num_nodes = ls->ls_num_nodes;
1429-
warned = kzalloc(num_nodes * sizeof(int), GFP_KERNEL);
1429+
warned = kcalloc(num_nodes, sizeof(int), GFP_KERNEL);
14301430
}
14311431
if (!warned)
14321432
continue;
@@ -5119,11 +5119,9 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
51195119
int wait_type, stub_unlock_result, stub_cancel_result;
51205120
int dir_nodeid;
51215121

5122-
ms_stub = kmalloc(sizeof(struct dlm_message), GFP_KERNEL);
5123-
if (!ms_stub) {
5124-
log_error(ls, "dlm_recover_waiters_pre no mem");
5122+
ms_stub = kmalloc(sizeof(*ms_stub), GFP_KERNEL);
5123+
if (!ms_stub)
51255124
return;
5126-
}
51275125

51285126
mutex_lock(&ls->ls_waiters_mutex);
51295127

fs/dlm/lockspace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj,
235235
return 0;
236236
}
237237

238-
static struct kset_uevent_ops dlm_uevent_ops = {
238+
static const struct kset_uevent_ops dlm_uevent_ops = {
239239
.uevent = dlm_uevent,
240240
};
241241

@@ -453,9 +453,14 @@ static int new_lockspace(const char *name, const char *cluster,
453453
*ops_result = 0;
454454
}
455455

456+
if (!cluster)
457+
log_print("dlm cluster name '%s' is being used without an application provided cluster name",
458+
dlm_config.ci_cluster_name);
459+
456460
if (dlm_config.ci_recover_callbacks && cluster &&
457461
strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) {
458-
log_print("dlm cluster name %s mismatch %s",
462+
log_print("dlm cluster name '%s' does not match "
463+
"the application cluster name '%s'",
459464
dlm_config.ci_cluster_name, cluster);
460465
error = -EBADR;
461466
goto out;

fs/dlm/lowcomms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ static int tcp_accept_from_sock(struct connection *con)
729729
mutex_unlock(&connections_lock);
730730

731731
memset(&peeraddr, 0, sizeof(peeraddr));
732-
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family,
732+
result = sock_create_lite(dlm_local_addr[0]->ss_family,
733733
SOCK_STREAM, IPPROTO_TCP, &newsock);
734734
if (result < 0)
735735
return -ENOMEM;

fs/dlm/member.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size,
217217
}
218218

219219
array_size = max + need;
220-
221-
array = kzalloc(array_size * sizeof(struct dlm_slot), GFP_NOFS);
220+
array = kcalloc(array_size, sizeof(*array), GFP_NOFS);
222221
if (!array)
223222
return -ENOMEM;
224223

@@ -319,7 +318,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node)
319318
struct dlm_member *memb;
320319
int error;
321320

322-
memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS);
321+
memb = kzalloc(sizeof(*memb), GFP_NOFS);
323322
if (!memb)
324323
return -ENOMEM;
325324

@@ -405,8 +404,7 @@ static void make_member_array(struct dlm_ls *ls)
405404
}
406405

407406
ls->ls_total_weight = total;
408-
409-
array = kmalloc(sizeof(int) * total, GFP_NOFS);
407+
array = kmalloc_array(total, sizeof(*array), GFP_NOFS);
410408
if (!array)
411409
return;
412410

@@ -492,8 +490,7 @@ void dlm_lsop_recover_done(struct dlm_ls *ls)
492490
return;
493491

494492
num = ls->ls_num_nodes;
495-
496-
slots = kzalloc(num * sizeof(struct dlm_slot), GFP_KERNEL);
493+
slots = kcalloc(num, sizeof(*slots), GFP_KERNEL);
497494
if (!slots)
498495
return;
499496

@@ -673,11 +670,11 @@ int dlm_ls_stop(struct dlm_ls *ls)
673670

674671
int dlm_ls_start(struct dlm_ls *ls)
675672
{
676-
struct dlm_recover *rv = NULL, *rv_old;
673+
struct dlm_recover *rv, *rv_old;
677674
struct dlm_config_node *nodes;
678675
int error, count;
679676

680-
rv = kzalloc(sizeof(struct dlm_recover), GFP_NOFS);
677+
rv = kzalloc(sizeof(*rv), GFP_NOFS);
681678
if (!rv)
682679
return -ENOMEM;
683680

fs/dlm/user.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ static void compat_input(struct dlm_write_request *kb,
123123
static void compat_output(struct dlm_lock_result *res,
124124
struct dlm_lock_result32 *res32)
125125
{
126+
memset(res32, 0, sizeof(*res32));
127+
126128
res32->version[0] = res->version[0];
127129
res32->version[1] = res->version[1];
128130
res32->version[2] = res->version[2];
@@ -355,6 +357,10 @@ static int dlm_device_register(struct dlm_ls *ls, char *name)
355357
error = misc_register(&ls->ls_device);
356358
if (error) {
357359
kfree(ls->ls_device.name);
360+
/* this has to be set to NULL
361+
* to avoid a double-free in dlm_device_deregister
362+
*/
363+
ls->ls_device.name = NULL;
358364
}
359365
fail:
360366
return error;

include/uapi/linux/dlm_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define _DLM_NETLINK_H
1111

1212
#include <linux/types.h>
13+
#include <linux/dlmconstants.h>
1314

1415
enum {
1516
DLM_STATUS_WAITING = 1,

0 commit comments

Comments
 (0)