Skip to contentSkip to conversation

procfs: returns ENOENT on opening the being-removed proc entry

PATCH In review FJCL) 荻野 大輔 2 participants 3 messages Jun 24, 2011 – Jun 30, 2011

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

PATCH 1/1 procfs: returns ENOENT on opening the being-removed proc entry

From: Daisuke Ohino <[email protected]>

opening the proc entry may return EINVAL if the entry is being removed, for example open("/proc/bus/pci/XX/YY") during the corresponding device is being hot-removed. The return value is inappropriate and should return ENOENT.

This return value comes from proc_reg_open().

fs/proc/inode.c:
-----------------------------------------------------------
static int proc_reg_open(struct inode *inode, struct file *file) {
(snip)

        if (!pde->proc_fops) {
                spin_unlock(&pde->pde_unload_lock);
                kfree(pdeo);
                return -EINVAL;
        }

(snip)
-----------------------------------------------------------

pde->proc_fops is NULL iff the proc entry is being removed. It is set by remove_proc_entry().

-----------------------------------------------------------
void remove_proc_entry(const char *name, struct proc_dir_entry*parent) {
(snip)

        /*
         * Stop accepting new callers into module. If you're
         * dynamically allocating ->proc_fops, save a pointer somewhere.
         */
        de->proc_fops = NULL;

(snip)
-----------------------------------------------------------

But POSIX says:

-----------------------------------------------------------
[EINVAL]
The implementation does not support synchronized I/O for this file.
-----------------------------------------------------------

Since removing proc entry is apparently not related to synchronized I/O, this function should return ENOENT in this case.

---
 fs/proc/inode.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/proc/inode.c +1 -1
index 74b48cf..7ed72d6 100644
@@ -319,7 +319,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 	if (!pde->proc_fops) {
 		spin_unlock(&pde->pde_unload_lock);
 		kfree(pdeo);
-		return -EINVAL;
+		return -ENOENT;
 	}
 	pde->pde_users++;
 	open = pde->proc_fops->open;

--

Since I don't subscribe LKML, please Cc me if you have any comment.

Thanks,
Daisuke

Reviewed-by on v1 1/1
#1 lore raw
Quoted 43 lines · On Fri, 24 Jun 2011 10:48:08 +0900 "FJCL) 荻野 大輔"…

From: Daisuke Ohino <[email protected]>

opening the proc entry may return EINVAL if the entry is being removed, for example open("/proc/bus/pci/XX/YY") during the corresponding device is being hot-removed. The return value is inappropriate and should return ENOENT.

This return value comes from proc_reg_open().

fs/proc/inode.c:
-----------------------------------------------------------
static int proc_reg_open(struct inode *inode, struct file *file) {
(snip)

        if (!pde->proc_fops) {
                spin_unlock(&pde->pde_unload_lock);
                kfree(pdeo);
                return -EINVAL;
        }

(snip)
-----------------------------------------------------------

pde->proc_fops is NULL iff the proc entry is being removed. It is set by remove_proc_entry().

-----------------------------------------------------------
void remove_proc_entry(const char *name, struct proc_dir_entry*parent) {
(snip)

        /*
         * Stop accepting new callers into module. If you're
         * dynamically allocating ->proc_fops, save a pointer somewhere.
         */
        de->proc_fops = NULL;

(snip)
-----------------------------------------------------------

But POSIX says:

-----------------------------------------------------------
[EINVAL]
The implementation does not support synchronized I/O for this file.
-----------------------------------------------------------

Quoted 4 lines

Since removing proc entry is apparently not related to synchronized I/O, this function should return ENOENT in this case.

It makes sense to me.

Add fsdevel to CC.

Quoted 31 lines
---
 fs/proc/inode.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/proc/inode.c +1 -2
index 74b48cf..7ed72d6 100644
@@ -319,7 +319,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 	if (!pde->proc_fops) {
 		spin_unlock(&pde->pde_unload_lock);
 		kfree(pdeo);
-		return -EINVAL;
+		return -ENOENT;
 	}
 	pde->pde_users++;
 	open = pde->proc_fops->open;
--

Since I don't subscribe LKML, please Cc me if you have any comment.

Thanks,
Daisuke

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

Hello.

Though I posted the following patch a week ago,
there is no objection, and Kame-san reviewed it.

I hope merge it by someone if possible.
(I don't find maintainer's name for procfs.)

---
I changed the return value to ENOENT.
This return value is then returned when opening the proc entry that have been removed.
For example, open("/proc/bus/pci/XX/YY") during the corresponding device is being hot-removed.

---
 fs/proc/inode.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/proc/inode.c +1 -1
index 74b48cf..7ed72d6 100644
@@ -319,7 +319,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 	if (!pde->proc_fops) {
 		spin_unlock(&pde->pde_unload_lock);
 		kfree(pdeo);
-		return -EINVAL;
+		return -ENOENT;
 	}
 	pde->pde_users++;
 	open = pde->proc_fops->open;

--

Thanks.

Signature · 1 line
Daisuke Ogino