aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-06 16:39:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-06 16:39:23 -0400
commitc7f396f12fb3644ff325acb2384b64c8eea7a746 (patch)
tree083ef38707847dfda019bf2c1be865e2fa725b5d
parentbe6297e9be118d89fa477a60ddfbf0e0b2dfacec (diff)
parent1c24285372412b26af4f0f980c115e857fb87c02 (diff)
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
-rw-r--r--fs/dlm/debug_fs.c25
-rw-r--r--fs/dlm/lock.c8
-rw-r--r--fs/dlm/lockspace.c9
-rw-r--r--fs/dlm/lowcomms.c2
-rw-r--r--fs/dlm/member.c15
-rw-r--r--fs/dlm/user.c6
-rw-r--r--include/uapi/linux/dlm_netlink.h1
7 files changed, 36 insertions, 30 deletions
diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index ca7089aeadab..fa08448e35dd 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -68,7 +68,7 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
68 if (lkb->lkb_wait_type) 68 if (lkb->lkb_wait_type)
69 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); 69 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
70 70
71 seq_puts(s, "\n"); 71 seq_putc(s, '\n');
72} 72}
73 73
74static void print_format1(struct dlm_rsb *res, struct seq_file *s) 74static 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)
111 } 111 }
112 if (rsb_flag(res, RSB_VALNOTVALID)) 112 if (rsb_flag(res, RSB_VALNOTVALID))
113 seq_puts(s, " (INVALID)"); 113 seq_puts(s, " (INVALID)");
114 seq_puts(s, "\n"); 114 seq_putc(s, '\n');
115 if (seq_has_overflowed(s)) 115 if (seq_has_overflowed(s))
116 goto out; 116 goto out;
117 } 117 }
@@ -156,7 +156,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
156 lkb->lkb_id, print_lockmode(lkb->lkb_rqmode)); 156 lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
157 if (lkb->lkb_wait_type) 157 if (lkb->lkb_wait_type)
158 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); 158 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
159 seq_puts(s, "\n"); 159 seq_putc(s, '\n');
160 if (seq_has_overflowed(s)) 160 if (seq_has_overflowed(s))
161 goto out; 161 goto out;
162 } 162 }
@@ -287,7 +287,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
287 else 287 else
288 seq_printf(s, " %02x", (unsigned char)r->res_name[i]); 288 seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
289 } 289 }
290 seq_puts(s, "\n"); 290 seq_putc(s, '\n');
291 if (seq_has_overflowed(s)) 291 if (seq_has_overflowed(s))
292 goto out; 292 goto out;
293 293
@@ -298,7 +298,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
298 298
299 for (i = 0; i < lvblen; i++) 299 for (i = 0; i < lvblen; i++)
300 seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]); 300 seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
301 seq_puts(s, "\n"); 301 seq_putc(s, '\n');
302 if (seq_has_overflowed(s)) 302 if (seq_has_overflowed(s))
303 goto out; 303 goto out;
304 304
@@ -361,8 +361,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s)
361 else 361 else
362 seq_printf(s, " %02x", (unsigned char)r->res_name[i]); 362 seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
363 } 363 }
364 seq_puts(s, "\n"); 364 seq_putc(s, '\n');
365
366 unlock_rsb(r); 365 unlock_rsb(r);
367} 366}
368 367
@@ -436,7 +435,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos)
436 if (bucket >= ls->ls_rsbtbl_size) 435 if (bucket >= ls->ls_rsbtbl_size)
437 return NULL; 436 return NULL;
438 437
439 ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS); 438 ri = kzalloc(sizeof(*ri), GFP_NOFS);
440 if (!ri) 439 if (!ri)
441 return NULL; 440 return NULL;
442 if (n == 0) 441 if (n == 0)
@@ -742,7 +741,7 @@ void dlm_delete_debug_file(struct dlm_ls *ls)
742 741
743int dlm_create_debug_file(struct dlm_ls *ls) 742int dlm_create_debug_file(struct dlm_ls *ls)
744{ 743{
745 char name[DLM_LOCKSPACE_LEN+8]; 744 char name[DLM_LOCKSPACE_LEN + 8];
746 745
747 /* format 1 */ 746 /* format 1 */
748 747
@@ -757,7 +756,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
757 /* format 2 */ 756 /* format 2 */
758 757
759 memset(name, 0, sizeof(name)); 758 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);
761 760
762 ls->ls_debug_locks_dentry = debugfs_create_file(name, 761 ls->ls_debug_locks_dentry = debugfs_create_file(name,
763 S_IFREG | S_IRUGO, 762 S_IFREG | S_IRUGO,
@@ -770,7 +769,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
770 /* format 3 */ 769 /* format 3 */
771 770
772 memset(name, 0, sizeof(name)); 771 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);
774 773
775 ls->ls_debug_all_dentry = debugfs_create_file(name, 774 ls->ls_debug_all_dentry = debugfs_create_file(name,
776 S_IFREG | S_IRUGO, 775 S_IFREG | S_IRUGO,
@@ -783,7 +782,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
783 /* format 4 */ 782 /* format 4 */
784 783
785 memset(name, 0, sizeof(name)); 784 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);
787 786
788 ls->ls_debug_toss_dentry = debugfs_create_file(name, 787 ls->ls_debug_toss_dentry = debugfs_create_file(name,
789 S_IFREG | S_IRUGO, 788 S_IFREG | S_IRUGO,
@@ -794,7 +793,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
794 goto fail; 793 goto fail;
795 794
796 memset(name, 0, sizeof(name)); 795 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);
798 797
799 ls->ls_debug_waiters_dentry = debugfs_create_file(name, 798 ls->ls_debug_waiters_dentry = debugfs_create_file(name,
800 S_IFREG | S_IRUGO, 799 S_IFREG | S_IRUGO,
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 6df332296c66..d4aaddec1b16 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -1426,7 +1426,7 @@ void dlm_scan_waiters(struct dlm_ls *ls)
1426 1426
1427 if (!num_nodes) { 1427 if (!num_nodes) {
1428 num_nodes = ls->ls_num_nodes; 1428 num_nodes = ls->ls_num_nodes;
1429 warned = kzalloc(num_nodes * sizeof(int), GFP_KERNEL); 1429 warned = kcalloc(num_nodes, sizeof(int), GFP_KERNEL);
1430 } 1430 }
1431 if (!warned) 1431 if (!warned)
1432 continue; 1432 continue;
@@ -5119,11 +5119,9 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
5119 int wait_type, stub_unlock_result, stub_cancel_result; 5119 int wait_type, stub_unlock_result, stub_cancel_result;
5120 int dir_nodeid; 5120 int dir_nodeid;
5121 5121
5122 ms_stub = kmalloc(sizeof(struct dlm_message), GFP_KERNEL); 5122 ms_stub = kmalloc(sizeof(*ms_stub), GFP_KERNEL);
5123 if (!ms_stub) { 5123 if (!ms_stub)
5124 log_error(ls, "dlm_recover_waiters_pre no mem");
5125 return; 5124 return;
5126 }
5127 5125
5128 mutex_lock(&ls->ls_waiters_mutex); 5126 mutex_lock(&ls->ls_waiters_mutex);
5129 5127
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 91592b75c309..78a7c855b06b 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -235,7 +235,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj,
235 return 0; 235 return 0;
236} 236}
237 237
238static struct kset_uevent_ops dlm_uevent_ops = { 238static const struct kset_uevent_ops dlm_uevent_ops = {
239 .uevent = dlm_uevent, 239 .uevent = dlm_uevent,
240}; 240};
241 241
@@ -453,9 +453,14 @@ static int new_lockspace(const char *name, const char *cluster,
453 *ops_result = 0; 453 *ops_result = 0;
454 } 454 }
455 455
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
456 if (dlm_config.ci_recover_callbacks && cluster && 460 if (dlm_config.ci_recover_callbacks && cluster &&
457 strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) { 461 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'",
459 dlm_config.ci_cluster_name, cluster); 464 dlm_config.ci_cluster_name, cluster);
460 error = -EBADR; 465 error = -EBADR;
461 goto out; 466 goto out;
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 9382db998ec9..4813d0e0cd9b 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -729,7 +729,7 @@ static int tcp_accept_from_sock(struct connection *con)
729 mutex_unlock(&connections_lock); 729 mutex_unlock(&connections_lock);
730 730
731 memset(&peeraddr, 0, sizeof(peeraddr)); 731 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,
733 SOCK_STREAM, IPPROTO_TCP, &newsock); 733 SOCK_STREAM, IPPROTO_TCP, &newsock);
734 if (result < 0) 734 if (result < 0)
735 return -ENOMEM; 735 return -ENOMEM;
diff --git a/fs/dlm/member.c b/fs/dlm/member.c
index 9c47f1c14a8b..3fda3832cf6a 100644
--- a/fs/dlm/member.c
+++ b/fs/dlm/member.c
@@ -217,8 +217,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size,
217 } 217 }
218 218
219 array_size = max + need; 219 array_size = max + need;
220 220 array = kcalloc(array_size, sizeof(*array), GFP_NOFS);
221 array = kzalloc(array_size * sizeof(struct dlm_slot), GFP_NOFS);
222 if (!array) 221 if (!array)
223 return -ENOMEM; 222 return -ENOMEM;
224 223
@@ -319,7 +318,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node)
319 struct dlm_member *memb; 318 struct dlm_member *memb;
320 int error; 319 int error;
321 320
322 memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS); 321 memb = kzalloc(sizeof(*memb), GFP_NOFS);
323 if (!memb) 322 if (!memb)
324 return -ENOMEM; 323 return -ENOMEM;
325 324
@@ -405,8 +404,7 @@ static void make_member_array(struct dlm_ls *ls)
405 } 404 }
406 405
407 ls->ls_total_weight = total; 406 ls->ls_total_weight = total;
408 407 array = kmalloc_array(total, sizeof(*array), GFP_NOFS);
409 array = kmalloc(sizeof(int) * total, GFP_NOFS);
410 if (!array) 408 if (!array)
411 return; 409 return;
412 410
@@ -492,8 +490,7 @@ void dlm_lsop_recover_done(struct dlm_ls *ls)
492 return; 490 return;
493 491
494 num = ls->ls_num_nodes; 492 num = ls->ls_num_nodes;
495 493 slots = kcalloc(num, sizeof(*slots), GFP_KERNEL);
496 slots = kzalloc(num * sizeof(struct dlm_slot), GFP_KERNEL);
497 if (!slots) 494 if (!slots)
498 return; 495 return;
499 496
@@ -673,11 +670,11 @@ int dlm_ls_stop(struct dlm_ls *ls)
673 670
674int dlm_ls_start(struct dlm_ls *ls) 671int dlm_ls_start(struct dlm_ls *ls)
675{ 672{
676 struct dlm_recover *rv = NULL, *rv_old; 673 struct dlm_recover *rv, *rv_old;
677 struct dlm_config_node *nodes; 674 struct dlm_config_node *nodes;
678 int error, count; 675 int error, count;
679 676
680 rv = kzalloc(sizeof(struct dlm_recover), GFP_NOFS); 677 rv = kzalloc(sizeof(*rv), GFP_NOFS);
681 if (!rv) 678 if (!rv)
682 return -ENOMEM; 679 return -ENOMEM;
683 680
diff --git a/fs/dlm/user.c b/fs/dlm/user.c
index 23488f559cf9..d18e7a539f11 100644
--- a/fs/dlm/user.c
+++ b/fs/dlm/user.c
@@ -123,6 +123,8 @@ static void compat_input(struct dlm_write_request *kb,
123static void compat_output(struct dlm_lock_result *res, 123static void compat_output(struct dlm_lock_result *res,
124 struct dlm_lock_result32 *res32) 124 struct dlm_lock_result32 *res32)
125{ 125{
126 memset(res32, 0, sizeof(*res32));
127
126 res32->version[0] = res->version[0]; 128 res32->version[0] = res->version[0];
127 res32->version[1] = res->version[1]; 129 res32->version[1] = res->version[1];
128 res32->version[2] = res->version[2]; 130 res32->version[2] = res->version[2];
@@ -355,6 +357,10 @@ static int dlm_device_register(struct dlm_ls *ls, char *name)
355 error = misc_register(&ls->ls_device); 357 error = misc_register(&ls->ls_device);
356 if (error) { 358 if (error) {
357 kfree(ls->ls_device.name); 359 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;
358 } 364 }
359fail: 365fail:
360 return error; 366 return error;
diff --git a/include/uapi/linux/dlm_netlink.h b/include/uapi/linux/dlm_netlink.h
index 647c8ef27227..ef1e2e08769a 100644
--- a/include/uapi/linux/dlm_netlink.h
+++ b/include/uapi/linux/dlm_netlink.h
@@ -10,6 +10,7 @@
10#define _DLM_NETLINK_H 10#define _DLM_NETLINK_H
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/dlmconstants.h>
13 14
14enum { 15enum {
15 DLM_STATUS_WAITING = 1, 16 DLM_STATUS_WAITING = 1,