staging: lustre: Convert more LIBCFS_ALLOC allocation to direct GFP_KERNEL

None of these need to be GFP_NOFS, so use GFP_KERNEL explicitly
with kmalloc(), kvmalloc(), or kvmalloc_array().
Change matching LIBCFS_FREE() to kfree() or kvfree()

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
NeilBrown 2018-01-09 12:19:38 +11:00 committed by Greg Kroah-Hartman
parent 12e46c461c
commit 343fb6af08
4 changed files with 26 additions and 38 deletions

View File

@ -146,7 +146,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return -EINVAL; return -EINVAL;
} }
LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len); *hdr_pp = kvmalloc(hdr.ioc_len, GFP_KERNEL);
if (!*hdr_pp) if (!*hdr_pp)
return -ENOMEM; return -ENOMEM;
@ -164,7 +164,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return 0; return 0;
free: free:
LIBCFS_FREE(*hdr_pp, hdr.ioc_len); kvfree(*hdr_pp);
return err; return err;
} }

View File

@ -156,7 +156,7 @@ int libcfs_ioctl(unsigned long cmd, void __user *uparam)
break; } break; }
} }
out: out:
LIBCFS_FREE(hdr, hdr->ioc_len); kvfree(hdr);
return err; return err;
} }
@ -302,7 +302,7 @@ static int __proc_cpt_table(void *data, int write,
LASSERT(cfs_cpt_table); LASSERT(cfs_cpt_table);
while (1) { while (1) {
LIBCFS_ALLOC(buf, len); buf = kzalloc(len, GFP_KERNEL);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
@ -311,7 +311,7 @@ static int __proc_cpt_table(void *data, int write,
break; break;
if (rc == -EFBIG) { if (rc == -EFBIG) {
LIBCFS_FREE(buf, len); kfree(buf);
len <<= 1; len <<= 1;
continue; continue;
} }
@ -325,8 +325,7 @@ static int __proc_cpt_table(void *data, int write,
rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
out: out:
if (buf) kfree(buf);
LIBCFS_FREE(buf, len);
return rc; return rc;
} }

View File

@ -108,7 +108,8 @@ lnet_create_remote_nets_table(void)
LASSERT(!the_lnet.ln_remote_nets_hash); LASSERT(!the_lnet.ln_remote_nets_hash);
LASSERT(the_lnet.ln_remote_nets_hbits > 0); LASSERT(the_lnet.ln_remote_nets_hbits > 0);
LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash)); hash = kvmalloc_array(LNET_REMOTE_NETS_HASH_SIZE, sizeof(*hash),
GFP_KERNEL);
if (!hash) { if (!hash) {
CERROR("Failed to create remote nets hash table\n"); CERROR("Failed to create remote nets hash table\n");
return -ENOMEM; return -ENOMEM;
@ -131,9 +132,7 @@ lnet_destroy_remote_nets_table(void)
for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++)
LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i])); LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i]));
LIBCFS_FREE(the_lnet.ln_remote_nets_hash, kvfree(the_lnet.ln_remote_nets_hash);
LNET_REMOTE_NETS_HASH_SIZE *
sizeof(the_lnet.ln_remote_nets_hash[0]));
the_lnet.ln_remote_nets_hash = NULL; the_lnet.ln_remote_nets_hash = NULL;
} }
@ -831,7 +830,7 @@ lnet_ping_info_create(int num_ni)
unsigned int infosz; unsigned int infosz;
infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]); infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]);
LIBCFS_ALLOC(ping_info, infosz); ping_info = kvzalloc(infosz, GFP_KERNEL);
if (!ping_info) { if (!ping_info) {
CERROR("Can't allocate ping info[%d]\n", num_ni); CERROR("Can't allocate ping info[%d]\n", num_ni);
return NULL; return NULL;
@ -864,9 +863,7 @@ lnet_get_ni_count(void)
static inline void static inline void
lnet_ping_info_free(struct lnet_ping_info *pinfo) lnet_ping_info_free(struct lnet_ping_info *pinfo)
{ {
LIBCFS_FREE(pinfo, kvfree(pinfo);
offsetof(struct lnet_ping_info,
pi_ni[pinfo->pi_nnis]));
} }
static void static void
@ -2160,7 +2157,7 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms,
if (id.pid == LNET_PID_ANY) if (id.pid == LNET_PID_ANY)
id.pid = LNET_PID_LUSTRE; id.pid = LNET_PID_LUSTRE;
LIBCFS_ALLOC(info, infosz); info = kzalloc(infosz, GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
@ -2310,6 +2307,6 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms,
LASSERT(!rc2); LASSERT(!rc2);
out_0: out_0:
LIBCFS_FREE(info, infosz); kfree(info);
return rc; return rc;
} }

View File

@ -108,10 +108,8 @@ lnet_ni_free(struct lnet_ni *ni)
kfree(ni->ni_lnd_tunables); kfree(ni->ni_lnd_tunables);
for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) { for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++)
LIBCFS_FREE(ni->ni_interfaces[i], kfree(ni->ni_interfaces[i]);
strlen(ni->ni_interfaces[i]) + 1);
}
/* release reference to net namespace */ /* release reference to net namespace */
if (ni->ni_net_ns) if (ni->ni_net_ns)
@ -197,7 +195,6 @@ int
lnet_parse_networks(struct list_head *nilist, char *networks) lnet_parse_networks(struct list_head *nilist, char *networks)
{ {
struct cfs_expr_list *el = NULL; struct cfs_expr_list *el = NULL;
int tokensize;
char *tokens; char *tokens;
char *str; char *str;
char *tmp; char *tmp;
@ -218,15 +215,12 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
return -EINVAL; return -EINVAL;
} }
tokensize = strlen(networks) + 1; tokens = kstrdup(networks, GFP_KERNEL);
LIBCFS_ALLOC(tokens, tokensize);
if (!tokens) { if (!tokens) {
CERROR("Can't allocate net tokens\n"); CERROR("Can't allocate net tokens\n");
return -ENOMEM; return -ENOMEM;
} }
memcpy(tokens, networks, tokensize);
tmp = tokens; tmp = tokens;
str = tokens; str = tokens;
@ -348,14 +342,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
* The newly allocated ni_interfaces[] can be * The newly allocated ni_interfaces[] can be
* freed when freeing the NI * freed when freeing the NI
*/ */
LIBCFS_ALLOC(ni->ni_interfaces[niface], ni->ni_interfaces[niface] = kstrdup(iface, GFP_KERNEL);
strlen(iface) + 1);
if (!ni->ni_interfaces[niface]) { if (!ni->ni_interfaces[niface]) {
CERROR("Can't allocate net interface name\n"); CERROR("Can't allocate net interface name\n");
goto failed; goto failed;
} }
strncpy(ni->ni_interfaces[niface], iface,
strlen(iface));
niface++; niface++;
iface = comma; iface = comma;
} while (iface); } while (iface);
@ -383,7 +374,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
list_for_each(temp_node, nilist) list_for_each(temp_node, nilist)
nnets++; nnets++;
LIBCFS_FREE(tokens, tokensize); kfree(tokens);
return nnets; return nnets;
failed_syntax: failed_syntax:
@ -399,7 +390,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
if (el) if (el)
cfs_expr_list_free(el); cfs_expr_list_free(el);
LIBCFS_FREE(tokens, tokensize); kfree(tokens);
return -EINVAL; return -EINVAL;
} }
@ -423,7 +414,7 @@ lnet_new_text_buf(int str_len)
return NULL; return NULL;
} }
LIBCFS_ALLOC(ltb, nob); ltb = kzalloc(nob, GFP_KERNEL);
if (!ltb) if (!ltb)
return NULL; return NULL;
@ -437,7 +428,7 @@ static void
lnet_free_text_buf(struct lnet_text_buf *ltb) lnet_free_text_buf(struct lnet_text_buf *ltb)
{ {
lnet_tbnob -= ltb->ltb_size; lnet_tbnob -= ltb->ltb_size;
LIBCFS_FREE(ltb, ltb->ltb_size); kfree(ltb);
} }
static void static void
@ -1155,7 +1146,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
if (nif <= 0) if (nif <= 0)
return nif; return nif;
LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); ipaddrs = kzalloc(nif * sizeof(*ipaddrs), GFP_KERNEL);
if (!ipaddrs) { if (!ipaddrs) {
CERROR("Can't allocate ipaddrs[%d]\n", nif); CERROR("Can't allocate ipaddrs[%d]\n", nif);
lnet_ipif_free_enumeration(ifnames, nif); lnet_ipif_free_enumeration(ifnames, nif);
@ -1188,7 +1179,8 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
*ipaddrsp = ipaddrs; *ipaddrsp = ipaddrs;
} else { } else {
if (nip > 0) { if (nip > 0) {
LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2)); ipaddrs2 = kzalloc(nip * sizeof(*ipaddrs2),
GFP_KERNEL);
if (!ipaddrs2) { if (!ipaddrs2) {
CERROR("Can't allocate ipaddrs[%d]\n", nip); CERROR("Can't allocate ipaddrs[%d]\n", nip);
nip = -ENOMEM; nip = -ENOMEM;
@ -1199,7 +1191,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp)
rc = nip; rc = nip;
} }
} }
LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); kfree(ipaddrs);
} }
return nip; return nip;
} }
@ -1225,7 +1217,7 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets)
} }
rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip); rc = lnet_match_networks(networksp, ip2nets, ipaddrs, nip);
LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); kfree(ipaddrs);
if (rc < 0) { if (rc < 0) {
LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc); LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc);