0

I'm doing a Linux driver tutorial, and I have encountered a problem with the sample lesson of passing parameters to the driver.  I tried another parameter-passing example I found on the internet with the same result.  Happens on Ubuntu and Raspberry Pi.

For some reason, when I insmod the driver with a text parameter for nameETX, dmesg shows that the kernel is thinking some of the text string is an 'unknown parameter'.  It does, however, accept the “The” part of the text string.  Any help please?

Source code:

char    *nameETX;
module_param(nameETX, charp, S_IRUSR | S_IWUSR);

Command line:

sudo insmod hello_world.ko nameETX="The latest driver"

dmesg output:

[  968.395399] hello_world: unknown parameter 'latest' ignored
[  968.395425] hello_world: unknown parameter 'driver' ignored
7
  • sounds like something is unwrapping a level of quotes and reparsing. I would suggest trying two set of quotes. If it could be sudo, try becoming root and running the insmod directly.
    – David G.
    Commented Jun 16 at 16:29
  • try escaping the spaces... "The\ latest\ driver"
    – jsotola
    Commented Jun 16 at 16:42
  • @jsotola - Nope, same issue
    – carlh
    Commented Jun 16 at 17:17
  • @DavidG. - tried double quotes and root account with no change
    – carlh
    Commented Jun 16 at 17:18
  • 1
    @JosephSible-ReinstateMonica - that did the trick. Thanks so much. The tutorial is a few years old which didn't have this problem. Something changes since then.
    – carlh
    Commented Jun 18 at 18:07

1 Answer 1

2

This is a copy of the answer by afenster to Pass a string parameter with space character to a kernel module (at Stack Overflow) (which was identified by Joseph Sible as being the same question).

When you run insmod ./params.ko mystring="Hello World", your quotes are eaten by the shell, and the insmod binary has the string mystring=Hello World as the parameter.  It passes it to the kernel as is, and then it all goes down to the kernel parse_args function (in kernel/params.c), which, in turn, calls next_arg to split the next parameter into name and value.

It definitely can handle spaces, as we see in the following comment in the code:

/*
 * Parse a string to get a param value pair.
 * You can use " around spaces, but can't escape ".
 * Hyphens and underscores equivalent in parameter names.
 */

and the following conditional statement:

static char *next_arg(char *args, char **param, char **val)
{
    ...
    for (i = 0; args[i]; i++) {
        if (isspace(args[i]) && !in_quote)
            break;
    ...
}

So the idea is that you need to pass the quotes to the kernel, not to the shell.  I don't have a Linux box to check the kernel module insertion right now, but I guess the following command will work:

sudo insmod hello_world.ko nameETX='"The latest driver"'

Here the shell will consume the single quotes, and the parameter for the insmod binary will be nameETX="The latest driver", so these quotes will be passed to kernel as is, which will make it possible to parse the value as you expect.  Try that; it should work.


(I made minor, cosmetic edits.)

I found the kernel source code (in cmdline.c) at GitHub and Bootlin.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .