Re: [PATCH v3 1/2] printk: console: Create console= parser that supports named options

From: Chris Down
Date: Mon Apr 17 2023 - 11:04:36 EST


(To others on this thread wondering about this patchset, Petr and I have had some discussions offlist about v4 and it should be up soon.)

Petr Mladek writes:
I thought a lot how to do it a clean way. IMHO, it would be great to
parse everything at a single place but it might require updating
all drivers. I am not sure if it is worth it.

So, I suggest to do it another way. We could implement a generic
function to find in the new key[:value] format. It would check
if the given option (key) exists and read the optional value.

The optional value would allow to define another new options
that would not need any value, e.g. "kthread" or "atomic" that
might be used in the upcoming code that allows to offload
console handling to kthreads.

Any thoughts on something simple like this that takes advantage of memmove()? This should overcome the mmio/io concerns, and it's fairly simple.

---

static bool find_and_remove_console_option(char *buf, size_t size,
const char *wanted, char *options)
{
bool found = false, first = true;
char *item, *opt = options;

while ((item = strsep(&opt, ","))) {
char *key = item, *value;

value = strchr(item, ':');
if (value)
*(value++) = '\0';

if (strcmp(key, wanted) == 0) {
found = true;
if (value) {
if (strlen(value) > size - 1) {
pr_warn("Can't copy console option value for %s:%s: not enough space (%zu)\n",
key, value, size);
found = false;
} else {
strscpy(buf, value, size);
}
} else
*buf = '\0';
}

if (!found && opt)
*(opt - 1) = ',';
if (!found && value)
*(value - 1) = ':';
if (!first)
*(item - 1) = ',';

if (found)
break;

first = false;
}

if (found) {
if (opt)
memmove(item, opt, strlen(opt) + 1);
else if (first)
*item = '\0';
else
*--item = '\0';
}

return found;
}