* [PATCH 0/3 v2] Trivial code clean for procfs @ 2012-09-05 12:17 yan 2012-09-05 12:17 ` [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed yan ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: yan @ 2012-09-05 12:17 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Changed from v1 : Add detailed changelog (suggested by Andrew Morton) yan (3): proc: return -ENOMEM when inode allocation failed proc: no need to initialize proc_inode->fd in proc_get_inode proc: use kzalloc instead of kmalloc and memset fs/proc/generic.c | 5 ++--- fs/proc/inode.c | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) -- 1.7.9.5 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed 2012-09-05 12:17 [PATCH 0/3 v2] Trivial code clean for procfs yan @ 2012-09-05 12:17 ` yan 2012-09-05 12:17 ` [PATCH 2/3 v2] proc : no need to initialize proc_inode->fd in proc_get_inode yan 2012-09-05 12:17 ` [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset yan 2 siblings, 0 replies; 5+ messages in thread From: yan @ 2012-09-05 12:17 UTC (permalink / raw) To: akpm; +Cc: linux-kernel If proc_get_inode() returns NULL then presumably it encountered memory exhaustion. proc_lookup_de() should return -ENOMEM in this case, not -EINVAL. Signed-off-by: yan <clouds.yan@gmail.com> --- fs/proc/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index b3647fe..9e8f631 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -427,7 +427,7 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir, if (!memcmp(dentry->d_name.name, de->name, de->namelen)) { pde_get(de); spin_unlock(&proc_subdir_lock); - error = -EINVAL; + error = -ENOMEM; inode = proc_get_inode(dir->i_sb, de); goto out_unlock; } -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3 v2] proc : no need to initialize proc_inode->fd in proc_get_inode 2012-09-05 12:17 [PATCH 0/3 v2] Trivial code clean for procfs yan 2012-09-05 12:17 ` [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed yan @ 2012-09-05 12:17 ` yan 2012-09-05 12:17 ` [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset yan 2 siblings, 0 replies; 5+ messages in thread From: yan @ 2012-09-05 12:17 UTC (permalink / raw) To: akpm; +Cc: linux-kernel proc_get_inode() obtains the inode via a call to iget_locked(). iget_locked() calls alloc_inode() which will call proc_alloc_inode() which clears proc_inode.fd, so there is no need to clear this field in proc_get_inode(). If iget_locked() instead found the inode via find_inode_fast(), that inode will not have I_NEW set so this change has no effect. Signed-off-by: yan <clouds.yan@gmail.com> --- fs/proc/inode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 7ac817b..3b22bbd 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -450,7 +450,6 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) return NULL; if (inode->i_state & I_NEW) { inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; - PROC_I(inode)->fd = 0; PROC_I(inode)->pde = de; if (de->mode) { -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset 2012-09-05 12:17 [PATCH 0/3 v2] Trivial code clean for procfs yan 2012-09-05 12:17 ` [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed yan 2012-09-05 12:17 ` [PATCH 2/3 v2] proc : no need to initialize proc_inode->fd in proc_get_inode yan @ 2012-09-05 12:17 ` yan 2012-09-05 21:37 ` Andrew Morton 2 siblings, 1 reply; 5+ messages in thread From: yan @ 2012-09-05 12:17 UTC (permalink / raw) To: akpm; +Cc: linux-kernel Part of the memory will be written twice after this change, but that should be negligible. Signed-off-by: yan <clouds.yan@gmail.com> --- fs/proc/generic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 9e8f631..38de015 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -616,10 +616,9 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, len = strlen(fn); - ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); + ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); if (!ent) goto out; - memset(ent, 0, sizeof(struct proc_dir_entry)); memcpy(ent->name, fn, len + 1); ent->namelen = len; ent->mode = mode; -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset 2012-09-05 12:17 ` [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset yan @ 2012-09-05 21:37 ` Andrew Morton 0 siblings, 0 replies; 5+ messages in thread From: Andrew Morton @ 2012-09-05 21:37 UTC (permalink / raw) To: yan; +Cc: linux-kernel On Wed, 5 Sep 2012 20:17:17 +0800 yan <clouds.yan@gmail.com> wrote: > Part of the memory will be written twice after this change, but that > should be negligible. > > ... > > --- a/fs/proc/generic.c > +++ b/fs/proc/generic.c > @@ -616,10 +616,9 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, > > len = strlen(fn); > > - ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); > + ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); > if (!ent) goto out; > > - memset(ent, 0, sizeof(struct proc_dir_entry)); > memcpy(ent->name, fn, len + 1); > ent->namelen = len; > ent->mode = mode; I'm not sure that I really like the idea of adding this additional overhead. But sure, it won't matter to anyone at all. While we're digging around in __proc_create(), how about we fix a few other things? From: Andrew Morton <akpm@linux-foundation.org> Subject: proc-use-kzalloc-instead-of-kmalloc-and-memset-fix fix __proc_create() coding-style issues, remove unneeded zero-initialisations Cc: yan <clouds.yan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> --- fs/proc/generic.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff -puN fs/proc/generic.c~proc-use-kzalloc-instead-of-kmalloc-and-memset-fix fs/proc/generic.c --- a/fs/proc/generic.c~proc-use-kzalloc-instead-of-kmalloc-and-memset-fix +++ a/fs/proc/generic.c @@ -605,7 +605,8 @@ static struct proc_dir_entry *__proc_cre unsigned int len; /* make sure name is valid */ - if (!name || !strlen(name)) goto out; + if (!name || !strlen(name)) + goto out; if (xlate_proc_name(name, parent, &fn) != 0) goto out; @@ -617,18 +618,17 @@ static struct proc_dir_entry *__proc_cre len = strlen(fn); ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); - if (!ent) goto out; + if (!ent) + goto out; memcpy(ent->name, fn, len + 1); ent->namelen = len; ent->mode = mode; ent->nlink = nlink; atomic_set(&ent->count, 1); - ent->pde_users = 0; spin_lock_init(&ent->pde_unload_lock); - ent->pde_unload_completion = NULL; INIT_LIST_HEAD(&ent->pde_openers); - out: +out: return ent; } _ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-05 21:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-09-05 12:17 [PATCH 0/3 v2] Trivial code clean for procfs yan 2012-09-05 12:17 ` [PATCH 1/3 v2] proc: return -ENOMEM when inode allocation failed yan 2012-09-05 12:17 ` [PATCH 2/3 v2] proc : no need to initialize proc_inode->fd in proc_get_inode yan 2012-09-05 12:17 ` [PATCH 3/3 v2] proc: use kzalloc instead of kmalloc and memset yan 2012-09-05 21:37 ` Andrew Morton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).