[PATCH -next 0/2] seq: Convert seq_puts and seq_putc to return void

STALE4312d

5 messages, 4 authors, 2014-11-12 · open the first message on its own page

[PATCH -next 0/2] seq: Convert seq_puts and seq_putc to return void

From: Joe Perches <joe@perches.com>
Date: 2014-11-10 18:58:55

These are error prone, so return void adn use seq_has_overflowed instead

Joe Perches (2):
  seq_puts: Convert to return void and convert uses too.
  seq_putc: Convert to return void and convert uses too.

 drivers/char/ipmi/ipmi_msghandler.c                |  4 +-
 drivers/parisc/ccio-dma.c                          |  7 +-
 drivers/regulator/dbx500-prcmu.c                   | 21 ++----
 drivers/usb/gadget/udc/goku_udc.c                  | 81 +++++++++++-----------
 drivers/watchdog/bcm_kona_wdt.c                    | 43 +++++++-----
 fs/seq_file.c                                      | 26 +++----
 include/linux/seq_file.h                           |  4 +-
 ipc/util.c                                         |  6 +-
 .../netfilter/nf_conntrack_l3proto_ipv4_compat.c   |  4 +-
 net/netfilter/nf_conntrack_expect.c                |  4 +-
 10 files changed, 105 insertions(+), 95 deletions(-)

-- 
2.1.2

[PATCH -next 2/2] seq_putc: Convert to return void and convert uses too.

From: Joe Perches <joe@perches.com>
Date: 2014-11-10 18:58:57

Using the return value of seq_putc is error-prone, so
make it return void instead.

Reverse the logic in seq_putc to make it like seq_puts.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/char/ipmi/ipmi_msghandler.c                   |  4 +++-
 fs/seq_file.c                                         | 11 ++++++-----
 include/linux/seq_file.h                              |  2 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c |  4 +++-
 net/netfilter/nf_conntrack_expect.c                   |  4 +++-
 5 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index f816211..c12fb30 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1953,7 +1953,9 @@ static int smi_ipmb_proc_show(struct seq_file *m, void *v)
 	seq_printf(m, "%x", intf->channels[0].address);
 	for (i = 1; i < IPMI_MAX_CHANNELS; i++)
 		seq_printf(m, " %x", intf->channels[i].address);
-	return seq_putc(m, '\n');
+	seq_putc(m, '\n');
+
+	return 0;
 }
 
 static int smi_ipmb_proc_open(struct inode *inode, struct file *file)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index e6be05a..5ca5af9 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -673,13 +673,14 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops,
 }
 EXPORT_SYMBOL(seq_open_private);
 
-int seq_putc(struct seq_file *m, char c)
+void seq_putc(struct seq_file *m, char c)
 {
-	if (m->count < m->size) {
-		m->buf[m->count++] = c;
-		return 0;
+	if (m->count >= m->size) {
+		seq_set_overflow(m);
+		return;
 	}
-	return -1;
+
+	m->buf[m->count++] = c;
 }
 EXPORT_SYMBOL(seq_putc);
 
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 9b02cb6..c1e47ff 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -115,7 +115,7 @@ ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
 loff_t seq_lseek(struct file *, loff_t, int);
 int seq_release(struct inode *, struct file *);
 int seq_escape(struct seq_file *, const char *, const char *);
-int seq_putc(struct seq_file *m, char c);
+void seq_putc(struct seq_file *m, char c);
 void seq_puts(struct seq_file *m, const char *s);
 int seq_write(struct seq_file *seq, const void *data, size_t len);
 
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
index a460a87..f0dfe92 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
@@ -300,7 +300,9 @@ static int exp_seq_show(struct seq_file *s, void *v)
 		    __nf_ct_l3proto_find(exp->tuple.src.l3num),
 		    __nf_ct_l4proto_find(exp->tuple.src.l3num,
 					 exp->tuple.dst.protonum));
-	return seq_putc(s, '\n');
+	seq_putc(s, '\n');
+
+	return 0;
 }
 
 static const struct seq_operations exp_seq_ops = {
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 91a1837..7a17070 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -561,7 +561,9 @@ static int exp_seq_show(struct seq_file *s, void *v)
 				   helper->expect_policy[expect->class].name);
 	}
 
