Skip to contentSkip to conversation

nfsd: Use kmemdup rather than duplicating its implementation

PATCH Applied Fuqian Huang 1 participant 1 message Jul 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 29/35 nfsd: Use kmemdup rather than duplicating its implementation

kmemdup is introduced to duplicate a region of memory in a neat way. Rather than kmalloc/kzalloc + memcpy, which the programmer needs to write the size twice (sometimes lead to mistakes), kmemdup improves readability, leads to smaller code and also reduce the chances of mistakes. Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

---
Changes in v2:
- Fix a typo in commit message (memset -> memcpy)

 fs/nfsd/nfscache.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfscache.c +1 -2
index da52b594362a..c0226f0281af 100644
@@ -533,13 +533,12 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
 	case RC_REPLBUFF:
 		cachv = &rp->c_replvec;
 		bufsize = len << 2;
-		cachv->iov_base = kmalloc(bufsize, GFP_KERNEL);
+		cachv->iov_base = kmemdup(statp, bufsize, GFP_KERNEL);
 		if (!cachv->iov_base) {
 			nfsd_reply_cache_free(b, rp);
 			return;
 		}
 		cachv->iov_len = bufsize;
-		memcpy(cachv->iov_base, statp, bufsize);
 		break;
 	case RC_NOCACHE:
 		nfsd_reply_cache_free(b, rp);
Signature · 1 line
2.11.0