11 Aug, 2020

1 commit

  • commit 55c7549819e438f40a3ef1d8ac5c38b73390bcb7 upstream.

    When running `make coccicheck` in report mode using the
    add_namespace.cocci file, it will fail for files that contain
    MODULE_LICENSE. Those match the replacement precondition, but spatch
    errors out as virtual.ns is not set.

    In order to fix that, add the virtual rule nsdeps and only do search and
    replace if that rule has been explicitly requested.

    In order to make spatch happy in report mode, we also need a dummy rule,
    as otherwise it errors out with "No rules apply". Using a script:python
    rule appears unrelated and odd, but this is the shortest I could come up
    with.

    Adjust scripts/nsdeps accordingly to set the nsdeps rule when run trough
    `make nsdeps`.

    Suggested-by: Julia Lawall
    Fixes: c7c4e29fb5a4 ("scripts: add_namespace: Fix coccicheck failed")
    Cc: YueHaibing
    Cc: jeyu@kernel.org
    Cc: cocci@systeme.lip6.fr
    Cc: stable@vger.kernel.org
    Signed-off-by: Matthias Maennich
    Reported-by: Shuah Khan
    Acked-by: Julia Lawall
    Link: https://lore.kernel.org/r/20200604164145.173925-1-maennich@google.com
    Signed-off-by: Greg Kroah-Hartman

    Matthias Maennich
     

05 Nov, 2019

1 commit

  • The nsdeps script passes a list of the module source files to
    generate_deps_for_ns() as a space delimited string named $mod_source_files,
    which then passes it to spatch. But since $mod_source_files is not encased
    in quotes, each source file in that string is treated as a separate shell
    function argument (as $2, $3, $4, etc.). However, the spatch invocation
    only refers to $2, so only the first file out of $mod_source_files is
    processed by spatch.

    This causes problems (namely, the MODULE_IMPORT_NS() statement doesn't
    get inserted) when a module is composed of many source files and the
    "main" module file containing the MODULE_LICENSE() statement is not the
    first file listed in $mod_source_files. Fix this by encasing
    $mod_source_files in quotes so that the entirety of the string is
    treated as a single argument and can be referred to as $2.

    In addition, put quotes in the variable assignment of mod_source_files
    to prevent any shell interpretation and field splitting.

    Reviewed-by: Masahiro Yamada
    Acked-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Jessica Yu
     

23 Oct, 2019

1 commit

  • When doing an out of tree build with O=, the nsdeps script constructs
    the absolute pathname of the module source file so that it can insert
    MODULE_IMPORT_NS statements in the right place. However, ${srctree}
    contains an unescaped path to the source tree, which, when used in a sed
    substitution, makes sed complain:

    ++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
    sed: -e expression #1, char 12: unknown option to `s'

    The sed substitution command 's' ends prematurely with the forward
    slashes in the pathname, and sed errors out when it encounters the 'h',
    which is an invalid sed substitution option. To avoid escaping forward
    slashes ${srctree}, we can use '|' as an alternative delimiter for
    sed instead to avoid this error.

    Reviewed-by: Masahiro Yamada
    Reviewed-by: Matthias Maennich
    Tested-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Jessica Yu
     

08 Oct, 2019

2 commits

  • scripts/nsdeps automatically generates a patch to add MODULE_IMPORT_NS
    tags, and what is nicer, it sorts the lines alphabetically with the
    'sort' command. However, the output from the 'sort' command depends on
    locale.

    For example, I got this:

    $ { echo usbstorage; echo usb_storage; } | LANG=en_US.UTF-8 sort
    usbstorage
    usb_storage
    $ { echo usbstorage; echo usb_storage; } | LANG=C sort
    usb_storage
    usbstorage

    So, this means people might potentially send different patches.

    This kind of issue was reported in the past, for example,
    commit f55f2328bb28 ("kbuild: make sorting initramfs contents
    independent of locale").

    Adding 'LANG=C' is a conventional way of fixing when a deterministic
    result is desirable.

    I added 'LANG=C' very close to the 'sort' command since changing
    locale affects the language of error messages etc. We should respect
    users' choice as much as possible.

    Reviewed-by: Matthias Maennich
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     
  • This script does not use bash-extension. I am guessing this hashbang
    was copied from scripts/coccicheck, which really uses bash-extension.

    /bin/sh is enough for this script.

    Reviewed-by: Matthias Maennich
    Signed-off-by: Masahiro Yamada
    Signed-off-by: Jessica Yu

    Masahiro Yamada
     

10 Sep, 2019

1 commit

  • A script that uses the '.ns_deps' files generated by modpost to
    automatically add the required symbol namespace dependencies to each
    module.

    Usage:
    1) Move some symbols to a namespace with EXPORT_SYMBOL_NS() or define
    DEFAULT_SYMBOL_NAMESPACE
    2) Run 'make' (or 'make modules') and get warnings about modules not
    importing that namespace.
    3) Run 'make nsdeps' to automatically add required import statements
    to said modules.

    This makes it easer for subsystem maintainers to introduce and maintain
    symbol namespaces into their codebase.

    Co-developed-by: Martijn Coenen
    Signed-off-by: Martijn Coenen
    Acked-by: Julia Lawall
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Matthias Maennich
    Signed-off-by: Jessica Yu

    Matthias Maennich