13 Jan, 2012

2 commits

  • For historical reasons, we allow module_param(bool) to take an int (or
    an unsigned int). That's going away.

    A few drivers really want an int: they set it to -1 and a parameter
    will set it to 0 or 1. This sucks: reading them from sysfs will give
    'Y' for both -1 and 1, but if we change it to an int, then the users
    might be broken (if they did "param" instead of "param=1").

    Use a new 'bint' parser for them.

    (ntfs has a different problem: it needs an int for debug_msgs because
    it's also exposed via sysctl.)

    Cc: Steve Glendinning
    Cc: Jean Delvare
    Cc: Guenter Roeck
    Cc: Hoang-Nam Nguyen
    Cc: Christoph Raisch
    Cc: Roland Dreier
    Cc: Sean Hefty
    Cc: Hal Rosenstock
    Cc: linux390@de.ibm.com
    Cc: Anton Altaparmakov
    Cc: Jaroslav Kysela
    Cc: Takashi Iwai
    Cc: lm-sensors@lm-sensors.org
    Cc: linux-rdma@vger.kernel.org
    Cc: linux-s390@vger.kernel.org
    Cc: linux-ntfs-dev@lists.sourceforge.net
    Cc: alsa-devel@alsa-project.org
    Acked-by: Takashi Iwai (For the sound part)
    Acked-by: Guenter Roeck (For the hwmon driver)
    Signed-off-by: Rusty Russell

    Rusty Russell
     
  • Use more flexible pr_debug. This allows:

    echo "module params +p" > /dbg/dynamic_debug/control

    to turn on debug messages when needed.

    Signed-off-by: Jim Cromie
    Signed-off-by: Rusty Russell

    Jim Cromie
     

31 Oct, 2011

1 commit

  • Through various other implicit include paths, some files were
    getting the full module.h file, and hence living the illusion
    that they really only needed moduleparam.h -- but the reality
    is that once you remove the module.h presence, these show up:

    kernel/params.c:583: warning: ‘struct module_kobject’ declared inside parameter list

    Such files really require module.h so simply make it so. As the
    file module.h grabs moduleparam.h on the fly, all will be well.

    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

26 Oct, 2011

1 commit

  • The user may use "foo-bar" for a kernel parameter defined as "foo_bar".
    Make sure it works the other way around too.

    Apply the equality of dashes and underscores on early_params and __setup
    params as well.

    The example given in Documentation/kernel-parameters.txt indicates that
    this is the intended behaviour.

    With the patch the kernel accepts "log-buf-len=1M" as expected.
    https://bugzilla.redhat.com/show_bug.cgi?id=744545

    Signed-off-by: Michal Schmidt
    Signed-off-by: Rusty Russell (neatened implementations)

    Michal Schmidt
     

24 Jul, 2011

3 commits

  • Userspace wants to manage module parameters with udev rules.
    This currently only works for loaded modules, but not for
    built-in ones.

    To allow access to the built-in modules we need to
    re-trigger all module load events that happened before any
    userspace was running. We already do the same thing for all
    devices, subsystems(buses) and drivers.

    This adds the currently missing /sys/module//uevent files
    to all module entries.

    Signed-off-by: Kay Sievers
    Signed-off-by: Rusty Russell (split & trivial fix)

    Kay Sievers
     
  • This simplifies the next patch, where we have an attribute on a
    builtin module (ie. module == NULL).

    Signed-off-by: Kay Sievers
    Signed-off-by: Rusty Russell (split into 2)

    Kay Sievers
     
  • In STANDARD_PARAM_DEF, param_set_* handles the case in which strtolfn
    returns -EINVAL but it may return -ERANGE. If it returns -ERANGE,
    param_set_* may set uninitialized value to the paramerter. We should handle
    both cases.

    The one of the cases in which strtolfn() returns -ERANGE is following:

    *Type of module parameter is long
    *Set the parameter more than LONG_MAX

    Signed-off-by: Satoru Moriya
    Signed-off-by: Rusty Russell

    Satoru Moriya
     

19 May, 2011

2 commits

  • Signed-off-by: Jonathan Cameron
    Signed-off-by: Rusty Russell

    Jonathan Cameron
     
  • On m68k natural alignment is 2-byte boundary but we are trying to
    align structures in __modver section on sizeof(void *) boundary.
    This causes trouble when we try to access elements in this section
    in array-like fashion when create "version" attributes for built-in
    modules.

    Moreover, as DaveM said, we can't reliably put structures into
    independent objects, put them into a special section, and then expect
    array access over them (via the section boundaries) after linking the
    objects together to just "work" due to variable alignment choices in
    different situations. The only solution that seems to work reliably
    is to make an array of plain pointers to the objects in question and
    put those pointers in the special section.

    Reported-by: Geert Uytterhoeven
    Signed-off-by: Dmitry Torokhov
    Signed-off-by: Rusty Russell

    Dmitry Torokhov
     

31 Mar, 2011

1 commit


24 Jan, 2011

1 commit

  • Currently only drivers that are built as modules have their versions
    shown in /sys/module//version, but this information might
    also be useful for built-in drivers as well. This especially important
    for drivers that do not define any parameters - such drivers, if
    built-in, are completely invisible from userspace.

    This patch changes MODULE_VERSION() macro so that in case when we are
    compiling built-in module, version information is stored in a separate
    section. Kernel then uses this data to create 'version' sysfs attribute
    in the same fashion it creates attributes for module parameters.

    Signed-off-by: Dmitry Torokhov
    Signed-off-by: Rusty Russell

    Dmitry Torokhov
     

11 Aug, 2010

7 commits

  • There may be cases (most obviously, sysfs-writable charp parameters) where
    a module needs to prevent sysfs access to parameters.

    Rather than express this in terms of a big lock, the functions are
    expressed in terms of what they protect against. This is clearer, esp.
    if the implementation changes to a module-level or even param-level lock.

    Signed-off-by: Rusty Russell
    Reviewed-by: Takashi Iwai
    Tested-by: Phil Carmody

    Rusty Russell
     
  • Since this section can be read-only (they're in .rodata), they should
    always have been const. Minor flow-through various functions.

    Signed-off-by: Rusty Russell
    Tested-by: Phil Carmody

    Rusty Russell
     
  • Instead of using a "I kmalloced this" flag, we keep track of the kmalloced
    strings and use that list to check if we need to kfree (in practice, the
    list is very short).

    This means that kparams can be const again, and plugs a leak. This
    is important for drivers/usb/gadget/nokia.c which gets modprobe/rmmod'ed
    frequently on the N9000.

    Signed-off-by: Rusty Russell
    Reviewed-by: Takashi Iwai
    Cc: Artem Bityutskiy
    Tested-by: Phil Carmody

    Rusty Russell
     
  • This allows us to generalize the KPARAM_KMALLOCED flag, by calling a function
    on every parameter when a module is unloaded.

    Signed-off-by: Rusty Russell
    Reviewed-by: Takashi Iwai
    Tested-by: Phil Carmody

    Rusty Russell
     
  • This is more kernel-ish, saves some space, and also allows us to
    expand the ops without breaking all the callers who are happy for the
    new members to be NULL.

    The few places which defined their own param types are changed to the
    new scheme (more which crept in recently fixed in following patches).

    Since we're touching them anyway, we change get() and set() to take a
    const struct kernel_param (which they really are). This causes some
    harmless warnings until we fix them (in following patches).

    To reduce churn, module_param_call creates the ops struct so the callers
    don't have to change (and casts the functions to reduce warnings).
    The modern version which takes an ops struct is called module_param_cb.

    Signed-off-by: Rusty Russell
    Reviewed-by: Takashi Iwai
    Tested-by: Phil Carmody
    Cc: "David S. Miller"
    Cc: Ville Syrjala
    Cc: Dmitry Torokhov
    Cc: Alessandro Rubini
    Cc: Michal Januszewski
    Cc: Trond Myklebust
    Cc: "J. Bruce Fields"
    Cc: Neil Brown
    Cc: linux-kernel@vger.kernel.org
    Cc: linux-input@vger.kernel.org
    Cc: linux-fbdev-devel@lists.sourceforge.net
    Cc: linux-nfs@vger.kernel.org
    Cc: netdev@vger.kernel.org

    Rusty Russell
     
  • This is modern style, and good to do before we start changing things.

    Signed-off-by: Rusty Russell
    Reviewed-by: Takashi Iwai
    Tested-by: Phil Carmody

    Rusty Russell
     
  • An audit by Dongdong Deng revealed that most driver-author-written param
    calls don't handle val == NULL (which happens when parameters are specified
    with no =, eg "foo" instead of "foo=1").

    The only real case to use this is boolean, so handle it specially for that
    case and remove a source of bugs for everyone else.

    Signed-off-by: Rusty Russell
    Cc: Dongdong Deng
    Cc: Américo Wang

    Rusty Russell
     

13 Mar, 2010

1 commit

  • * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial: (56 commits)
    doc: fix typo in comment explaining rb_tree usage
    Remove fs/ntfs/ChangeLog
    doc: fix console doc typo
    doc: cpuset: Update the cpuset flag file
    Fix of spelling in arch/sparc/kernel/leon_kernel.c no longer needed
    Remove drivers/parport/ChangeLog
    Remove drivers/char/ChangeLog
    doc: typo - Table 1-2 should refer to "status", not "statm"
    tree-wide: fix typos "ass?o[sc]iac?te" -> "associate" in comments
    No need to patch AMD-provided drivers/gpu/drm/radeon/atombios.h
    devres/irq: Fix devm_irq_match comment
    Remove reference to kthread_create_on_cpu
    tree-wide: Assorted spelling fixes
    tree-wide: fix 'lenght' typo in comments and code
    drm/kms: fix spelling in error message
    doc: capitalization and other minor fixes in pnp doc
    devres: typo fix s/dev/devm/
    Remove redundant trailing semicolons from macros
    fix typo "definetly" -> "definitely" in comment
    tree-wide: s/widht/width/g typo in comments
    ...

    Fix trivial conflict in Documentation/laptops/00-INDEX

    Linus Torvalds
     

08 Mar, 2010

4 commits

  • Conflicts:
    Documentation/filesystems/proc.txt
    arch/arm/mach-u300/include/mach/debug-macro.S
    drivers/net/qlge/qlge_ethtool.c
    drivers/net/qlge/qlge_main.c
    drivers/net/typhoon.c

    Jiri Kosina
     
  • These are the non-static sysfs attributes that exist on
    my test machine. Fix them to use sysfs_attr_init or
    sysfs_bin_attr_init as appropriate. It simply requires
    making a sysfs attribute present to see this. So this
    is a little bit tedious but otherwise not too bad.

    Signed-off-by: Eric W. Biederman
    Acked-by: WANG Cong
    Cc: Tejun Heo
    Signed-off-by: Greg Kroah-Hartman

    Eric W. Biederman
     
  • Constify struct sysfs_ops.

    This is part of the ops structure constification
    effort started by Arjan van de Ven et al.

    Benefits of this constification:

    * prevents modification of data that is shared
    (referenced) by many other structure instances
    at runtime

    * detects/prevents accidental (but not intentional)
    modification attempts on archs that enforce
    read-only kernel data at runtime

    * potentially better optimized code as the compiler
    can assume that the const data cannot be changed

    * the compiler/linker move const data into .rodata
    and therefore exclude them from false sharing

    Signed-off-by: Emese Revfy
    Acked-by: David Teigland
    Acked-by: Matt Domsch
    Acked-by: Maciej Sosnowski
    Acked-by: Hans J. Koch
    Acked-by: Pekka Enberg
    Acked-by: Jens Axboe
    Acked-by: Stephen Hemminger
    Signed-off-by: Greg Kroah-Hartman

    Emese Revfy
     
  • Constify struct kset_uevent_ops.

    This is part of the ops structure constification
    effort started by Arjan van de Ven et al.

    Benefits of this constification:

    * prevents modification of data that is shared
    (referenced) by many other structure instances
    at runtime

    * detects/prevents accidental (but not intentional)
    modification attempts on archs that enforce
    read-only kernel data at runtime

    * potentially better optimized code as the compiler
    can assume that the const data cannot be changed

    * the compiler/linker move const data into .rodata
    and therefore exclude them from false sharing

    Signed-off-by: Emese Revfy
    Signed-off-by: Greg Kroah-Hartman

    Emese Revfy
     

07 Mar, 2010

1 commit


05 Feb, 2010

1 commit


16 Dec, 2009

1 commit

  • Makes use of skip_spaces() defined in lib/string.c for removing leading
    spaces from strings all over the tree.

    It decreases lib.a code size by 47 bytes and reuses the function tree-wide:
    text data bss dec hex filename
    64688 584 592 65864 10148 (TOTALS-BEFORE)
    64641 584 592 65817 10119 (TOTALS-AFTER)

    Also, while at it, if we see (*str && isspace(*str)), we can be sure to
    remove the first condition (*str) as the second one (isspace(*str)) also
    evaluates to 0 whenever *str == 0, making it redundant. In other words,
    "a char equals zero is never a space".

    Julia Lawall tried the semantic patch (http://coccinelle.lip6.fr) below,
    and found occurrences of this pattern on 3 more files:
    drivers/leds/led-class.c
    drivers/leds/ledtrig-timer.c
    drivers/video/output.c

    @@
    expression str;
    @@

    ( // ignore skip_spaces cases
    while (*str && isspace(*str)) { \(str++;\|++str;\) }
    |
    - *str &&
    isspace(*str)
    )

    Signed-off-by: André Goddard Rosa
    Cc: Julia Lawall
    Cc: Martin Schwidefsky
    Cc: Jeff Dike
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: Richard Purdie
    Cc: Neil Brown
    Cc: Kyle McMartin
    Cc: Henrique de Moraes Holschuh
    Cc: David Howells
    Cc:
    Cc: Samuel Ortiz
    Cc: Patrick McHardy
    Cc: Takashi Iwai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     

29 Oct, 2009

3 commits

  • We create a dummy struct kernel_param on the stack for parsing each
    array element, but we didn't initialize the flags word. This matters
    for arrays of type "bool", where the flag indicates if it really is
    an array of bools or unsigned int (old-style).

    Reported-by: Takashi Iwai
    Signed-off-by: Rusty Russell
    Cc: stable@kernel.org

    Rusty Russell
     
  • kp->arg is always true: it's the contents of that pointer we care about.

    Reported-by: Takashi Iwai
    Signed-off-by: Rusty Russell
    Cc: stable@kernel.org

    Rusty Russell
     
  • e180a6b7759a "param: fix charp parameters set via sysfs" fixed the case
    where charp parameters written via sysfs were freed, leaving drivers
    accessing random memory.

    Unfortunately, storing a flag in the kparam struct was a bad idea: it's
    rodata so setting it causes an oops on some archs. But that's not all:

    1) module_param_array() on charp doesn't work reliably, since we use an
    uninitialized temporary struct kernel_param.
    2) there's a fundamental race if a module uses this parameter and then
    it's changed: they will still access the old, freed, memory.

    The simplest fix (ie. for 2.6.32) is to never free the memory. This
    prevents all these problems, at cost of a memory leak. In practice, there
    are only 18 places where a charp is writable via sysfs, and all are
    root-only writable.

    Reported-by: Takashi Iwai
    Cc: Sitsofe Wheeler
    Cc: Frederic Weisbecker
    Cc: Christof Schmitt
    Signed-off-by: Rusty Russell
    Cc: stable@kernel.org

    Rusty Russell
     

24 Sep, 2009

1 commit

  • Some boot mechanisms require that kernel parameters are stored in a
    separate file which is loaded to memory without further processing
    (e.g. the "Load from FTP" method on s390). When such a file contains
    newline characters, the kernel parameter preceding the newline might
    not be correctly parsed (due to the newline being stuck to the end of
    the actual parameter value) which can lead to boot failures.

    This patch improves kernel command line usability in such a situation
    by allowing generic whitespace characters as separators between kernel
    parameters.

    Signed-off-by: Peter Oberparleiter
    Signed-off-by: Rusty Russell

    Peter Oberparleiter
     

12 Jun, 2009

3 commits


31 Mar, 2009

1 commit

  • Impact: fix crash on reading from /sys/module/.../ieee80211_default_rc_algo

    The module_param type "charp" simply sets a char * pointer in the
    module to the parameter in the commandline string: this is why we keep
    the (mangled) module command line around. But when set via sysfs (as
    about 11 charp parameters can be) this memory is freed on the way
    out of the write(). Future reads hit random mem.

    So we kstrdup instead: we have to check we're not in early commandline
    parsing, and we have to note when we've used it so we can reliably
    kfree the parameter when it's next overwritten, and also on module
    unload.

    (Thanks to Randy Dunlap for CONFIG_SYSFS=n fixes)

    Reported-by: Sitsofe Wheeler
    Diagnosed-by: Frederic Weisbecker
    Tested-by: Frederic Weisbecker
    Tested-by: Christof Schmitt
    Signed-off-by: Rusty Russell

    Rusty Russell
     

