Commit 0a453383 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] Use fixed size buffer instead of kmalloc for m_class in ip_map

This avoids lots of bothersome memory management and is generally
cleaner. 
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 1e632d02
......@@ -90,7 +90,7 @@ static void svcauth_unix_domain_release(struct auth_domain *dom)
struct ip_map {
struct cache_head h;
char *m_class; /* e.g. "nfsd" */
char m_class[8]; /* e.g. "nfsd" */
struct in_addr m_addr;
struct unix_domain *m_client;
int m_add_change;
......@@ -104,7 +104,6 @@ void ip_map_put(struct cache_head *item, struct cache_detail *cd)
if (test_bit(CACHE_VALID, &item->flags) &&
!test_bit(CACHE_NEGATIVE, &item->flags))
auth_domain_put(&im->m_client->h);
kfree(im->m_class);
kfree(im);
}
}
......@@ -121,8 +120,7 @@ static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp)
}
static inline void ip_map_init(struct ip_map *new, struct ip_map *item)
{
new->m_class = item->m_class;
item->m_class = NULL;
strcpy(new->m_class, item->m_class);
new->m_addr.s_addr = item->m_addr.s_addr;
}
static inline void ip_map_update(struct ip_map *new, struct ip_map *item)
......@@ -171,6 +169,8 @@ static int ip_map_parse(struct cache_detail *cd,
/* class */
len = qword_get(&mesg, class, 50);
if (len <= 0) return -EINVAL;
if (len >= sizeof(ipm.m_class))
return -EINVAL;
/* ip address */
len = qword_get(&mesg, buf, 50);
......@@ -194,9 +194,7 @@ static int ip_map_parse(struct cache_detail *cd,
} else
dom = NULL;
ipm.m_class = strdup(class);
if (ipm.m_class == NULL)
return -ENOMEM;
strcpy(ipm.m_class, class);
ipm.m_addr.s_addr =
htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
ipm.h.flags = 0;
......@@ -212,7 +210,6 @@ static int ip_map_parse(struct cache_detail *cd,
ip_map_put(&ipmp->h, &ip_map_cache);
if (dom)
auth_domain_put(dom);
if (ipm.m_class) kfree(ipm.m_class);
if (!ipmp)
return -ENOMEM;
cache_flush();
......@@ -272,9 +269,7 @@ int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
if (dom->flavour != RPC_AUTH_UNIX)
return -EINVAL;
udom = container_of(dom, struct unix_domain, h);
ip.m_class = strdup("nfsd");
if (!ip.m_class)
return -ENOMEM;
strcpy(ip.m_class, "nfsd");
ip.m_addr = addr;
ip.m_client = udom;
ip.m_add_change = udom->addr_changes+1;
......@@ -282,7 +277,7 @@ int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
ip.h.expiry_time = NEVER;
ipmp = ip_map_lookup(&ip, 1);
if (ip.m_class) kfree(ip.m_class);
if (ipmp) {
ip_map_put(&ipmp->h, &ip_map_cache);
return 0;
......@@ -306,7 +301,7 @@ struct auth_domain *auth_unix_lookup(struct in_addr addr)
struct ip_map key, *ipm;
struct auth_domain *rv;
key.m_class = "nfsd";
strcpy(key.m_class, "nfsd");
key.m_addr = addr;
ipm = ip_map_lookup(&key, 0);
......@@ -368,7 +363,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, u32 *authp)
svc_putu32(resv, RPC_AUTH_NULL);
svc_putu32(resv, 0);
key.m_class = rqstp->rq_server->sv_program->pg_class;
strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class);
key.m_addr = rqstp->rq_addr.sin_addr;
ipm = ip_map_lookup(&key, 0);
......@@ -464,7 +459,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, u32 *authp)
}
key.m_class = rqstp->rq_server->sv_program->pg_class;
strcpy(key.m_class, rqstp->rq_server->sv_program->pg_class);
key.m_addr = rqstp->rq_addr.sin_addr;
......
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