-	return seq_putc(s, '\n');
+	seq_putc(s, '\n');
+
+	return 0;
 }
 
 static const struct seq_operations exp_seq_ops = {
-- 
2.1.2


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk

Re: [PATCH -next 2/2] seq_putc: Convert to return void and convert uses too.

From: Petr Mladek <hidden>
Date: 2014-11-11 13:47:40

On Mon 2014-11-10 10:58:57, Joe Perches wrote:
Using the return value of seq_putc is error-prone, so
make it return void instead.

Reverse the logic in seq_putc to make it like seq_puts.

Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Petr Mladek <redacted>

The changes are correct. The show() functions should return 0
even when there is an overflow. They are called by traverse()
from seq_read() that might increase the buffer size and try again.


Best Regards,
Petr

Re: [PATCH -next 2/2] seq_putc: Convert to return void and convert uses too.

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: 2014-11-12 12:29:00

On Tue, Nov 11, 2014 at 02:47:40PM +0100, Petr Mladek wrote:
On Mon 2014-11-10 10:58:57, Joe Perches wrote:
quoted
Using the return value of seq_putc is error-prone, so
make it return void instead.

Reverse the logic in seq_putc to make it like seq_puts.

Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Petr Mladek <redacted>

The changes are correct. The show() functions should return 0
even when there is an overflow. They are called by traverse()
from seq_read() that might increase the buffer size and try again.
Just in case you need this for the netfilter chunks:

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Thanks.

Re: [PATCH -next 2/2] seq_putc: Convert to return void and convert uses too.

From: Corey Minyard <hidden>
Date: 2014-11-12 15:25:00

Ok by me for the IPMI part.

Reviewed-by: Corey Minyard <redacted>

On 11/10/2014 12:58 PM, Joe Perches wrote:
quoted hunk
Using the return value of seq_putc is error-prone, so
make it return void instead.

Reverse the logic in seq_putc to make it like seq_puts.

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/char/ipmi/ipmi_msghandler.c                   |  4 +++-
 fs/seq_file.c                                         | 11 ++++++-----
 include/linux/seq_file.h                              |  2 +-
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c |  4 +++-
 net/netfilter/nf_conntrack_expect.c                   |  4 +++-
 5 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index f816211..c12fb30 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -1953,7 +1953,9 @@ static int smi_ipmb_proc_show(struct seq_file *m, void *v)
 	seq_printf(m, "%x", intf->channels[0].address);
 	for (i = 1; i < IPMI_MAX_CHANNELS; i++)
 		seq_printf(m, " %x", intf->channels[i].address);
-	return seq_putc(m, '\n');
+	seq_putc(m, '\n');
+
+	return 0;
 }
 
 static int smi_ipmb_proc_open(struct inode *inode, struct file *file)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index e6be05a..5ca5af9 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -673,13 +673,14 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops,
 }
 EXPORT_SYMBOL(seq_open_private);
 
-int seq_putc(struct seq_file *m, char c)
+void seq_putc(struct seq_file *m, char c)
 {
-	if (m->count < m->size) {
-		m->buf[m->count++] = c;
-		return 0;
+	if (m->count >= m->size) {
+		seq_set_overflow(m);
+		return;
 	}
-	return -1;
+
+	m->buf[m->count++] = c;
 }
 EXPORT_SYMBOL(seq_putc);
 
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 9b02cb6..c1e47ff 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -115,7 +115,7 @@ ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
 loff_t seq_lseek(struct file *, loff_t, int);
 int seq_release(struct inode *, struct file *);
 int seq_escape(struct seq_file *, const char *, const char *);
-int seq_putc(struct seq_file *m, char c);
+void seq_putc(struct seq_file *m, char c);
 void seq_puts(struct seq_file *m, const char *s);
 int seq_write(struct seq_file *seq, const void *data, size_t len);
 
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
index a460a87..f0dfe92 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4_compat.c
@@ -300,7 +300,9 @@ static int exp_seq_show(struct seq_file *s, void *v)
 		    __nf_ct_l3proto_find(exp->tuple.src.l3num),
 		    __nf_ct_l4proto_find(exp->tuple.src.l3num,
 					 exp->tuple.dst.protonum));
-	return seq_putc(s, '\n');
+	seq_putc(s, '\n');
+
+	return 0;
 }
 
 static const struct seq_operations exp_seq_ops = {
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 91a1837..7a17070 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -561,7 +561,9 @@ static int exp_seq_show(struct seq_file *s, void *v)
 				   helper->expect_policy[expect->class].name);
 	}
 
-	return seq_putc(s, '\n');
+	seq_putc(s, '\n');
+
+	return 0;
 }
 
 static const struct seq_operations exp_seq_ops = {

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help