Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ce74dd6 authored by Al Viro's avatar Al Viro
Browse files

Merge tag 'trace-seq-file-cleanup' of...

Merge tag 'trace-seq-file-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace into for-next

Pull the beginning of seq_file cleanup from Steven:
  "I'm looking to clean up the seq_file code and to eventually merge the
  trace_seq code with seq_file as well, since they basically do the same thing.

  Part of this process is to remove the return code of seq_printf() and friends
  as they are rather inconsistent. It is better to use the new function
  seq_has_overflowed() if you want to stop processing when the buffer
  is full. Note, if the buffer is full, the seq_file code will throw away
  the contents, allocate a bigger buffer, and then call your code again
  to fill in the data. The only thing that breaking out of the function
  early does is to save a little time which is probably never noticed.

  I started with patches from Joe Perches and modified them as well.
  There's many more places that need to be updated before we can convert
  seq_printf() and friends to return void. But this patch set introduces
  the seq_has_overflowed() and does some initial updates."
parents 78d28e65 9761536e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -140,7 +140,7 @@ file.
				     struct dentry *parent,
				     struct dentry *parent,
				     struct debugfs_regset32 *regset);
				     struct debugfs_regset32 *regset);


    int debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs,
    void debugfs_print_regs32(struct seq_file *s, struct debugfs_reg32 *regs,
			 int nregs, void __iomem *base, char *prefix);
			 int nregs, void __iomem *base, char *prefix);


The "base" argument may be 0, but you may want to build the reg32 array
The "base" argument may be 0, but you may want to build the reg32 array
+13 −9
Original line number Original line Diff line number Diff line
@@ -180,23 +180,19 @@ output must be passed to the seq_file code. Some utility functions have
been defined which make this task easy.
been defined which make this task easy.


Most code will simply use seq_printf(), which works pretty much like
Most code will simply use seq_printf(), which works pretty much like
printk(), but which requires the seq_file pointer as an argument. It is
printk(), but which requires the seq_file pointer as an argument.
common to ignore the return value from seq_printf(), but a function
producing complicated output may want to check that value and quit if
something non-zero is returned; an error return means that the seq_file
buffer has been filled and further output will be discarded.


For straight character output, the following functions may be used:
For straight character output, the following functions may be used:


	int seq_putc(struct seq_file *m, char c);
	seq_putc(struct seq_file *m, char c);
	int seq_puts(struct seq_file *m, const char *s);
	seq_puts(struct seq_file *m, const char *s);
	int seq_escape(struct seq_file *m, const char *s, const char *esc);
	seq_escape(struct seq_file *m, const char *s, const char *esc);


The first two output a single character and a string, just like one would
The first two output a single character and a string, just like one would
expect. seq_escape() is like seq_puts(), except that any character in s
expect. seq_escape() is like seq_puts(), except that any character in s
which is in the string esc will be represented in octal form in the output.
which is in the string esc will be represented in octal form in the output.


There is also a pair of functions for printing filenames:
There are also a pair of functions for printing filenames:


	int seq_path(struct seq_file *m, struct path *path, char *esc);
	int seq_path(struct seq_file *m, struct path *path, char *esc);
	int seq_path_root(struct seq_file *m, struct path *path,
	int seq_path_root(struct seq_file *m, struct path *path,
@@ -209,6 +205,14 @@ root is desired, it can be used with seq_path_root(). Note that, if it
turns out that path cannot be reached from root, the value of root will be
turns out that path cannot be reached from root, the value of root will be
changed in seq_file_root() to a root which *does* work.
changed in seq_file_root() to a root which *does* work.


A function producing complicated output may want to check
	bool seq_has_overflowed(struct seq_file *m);
and avoid further seq_<output> calls if true is returned.

A true return from seq_has_overflowed means that the seq_file buffer will
be discarded and the seq_show function will attempt to allocate a larger
buffer and retry printing.



Making it all work
Making it all work


+1 −1
Original line number Original line Diff line number Diff line
@@ -835,7 +835,7 @@ struct file_operations {
	ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int);
	ssize_t (*splice_read)(struct file *, struct pipe_inode_info *, size_t, unsigned int);
	int (*setlease)(struct file *, long arg, struct file_lock **, void **);
	int (*setlease)(struct file *, long arg, struct file_lock **, void **);
	long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len);
	long (*fallocate)(struct file *, int mode, loff_t offset, loff_t len);
	int (*show_fdinfo)(struct seq_file *m, struct file *f);
	void (*show_fdinfo)(struct seq_file *m, struct file *f);
};
};


Again, all methods are called without any locks being held, unless
Again, all methods are called without any locks being held, unless
+2 −2
Original line number Original line Diff line number Diff line
@@ -2209,7 +2209,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
}
}


#ifdef CONFIG_PROC_FS
#ifdef CONFIG_PROC_FS
static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
static void tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
{
{
	struct tun_struct *tun;
	struct tun_struct *tun;
	struct ifreq ifr;
	struct ifreq ifr;
@@ -2225,7 +2225,7 @@ static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
	if (tun)
	if (tun)
		tun_put(tun);
		tun_put(tun);


	return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
	seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
}
}
#endif
#endif


+8 −7
Original line number Original line Diff line number Diff line
@@ -692,18 +692,19 @@ EXPORT_SYMBOL_GPL(debugfs_create_u32_array);
 * because some peripherals have several blocks of identical registers,
 * because some peripherals have several blocks of identical registers,
 * for example configuration of dma channels
 * for example configuration of dma channels
 */
 */
int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
			  int nregs, void __iomem *base, char *prefix)
			  int nregs, void __iomem *base, char *prefix)
{
{
	int i, ret = 0;
	int i;


	for (i = 0; i < nregs; i++, regs++) {
	for (i = 0; i < nregs; i++, regs++) {
		if (prefix)
		if (prefix)
			ret += seq_printf(s, "%s", prefix);
			seq_printf(s, "%s", prefix);
		ret += seq_printf(s, "%s = 0x%08x\n", regs->name,
		seq_printf(s, "%s = 0x%08x\n", regs->name,
			   readl(base + regs->offset));
			   readl(base + regs->offset));
		if (seq_has_overflowed(s))
			break;
	}
	}
	return ret;
}
}
EXPORT_SYMBOL_GPL(debugfs_print_regs32);
EXPORT_SYMBOL_GPL(debugfs_print_regs32);


Loading