Skip to contentSkip to conversation

fs/seq_file: Fix warning of passing zero to 'PTR_ERR'

PATCH In review Vasyl Gomonovych 3 participants 5 messages Dec 7, 2017 – Dec 8, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/seq_file: Fix warning of passing zero to 'PTR_ERR'

p could be NULL and passing into PTR_ERR

---
 fs/seq_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/seq_file.c +2 -2
index 4be761c..8b700b9 100644
@@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		size_t offs = m->count;
 		loff_t next = pos;
 		p = m->op->next(m, p, &next);
-		if (!p || IS_ERR(p)) {
-			err = PTR_ERR(p);
+		if (IS_ERR(p)) {
+			err = (!p ? -EFAULT : PTR_ERR(p));
 			break;
 		}
 		err = m->op->show(m, p);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 1 line · Vasyl Gomonovych

p could be NULL and passing into PTR_ERR

What makes you think this is correct?

To quote the documentation:

The next function to implement is called, amazingly, next(); its job is to move the iterator forward to the next position in the sequence. The example module can simply increment the position by one; more useful modules will do what is needed to step through some data structure. The next() function returns a new iterator, or NULL if the sequence is complete. Here's the example version:

So if it returns NULL, we want to set err to 0 and break. Which is, um, exactly what the code does.

Did you test this at all?

Quoted 23 lines
---
 fs/seq_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/seq_file.c +2 -2
index 4be761c..8b700b9 100644
@@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		size_t offs = m->count;
 		loff_t next = pos;
 		p = m->op->next(m, p, &next);
-		if (!p || IS_ERR(p)) {
-			err = PTR_ERR(p);
+		if (IS_ERR(p)) {
+			err = (!p ? -EFAULT : PTR_ERR(p));
 			break;
 		}
 		err = m->op->show(m, p);
Signature · 1 line
1.9.1
maintainer
#2 lore raw
In reply to Vasyl Gomonovych
Quoted 12 lines · Vasyl Gomonovych

p could be NULL and passing into PTR_ERR

---
 fs/seq_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/seq_file.c +0 -0
index 4be761c..8b700b9 100644

fs/seq_file.c ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) · line 266

Quoted 7 lines
fs/seq_file.c +2 -2
@@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		size_t offs = m->count;
 		loff_t next = pos;
 		p = m->op->next(m, p, &next);
-		if (!p || IS_ERR(p)) {
-			err = PTR_ERR(p);
+		if (IS_ERR(p)) {
+			err = (!p ? -EFAULT : PTR_ERR(p));

What does it fix, if I might ask? And while we are at it, would you mind explaining the reasoning behind that change? Or, say, testing done to it...

maintainer
#3 lore raw
Quoted 8 lines · Al Viro
Quoted 7 lines · Vasyl Gomonovych

p could be NULL and passing into PTR_ERR

---
 fs/seq_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines

fs/seq_file.c ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) · line 266

Quoted 12 lines
fs/seq_file.c +2 -2
index 4be761c..8b700b9 100644
@@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		size_t offs = m->count;
 		loff_t next = pos;
 		p = m->op->next(m, p, &next);
-		if (!p || IS_ERR(p)) {
-			err = PTR_ERR(p);
+		if (IS_ERR(p)) {
+			err = (!p ? -EFAULT : PTR_ERR(p));

What does it fix, if I might ask? And while we are at it, would you mind explaining the reasoning behind that change? Or, say, testing done to it...

While we are at it, where has that -EFAULT come from? And how would it be ever reached, seeing that IS_ERR(NULL) is false?

#4 lore raw

Hi,

Guys sorry for this idiotic piece of code.
Yesterday after doc seq_file.txt read I did not catch real way of work there. And made this shit.
Sorry.

Regards Vasyl

Quoted 28 lines · Al Viro
Quoted 8 lines · Al Viro
Quoted 7 lines · Vasyl Gomonovych

p could be NULL and passing into PTR_ERR

---
 fs/seq_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines

fs/seq_file.c ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) · line 266

Quoted 12 lines
fs/seq_file.c +2 -2
index 4be761c..8b700b9 100644
@@ -262,8 +262,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
            size_t offs = m->count;
            loff_t next = pos;
            p = m->op->next(m, p, &next);
-           if (!p || IS_ERR(p)) {
-                   err = PTR_ERR(p);
+           if (IS_ERR(p)) {
+                   err = (!p ? -EFAULT : PTR_ERR(p));

What does it fix, if I might ask? And while we are at it, would you mind explaining the reasoning behind that change? Or, say, testing done to it...

While we are at it, where has that -EFAULT come from? And how would it be ever reached, seeing that IS_ERR(NULL) is false?

Signature · 1 line
Доброї вам пори дня.