Commit c7f396f1 authored by Linus Torvalds's avatar Linus Torvalds

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
parents be6297e9 1c242853
...@@ -68,7 +68,7 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb, ...@@ -68,7 +68,7 @@ static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
if (lkb->lkb_wait_type) if (lkb->lkb_wait_type)
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
seq_puts(s, "\n"); seq_putc(s, '\n');
} }
static void print_format1(struct dlm_rsb *res, struct seq_file *s) 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) ...@@ -111,7 +111,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
} }
if (rsb_flag(res, RSB_VALNOTVALID)) if (rsb_flag(res, RSB_VALNOTVALID))
seq_puts(s, " (INVALID)"); seq_puts(s, " (INVALID)");
seq_puts(s, "\n"); seq_putc(s, '\n');
if (seq_has_overflowed(s)) if (seq_has_overflowed(s))
goto out; goto out;
} }
...@@ -156,7 +156,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s) ...@@ -156,7 +156,7 @@ static void print_format1(struct dlm_rsb *res, struct seq_file *s)
lkb->lkb_id, print_lockmode(lkb->lkb_rqmode)); lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
if (lkb->lkb_wait_type) if (lkb->lkb_wait_type)
seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
seq_puts(s, "\n"); seq_putc(s, '\n');
if (seq_has_overflowed(s)) if (seq_has_overflowed(s))
goto out; goto out;
} }
...@@ -287,7 +287,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s) ...@@ -287,7 +287,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
else else
seq_printf(s, " %02x", (unsigned char)r->res_name[i]); seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
} }
seq_puts(s, "\n"); seq_putc(s, '\n');
if (seq_has_overflowed(s)) if (seq_has_overflowed(s))
goto out; goto out;
...@@ -298,7 +298,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s) ...@@ -298,7 +298,7 @@ static void print_format3(struct dlm_rsb *r, struct seq_file *s)
for (i = 0; i < lvblen; i++) for (i = 0; i < lvblen; i++)
seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]); seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
seq_puts(s, "\n"); seq_putc(s, '\n');
if (seq_has_overflowed(s)) if (seq_has_overflowed(s))
goto out; goto out;
...@@ -361,8 +361,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s) ...@@ -361,8 +361,7 @@ static void print_format4(struct dlm_rsb *r, struct seq_file *s)
else else
seq_printf(s, " %02x", (unsigned char)r->res_name[i]); seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
} }
seq_puts(s, "\n"); seq_putc(s, '\n');
unlock_rsb(r); unlock_rsb(r);
} }
...@@ -436,7 +435,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -436,7 +435,7 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos)
if (bucket >= ls->ls_rsbtbl_size) if (bucket >= ls->ls_rsbtbl_size)
return NULL; return NULL;
ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS); ri = kzalloc(sizeof(*ri), GFP_NOFS);
if (!ri) if (!ri)
return NULL; return NULL;
if (n == 0) if (n == 0)
...@@ -742,7 +741,7 @@ void dlm_delete_debug_file(struct dlm_ls *ls) ...@@ -742,7 +741,7 @@ void dlm_delete_debug_file(struct dlm_ls *ls)
int dlm_create_debug_file(struct dlm_ls *ls) int dlm_create_debug_file(struct dlm_ls *ls)
{ {
char name[DLM_LOCKSPACE_LEN+8]; char name[DLM_LOCKSPACE_LEN + 8];
/* format 1 */ /* format 1 */
...@@ -757,7 +756,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) ...@@ -757,7 +756,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
/* format 2 */ /* format 2 */
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name); snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name);
ls->ls_debug_locks_dentry = debugfs_create_file(name, ls->ls_debug_locks_dentry = debugfs_create_file(name,
S_IFREG | S_IRUGO, S_IFREG | S_IRUGO,
...@@ -770,7 +769,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) ...@@ -770,7 +769,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
/* format 3 */ /* format 3 */
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name); snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_all", ls->ls_name);
ls->ls_debug_all_dentry = debugfs_create_file(name, ls->ls_debug_all_dentry = debugfs_create_file(name,
S_IFREG | S_IRUGO, S_IFREG | S_IRUGO,
...@@ -783,7 +782,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) ...@@ -783,7 +782,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
/* format 4 */ /* format 4 */
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_toss", ls->ls_name); snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_toss", ls->ls_name);
ls->ls_debug_toss_dentry = debugfs_create_file(name, ls->ls_debug_toss_dentry = debugfs_create_file(name,
S_IFREG | S_IRUGO, S_IFREG | S_IRUGO,
...@@ -794,7 +793,7 @@ int dlm_create_debug_file(struct dlm_ls *ls) ...@@ -794,7 +793,7 @@ int dlm_create_debug_file(struct dlm_ls *ls)
goto fail; goto fail;
memset(name, 0, sizeof(name)); memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name); snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
ls->ls_debug_waiters_dentry = debugfs_create_file(name, ls->ls_debug_waiters_dentry = debugfs_create_file(name,
S_IFREG | S_IRUGO, S_IFREG | S_IRUGO,
......
...@@ -1426,7 +1426,7 @@ void dlm_scan_waiters(struct dlm_ls *ls) ...@@ -1426,7 +1426,7 @@ void dlm_scan_waiters(struct dlm_ls *ls)
if (!num_nodes) { if (!num_nodes) {
num_nodes = ls->ls_num_nodes; num_nodes = ls->ls_num_nodes;
warned = kzalloc(num_nodes * sizeof(int), GFP_KERNEL); warned = kcalloc(num_nodes, sizeof(int), GFP_KERNEL);
} }
if (!warned) if (!warned)
continue; continue;
...@@ -5119,11 +5119,9 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls) ...@@ -5119,11 +5119,9 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
int wait_type, stub_unlock_result, stub_cancel_result; int wait_type, stub_unlock_result, stub_cancel_result;
int dir_nodeid; int dir_nodeid;
ms_stub = kmalloc(sizeof(struct dlm_message), GFP_KERNEL); ms_stub = kmalloc(sizeof(*ms_stub), GFP_KERNEL);
if (!ms_stub) { if (!ms_stub)
log_error(ls, "dlm_recover_waiters_pre no mem");
return; return;
}
mutex_lock(&ls->ls_waiters_mutex); mutex_lock(&ls->ls_waiters_mutex);
......
...@@ -235,7 +235,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj, ...@@ -235,7 +235,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj,
return 0; return 0;
} }
static struct kset_uevent_ops dlm_uevent_ops = { static const struct kset_uevent_ops dlm_uevent_ops = {
.uevent = dlm_uevent, .uevent = dlm_uevent,
}; };
...@@ -453,9 +453,14 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -453,9 +453,14 @@ static int new_lockspace(const char *name, const char *cluster,
*ops_result = 0; *ops_result = 0;
} }
if (!cluster)
log_print("dlm cluster name '%s' is being used without an application provided cluster name",
dlm_config.ci_cluster_name);
if (dlm_config.ci_recover_callbacks && cluster && if (dlm_config.ci_recover_callbacks && cluster &&
strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) { strncmp(cluster, dlm_config.ci_cluster_name, DLM_LOCKSPACE_LEN)) {
log_print("dlm cluster name %s mismatch %s", log_print("dlm cluster name '%s' does not match "
"the application cluster name '%s'",
dlm_config.ci_cluster_name, cluster); dlm_config.ci_cluster_name, cluster);
error = -EBADR; error = -EBADR;
goto out; goto out;
......
...@@ -729,7 +729,7 @@ static int tcp_accept_from_sock(struct connection *con) ...@@ -729,7 +729,7 @@ static int tcp_accept_from_sock(struct connection *con)
mutex_unlock(&connections_lock); mutex_unlock(&connections_lock);
memset(&peeraddr, 0, sizeof(peeraddr)); memset(&peeraddr, 0, sizeof(peeraddr));
result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family, result = sock_create_lite(dlm_local_addr[0]->ss_family,
SOCK_STREAM, IPPROTO_TCP, &newsock); SOCK_STREAM, IPPROTO_TCP, &newsock);
if (result < 0) if (result < 0)
return -ENOMEM; return -ENOMEM;
......
...@@ -217,8 +217,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size, ...@@ -217,8 +217,7 @@ int dlm_slots_assign(struct dlm_ls *ls, int *num_slots, int *slots_size,
} }
array_size = max + need; array_size = max + need;
array = kcalloc(array_size, sizeof(*array), GFP_NOFS);
array = kzalloc(array_size * sizeof(struct dlm_slot), GFP_NOFS);
if (!array) if (!array)
return -ENOMEM; return -ENOMEM;
...@@ -319,7 +318,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node) ...@@ -319,7 +318,7 @@ static int dlm_add_member(struct dlm_ls *ls, struct dlm_config_node *node)
struct dlm_member *memb; struct dlm_member *memb;
int error; int error;
memb = kzalloc(sizeof(struct dlm_member), GFP_NOFS); memb = kzalloc(sizeof(*memb), GFP_NOFS);
if (!memb) if (!memb)
return -ENOMEM; return -ENOMEM;
...@@ -405,8 +404,7 @@ static void make_member_array(struct dlm_ls *ls) ...@@ -405,8 +404,7 @@ static void make_member_array(struct dlm_ls *ls)
} }
ls->ls_total_weight = total; ls->ls_total_weight = total;
array = kmalloc_array(total, sizeof(*array), GFP_NOFS);
array = kmalloc(sizeof(int) * total, GFP_NOFS);
if (!array) if (!array)
return; return;
...@@ -492,8 +490,7 @@ void dlm_lsop_recover_done(struct dlm_ls *ls) ...@@ -492,8 +490,7 @@ void dlm_lsop_recover_done(struct dlm_ls *ls)
return; return;
num = ls->ls_num_nodes; num = ls->ls_num_nodes;
slots = kcalloc(num, sizeof(*slots), GFP_KERNEL);
slots = kzalloc(num * sizeof(struct dlm_slot), GFP_KERNEL);
if (!slots) if (!slots)
return; return;
...@@ -673,11 +670,11 @@ int dlm_ls_stop(struct dlm_ls *ls) ...@@ -673,11 +670,11 @@ int dlm_ls_stop(struct dlm_ls *ls)
int dlm_ls_start(struct dlm_ls *ls) int dlm_ls_start(struct dlm_ls *ls)
{ {
struct dlm_recover *rv = NULL, *rv_old; struct dlm_recover *rv, *rv_old;
struct dlm_config_node *nodes; struct dlm_config_node *nodes;
int error, count; int error, count;
rv = kzalloc(sizeof(struct dlm_recover), GFP_NOFS); rv = kzalloc(sizeof(*rv), GFP_NOFS);
if (!rv) if (!rv)
return -ENOMEM; return -ENOMEM;
......
...@@ -123,6 +123,8 @@ static void compat_input(struct dlm_write_request *kb, ...@@ -123,6 +123,8 @@ static void compat_input(struct dlm_write_request *kb,
static void compat_output(struct dlm_lock_result *res, static void compat_output(struct dlm_lock_result *res,
struct dlm_lock_result32 *res32) struct dlm_lock_result32 *res32)
{ {
memset(res32, 0, sizeof(*res32));
res32->version[0] = res->version[0]; res32->version[0] = res->version[0];
res32->version[1] = res->version[1]; res32->version[1] = res->version[1];
res32->version[2] = res->version[2]; res32->version[2] = res->version[2];
...@@ -355,6 +357,10 @@ static int dlm_device_register(struct dlm_ls *ls, char *name) ...@@ -355,6 +357,10 @@ static int dlm_device_register(struct dlm_ls *ls, char *name)
error = misc_register(&ls->ls_device); error = misc_register(&ls->ls_device);
if (error) { if (error) {
kfree(ls->ls_device.name); kfree(ls->ls_device.name);
/* this has to be set to NULL
* to avoid a double-free in dlm_device_deregister
*/
ls->ls_device.name = NULL;
} }
fail: fail:
return error; return error;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define _DLM_NETLINK_H #define _DLM_NETLINK_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/dlmconstants.h>
enum { enum {
DLM_STATUS_WAITING = 1, DLM_STATUS_WAITING = 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment