From: MaJun <majun258@huawei.com>
To: <ebiederm@xmission.com>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<akpm@linux-foundation.org>, <dhowells@redhat.com>,
<Waiman.Long@hp.com>, <viro@zeniv.linux.org.uk>,
<dingtianhong@huawei.com>, <guohanjun@huawei.com>,
<majun258@huawei.com>, <fanjinke1@huawei.com>
Subject: [PATCH] Change the spin_lock/unlock_irq interface in proc_alloc_inum() function
Date: Wed, 2 Mar 2016 10:47:59 +0800 [thread overview]
Message-ID: <1456886879-28128-1-git-send-email-majun258@huawei.com> (raw)
From: Ma Jun <majun258@huawei.com>
The spin_lock/unlock_irq interface is not safe when this function is called
at some case which need irq disabled.
For example:
spin_lock_irqsave()
|
request_irq() --> proc_alloc_inum()
|
spin_unlock_irqrestore()
Reported-by: Fan Jinke <fanjinke1@huawei.com>
Signed-off-by: Ma Jun <majun258@huawei.com>
---
fs/proc/generic.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index ff3ffc7..4fc1502 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -191,23 +191,24 @@ int proc_alloc_inum(unsigned int *inum)
{
unsigned int i;
int error;
+ unsigned long flags;
retry:
if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL))
return -ENOMEM;
- spin_lock_irq(&proc_inum_lock);
+ spin_lock_irqsave(&proc_inum_lock, flags);
error = ida_get_new(&proc_inum_ida, &i);
- spin_unlock_irq(&proc_inum_lock);
+ spin_unlock_irqrestore(&proc_inum_lock, flags);
if (error == -EAGAIN)
goto retry;
else if (error)
return error;
if (i > UINT_MAX - PROC_DYNAMIC_FIRST) {
- spin_lock_irq(&proc_inum_lock);
+ spin_lock_irqsave(&proc_inum_lock, flags);
ida_remove(&proc_inum_ida, i);
- spin_unlock_irq(&proc_inum_lock);
+ spin_unlock_irqrestore(&proc_inum_lock, flags);
return -ENOSPC;
}
*inum = PROC_DYNAMIC_FIRST + i;
--
1.7.1
next reply other threads:[~2016-03-02 2:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 2:47 MaJun [this message]
2016-03-02 3:09 ` Al Viro
2016-03-02 6:32 ` majun (F)
2016-03-02 17:29 ` Al Viro
2016-03-02 17:57 ` Al Viro
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=1456886879-28128-1-git-send-email-majun258@huawei.com \
--to=majun258@huawei.com \
--cc=Waiman.Long@hp.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=dingtianhong@huawei.com \
--cc=ebiederm@xmission.com \
--cc=fanjinke1@huawei.com \
--cc=guohanjun@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®