Skip to contentSkip to conversation

fs/seq_file: remove some dead code

PATCH In review Dan Carpenter 2 participants 2 messages May 20, 2017 – May 23, 2017

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

PATCH 1/1 fs/seq_file: remove some dead code

We have never used this "err = PTR_ERR(p);" assignment and it annoys static checkers.

fs/seq_file.c +1 -3
index 13e8c092d4d2..d6f82ce288f4 100644
@@ -261,10 +261,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 (!p || IS_ERR(p))
 			break;
-		}
 		err = m->op->show(m, p);
 		if (seq_has_overflowed(m) || err) {
 			m->count = offs;
#1 lore raw
Quoted 12 lines · Dan Carpenter

We have never used this "err = PTR_ERR(p);" assignment and it annoys static checkers.

fs/seq_file.c +0 -0
index 13e8c092d4d2..d6f82ce288f4 100644
@@ -261,10 +261,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		size_t offs = m->count;

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

Quoted 10 lines
fs/seq_file.c +1 -3
 		loff_t next = pos;
 		p = m->op->next(m, p, &next);
-		if (!p || IS_ERR(p)) {
-			err = PTR_ERR(p);
+		if (!p || IS_ERR(p))
 			break;
-		}
 		err = m->op->show(m, p);
 		if (seq_has_overflowed(m) || err) {
 			m->count = offs;

I'm guessing the static analysis is reporting that "err" is unused, because it is clobbered after the end of the loop?

			if (likely(err <= 0))
				break;
		}
		pos = next;
	}
	m->op->stop(m, p);
	n = min(m->count, size);
	err = copy_to_user(buf, m->buf, n);
	if (err)
		goto Efault;

Unfortunately, this code dates back to the primordial "1da177e4" commit at the start of Git history, so history to see how it got into this state.

Presumably, copy_to_user() is called unconditionally to return all data read so far to userspace, and in that case "err" doesn't matter - something was returned to userspace. I was thinking that copy_to_user() should be skipped if "n == 0", so that the original "err" value is returned, but it may be that this is never true in the "Fill:" case (ugh, upper-case labels).

	n = min(m->count, size);
	if (n == 0)
		goto Done;

The logic isn't very clear here, so it isn't clear what the right change is.

Cheers, Andreas