From: Cong Wang <xiyou.wangcong@gmail.com>
To: yan yan <clouds.yan@gmail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] proc: return -ENOMEM when inode allocation failed
Date: Wed, 05 Sep 2012 15:15:46 +0800 [thread overview]
Message-ID: <5046FC22.3050509@gmail.com> (raw)
In-Reply-To: <CAH+=+MG=9189mS7+Cb85-PV51EX1Df-zGmZ3u4YtSsEfmphYUQ@mail.gmail.com>
On 09/04/2012 05:22 PM, yan yan wrote:
> 2012/9/4 Cong Wang <xiyou.wangcong@gmail.com>:
>> On 09/03/2012 10:14 PM, yan wrote:
>>>
>>> Signed-off-by: yan <clouds.yan@gmail.com>
>>
>>
>> Please provide a changelog to explain why we need this patch.
>
> I think the title is self explained.
>
>
>>> ---
>>> 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;
>>
>>
>> Why the !memcmp() case is related with ENOMEM ??
>
> We are presetting 'error' here. The following proc_get_inode() will try
> to get an inode, either from inode cache or allocate a new one (and fill it).
>
> If we get a NULL inode, that means allocation failed. That's how
> ENOMEM involved.
Then the following patch is probably better than yours:
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index b3647fe..6b22913 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -427,12 +427,16 @@ 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;
inode = proc_get_inode(dir->i_sb, de);
+ if (!inode) {
+ error = -ENOMEM;
+ goto out_put;
+ }
goto out_unlock;
}
}
spin_unlock(&proc_subdir_lock);
+
out_unlock:
if (inode) {
@@ -440,6 +444,8 @@ out_unlock:
d_add(dentry, inode);
return NULL;
}
+out_put:
+
if (de)
pde_put(de);
return ERR_PTR(error);
next prev parent reply other threads:[~2012-09-05 7:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 14:14 [PATCH 0/3] Trivial code clean for procfs yan
2012-09-03 14:14 ` [PATCH 1/3] proc: return -ENOMEM when inode allocation failed yan
2012-09-04 0:38 ` Ryan Mallon
2012-09-04 3:02 ` Cong Wang
2012-09-04 9:22 ` yan yan
2012-09-04 22:41 ` Andrew Morton
2012-09-05 7:15 ` Cong Wang [this message]
2012-09-05 7:57 ` yan yan
2012-09-03 14:14 ` [PATCH 2/3] proc : no need to initialize proc_inode->fd in proc_get_inode yan
2012-09-04 22:49 ` Andrew Morton
2012-09-03 14:14 ` [PATCH 3/3] proc: use kzalloc instead of kmalloc and memset yan
2012-09-04 0:44 ` Ryan Mallon
2012-09-04 9:10 ` yan yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5046FC22.3050509@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=clouds.yan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.