24 Oct, 2008

1 commit


22 Oct, 2008

3 commits

  • There are a lot of one-liner uses of __setup() in the kernel: they're
    cumbersome and not queryable (definitely not settable) via /sys. Yet
    it's ugly to simplify them to module_param(), because by default that
    inserts a prefix of the module name (usually filename).

    So, introduce a "core_param". The parameter gets no prefix, but
    appears in /sys/module/kernel/parameters/ (if non-zero perms arg). I
    thought about using the name "core", but that's more common than
    "kernel". And if you create a module called "kernel", you will die
    a horrible death.

    Signed-off-by: Rusty Russell

    Rusty Russell
     
  • Instead of insisting each new module_param sysfs entry is unique,
    handle the case where it already exists (for builtin modules).

    The current code assumes that all identical prefixes are together in
    the section: true for normal uses, but not necessarily so if someone
    overrides MODULE_PARAM_PREFIX. More importantly, it's not true with
    the new "core_param()" code which uses "kernel" as a prefix.

    This simplifies the caller for the builtin case, at a slight loss of
    efficiency (we do the lookup every time to see if the directory
    exists).

    Signed-off-by: Rusty Russell
    Cc: Greg Kroah-Hartman

    Rusty Russell
     
  • The kparam code tries to handle over-length parameter prefixes at
    runtime. Not only would I bet this has never been tested, it's not
    clear that truncating names is a good idea either.

    So let's check at compile time. We need to move the #define to
    moduleparam.h to do this, though.

    Signed-off-by: Rusty Russell

    Rusty Russell
     

09 Feb, 2008

1 commit

  • Currently, for every sysfs node, the callers will be responsible for
    implementing store operation, so many many callers are doing duplicate
    things to validate input, they have the same mistakes because they are
    calling simple_strtol/ul/ll/uul, especially for module params, they are
    just numeric, but you can echo such values as 0x1234xxx, 07777888 and
    1234aaa, for these cases, module params store operation just ignores
    succesive invalid char and converts prefix part to a numeric although input
    is acctually invalid.

    This patch tries to fix the aforementioned issues and implements
    strict_strtox serial functions, kernel/params.c uses them to strictly
    validate input, so module params will reject such values as 0x1234xxxx and
    returns an error:

    write error: Invalid argument

    Any modules which export numeric sysfs node can use strict_strtox instead of
    simple_strtox to reject any invalid input.

    Here are some test results:

    Before applying this patch:

    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]#

    After applying this patch:

    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000g > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo 0x1000gggggggg > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# echo 010000 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# echo 0100008 > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# echo 010000aaaaa > /sys/module/e1000/parameters/copybreak
    -bash: echo: write error: Invalid argument
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]# echo -n 4096 > /sys/module/e1000/parameters/copybreak
    [root@yangyi-dev /]# cat /sys/module/e1000/parameters/copybreak
    4096
    [root@yangyi-dev /]#

    [akpm@linux-foundation.org: fix compiler warnings]
    [akpm@linux-foundation.org: fix off-by-one found by tiwai@suse.de]
    Signed-off-by: Yi Yang
    Cc: Greg KH
    Cc: "Randy.Dunlap"
    Cc: Takashi Iwai
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yi Yang
     

07 Feb, 2008

1 commit