public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Chris Down <chris@chrisdown.name>
Cc: linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	John Ogness <john.ogness@linutronix.de>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kees Cook <keescook@chromium.org>,
	kernel-team@fb.com
Subject: Re: [PATCH v5] printk: Userspace format enumeration support
Date: Tue, 16 Mar 2021 12:39:05 +0100	[thread overview]
Message-ID: <YFCY2VIlpYc6cANM@alley> (raw)
In-Reply-To: <YE9RK89jLbLQcSEq@chrisdown.name>

On Mon 2021-03-15 12:20:59, Chris Down wrote:
> Petr Mladek writes:
> > > I don't feel strongly that this is more clear though, so maybe you
> > > mean something else?
> > 
> > I was pretty tired when reviewing the patch. It was not easy for me
> > to create the mental model of the code. I felt that some other names
> > would have made it easier.
> > 
> > Also the tricky pi_next() implementation did not help much. It looks
> > like you changed the code many times to get it working and did not
> > clean it at the end.
> 
> No worries. I'm not totally clear on what you're asking for though: do you
> meant that you'd like the SEQ_START_TOKEN logic to only be present for
> pi_start, or to pull out the logic currently in pi_next into another
> function and call it from both, or?
> 
> In my mind, pi_start is really just a special case of pi_next, so the code
> flow makes sense to me. I'm happy to change it to whatever you like, but
> it's not immediately obvious to me what that is :-)

Good question! I have missed that pi_start() can be called also with non-zero
pos when seeking.

OK, pi_start() has to handle pos == 0 special way, so let's handle it
there. Call pi_next() only when pos != 0.

The following code should do the job. I took this from my previous reply.
It is already based on the other suggested changes:

static struct pi_entry *pi_get_entry(struct module *mod, int idx)
{
	struct pi_entry *entries;
	int num_entries;

	if (mod) {
		entries = mod->entries;
		num_entries = num->num_entries;
	} else {
		entries = vmlinux_entries;
		num_entries = vmlinux_num_entries;
	}

	if (idx >= num_entries)
		return NULL;

	return entries[idx];
}

static void *pi_next(struct seq_file *s, void *v, loff_t *pos)
{
	const struct module *mod = (struct module*)s->file->f_inode->i_private;
	struct pi_entry *entry;

	entry = pi_get_entry(mod, *pos);
	*(pos)++;

	return entry;
}

static void *pi_start(struct seq_file *s, loff_t *pos)
{
	/*
	 * Make show() print the header line. Do not update *pos
	 * because pi_next() still has to return entry on the index zero.
	 */
	if (*pos == 0)
		return SEQ_START_TOKEN;

	return pi_next(s, NULL, pos);
}

Best Regards,
Petr

  reply	other threads:[~2021-03-16 11:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10  2:30 [PATCH v5] printk: Userspace format enumeration support Chris Down
2021-03-10  6:20 ` kernel test robot
2021-03-10  6:50 ` Greg Kroah-Hartman
2021-03-10 12:12   ` Chris Down
2021-03-10 12:16     ` Greg Kroah-Hartman
2021-03-11  9:34       ` Petr Mladek
2021-03-11  9:43         ` Greg Kroah-Hartman
2021-03-10 12:17 ` Chris Down
2021-03-11  9:20   ` Petr Mladek
2021-03-10 12:31 ` kernel test robot
2021-03-12 11:14 ` Petr Mladek
2021-03-12 13:53   ` Chris Down
2021-03-15 10:02     ` Petr Mladek
2021-03-15 12:20       ` Chris Down
2021-03-16 11:39         ` Petr Mladek [this message]
2021-03-16 13:27           ` Chris Down
2021-03-16 14:12 ` Rasmus Villemoes
2021-03-16 14:28   ` Chris Down
2021-03-17  8:40     ` Petr Mladek
2021-03-17 10:03       ` Rasmus Villemoes
2021-03-18 10:46         ` Petr Mladek
2021-03-18 11:31           ` Rasmus Villemoes
2021-03-19 11:43             ` Petr Mladek
2021-04-16 13:56           ` Chris Down
2021-04-16 14:09             ` Joe Perches
2021-04-16 14:29               ` Chris Down
2021-04-19  7:27             ` Rasmus Villemoes
2021-04-19  9:16               ` Petr Mladek
2021-04-19  9:53                 ` Greg Kroah-Hartman
2021-04-19 11:02                   ` Joe Perches
2021-04-21 13:14               ` Chris Down
2021-04-22 12:36                 ` Joe Perches
2021-04-22 14:59                   ` Chris Down

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFCY2VIlpYc6cANM@alley \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chrisdown.name \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=john.ogness@linutronix.de \
    --cc=keescook@chromium.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox