30 Dec, 2020

1 commit

  • [ Upstream commit e3e9ced5c93803d5b2ea1942c4bf0192622531d6 ]

    kfree(host->card) has been called in put_device so that
    another kfree would raise cause a double-free bug.

    Fixes: 0193383a5833 ("memstick: core: fix device_register() error handling")
    Reported-by: Hulk Robot
    Signed-off-by: Qinglang Miao
    Link: https://lore.kernel.org/r/20201120074846.31322-1-miaoqinglang@huawei.com
    Signed-off-by: Ulf Hansson
    Signed-off-by: Sasha Levin

    Qinglang Miao
     

28 Sep, 2020

2 commits

  • Ulf Hansson
     
  • After commit 6827ca573c03 ("memstick: rtsx_usb_ms: Support runtime power
    management"), removing module rtsx_usb_ms will be stuck.

    The deadlock is caused by powering on and powering off at the same time,
    the former one is when memstick_check() is flushed, and the later is called
    by memstick_remove_host().

    Soe let's skip allocating card to prevent this issue.

    Fixes: 6827ca573c03 ("memstick: rtsx_usb_ms: Support runtime power management")
    Signed-off-by: Kai-Heng Feng
    Link: https://lore.kernel.org/r/20200925084952.13220-1-kai.heng.feng@canonical.com
    Cc: stable@vger.kernel.org
    Signed-off-by: Ulf Hansson

    Kai-Heng Feng
     

07 Sep, 2020

1 commit


24 Aug, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

21 Nov, 2019

1 commit


11 Sep, 2019

1 commit


12 Jul, 2019

1 commit

  • Pull MMC updates from Ulf Hansson:
    "MMC core:
    - Let the dma map ops deal with bouncing and drop dma_max_pfn() from
    the dma-mapping interface for ARM
    - Convert the generic MMC DT doc to YAML schemas
    - Drop questionable support for powered-on re-init of SDIO cards at
    runtime resume and for SDIO HW reset
    - Prevent questionable re-init of powered-on removable SDIO cards at
    system resume
    - Cleanup and clarify some SDIO core code

    MMC host:
    - tmio: Make runtime PM enablement more flexible for variants
    - tmio/renesas_sdhi: Rename DT doc tmio_mmc.txt to renesas,sdhi.txt
    to clarify
    - sdhci-pci: Add support for Intel EHL
    - sdhci-pci-o2micro: Enable support for 8-bit bus
    - sdhci-msm: Prevent acquiring a mutex while holding a spin_lock
    - sdhci-of-esdhc: Improve clock management and tuning
    - sdhci_am654: Enable support for 4 and 8-bit bus on J721E
    - sdhci-sprd: Use pinctrl for a proper signal voltage switch
    - sdhci-sprd: Add support for HS400 enhanced strobe mode
    - sdhci-sprd: Enable PHY DLL and allow delay config to stabilize the
    clock
    - sdhci-sprd: Add support for optional gate clock
    - sunxi-mmc: Convert DT doc to YAML schemas
    - meson-gx: Add support for broken DRAM access for DMA

    MEMSTICK core:
    - Fixup error path of memstick_init()"

    * tag 'mmc-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: (52 commits)
    mmc: sdhci_am654: Add dependency on MMC_SDHCI_AM654
    mmc: alcor: remove a redundant greater or equal to zero comparison
    mmc: sdhci-msm: fix mutex while in spinlock
    mmc: sdhci_am654: Make some symbols static
    dma-mapping: remove dma_max_pfn
    mmc: core: let the dma map ops handle bouncing
    dt-binding: mmc: rename tmio_mmc.txt to renesas,sdhi.txt
    mmc: sdhci-sprd: Add pin control support for voltage switch
    dt-bindings: mmc: sprd: Add pinctrl support
    mmc: sdhci-sprd: Add start_signal_voltage_switch ops
    mmc: sdhci-pci: Add support for Intel EHL
    mmc: tmio: Use dma_max_mapping_size() instead of a workaround
    mmc: sdio: Drop unused in-parameter from mmc_sdio_init_card()
    mmc: sdio: Drop unused in-parameter to mmc_sdio_reinit_card()
    mmc: sdio: Don't re-initialize powered-on removable SDIO cards at resume
    mmc: sdio: Drop powered-on re-init at runtime resume and HW reset
    mmc: sdio: Move comment about re-initialization to mmc_sdio_reinit_card()
    mmc: sdio: Drop mmc_claim|release_host() in mmc_sdio_power_restore()
    mmc: sdio: Turn sdio_run_irqs() into static
    mmc: sdhci: Fix indenting on SDHCI_CTRL_8BITBUS
    ...

    Linus Torvalds
     

19 Jun, 2019

1 commit

  • Based on 2 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation #

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 4122 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Kate Stewart
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

10 Jun, 2019

1 commit

  • If bus_register fails. On its error handling path, it has cleaned up
    what it has done. There is no need to call bus_unregister again.
    Otherwise, if bus_unregister is called, issues such as null-ptr-deref
    will arise.

    Syzkaller report this:

    kobject_add_internal failed for memstick (error: -12 parent: bus)
    BUG: KASAN: null-ptr-deref in sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
    Read of size 8 at addr 0000000000000078 by task syz-executor.0/4460

    Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0xa9/0x10e lib/dump_stack.c:113
    __kasan_report+0x171/0x18d mm/kasan/report.c:321
    kasan_report+0xe/0x20 mm/kasan/common.c:614
    sysfs_remove_file_ns+0x1b/0x40 fs/sysfs/file.c:467
    sysfs_remove_file include/linux/sysfs.h:519 [inline]
    bus_remove_file+0x6c/0x90 drivers/base/bus.c:145
    remove_probe_files drivers/base/bus.c:599 [inline]
    bus_unregister+0x6e/0x100 drivers/base/bus.c:916 ? 0xffffffffc1590000
    memstick_init+0x7a/0x1000 [memstick]
    do_one_initcall+0xb9/0x3b5 init/main.c:914
    do_init_module+0xe0/0x330 kernel/module.c:3468
    load_module+0x38eb/0x4270 kernel/module.c:3819
    __do_sys_finit_module+0x162/0x190 kernel/module.c:3909
    do_syscall_64+0x72/0x2a0 arch/x86/entry/common.c:298
    entry_SYSCALL_64_after_hwframe+0x49/0xbe

    Fixes: baf8532a147d ("memstick: initial commit for Sony MemoryStick support")
    Reported-by: Hulk Robot
    Signed-off-by: Wang Hai
    Signed-off-by: Ulf Hansson

    Wang Hai
     

28 May, 2019

1 commit

  • We accidentally changed the error code from -EAGAIN to 1 when we did the
    blk-mq conversion.

    Maybe a contributing factor to this mistake is that it wasn't obvious
    that the "while (chunk) {" condition is always true. I have cleaned
    that up as well.

    Fixes: d0be12274dad ("mspro_block: convert to blk-mq")
    Cc: stable@vger.kernel.org
    Signed-off-by: Dan Carpenter
    Signed-off-by: Ulf Hansson

    Dan Carpenter
     

21 May, 2019

1 commit


29 Dec, 2018

1 commit

  • Pull MMC updates from Ulf Hansson:
    "This time, this pull request contains changes crossing subsystems and
    archs/platforms, which is mainly because of a bigger modernization of
    moving from legacy GPIO to GPIO descriptors for MMC (by Linus
    Walleij).

    Additionally, once again, I am funneling changes to
    drivers/misc/cardreader/* and drivers/memstick/* through my MMC tree,
    mostly due to that we lack a maintainer for these.

    Summary:

    MMC core:
    - Cleanup BKOPS support
    - Introduce MMC_CAP_SYNC_RUNTIME_PM
    - slot-gpio: Delete legacy slot GPIO handling

    MMC host:
    - alcor: Add new mmc host driver for Alcor Micro PCI based cardreader
    - bcm2835: Several improvements to better recover from errors
    - jz4740: Rework and fixup pre|post_req support
    - mediatek: Add support for SDIO IRQs
    - meson-gx: Improve clock phase management
    - meson-gx: Stop descriptor on errors
    - mmci: Complete the sbc error path by sending a stop command
    - renesas_sdhi/tmio: Fixup reset/resume operations
    - renesas_sdhi: Add support for r8a774c0 and R7S9210
    - renesas_sdhi: Whitelist R8A77990 SDHI
    - renesas_sdhi: Fixup eMMC HS400 compatibility issues for H3 and M3-W
    - rtsx_usb_sdmmc: Re-work card detection/removal support
    - rtsx_usb_sdmmc: Re-work runtime PM support
    - sdhci: Fix timeout loops for some variant drivers
    - sdhci: Improve support for error handling due to failing commands
    - sdhci-acpi/pci: Disable LED control for Intel BYT-based controllers
    - sdhci_am654: Add new SDHCI variant driver to support TI's AM654 SOCs
    - sdhci-of-esdhc: Add support for eMMC HS400 mode
    - sdhci-omap: Fixup reset support
    - sdhci-omap: Workaround errata regarding SDR104/HS200 tuning failures
    - sdhci-msm: Fixup sporadic write transfers issues for SDR104/HS200
    - sdhci-msm: Fixup dynamical clock gating issues
    - various: Complete converting all hosts into using slot GPIO descriptors

    Other:
    - Move GPIO mmc platform data for mips/sh/arm to GPIO descriptors
    - Add new Alcor Micro cardreader PCI driver
    - Support runtime power management for memstick rtsx_usb_ms driver
    - Use USB remote wakeups for card detection for rtsx_usb misc driver"

    * tag 'mmc-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: (99 commits)
    mmc: mediatek: Add MMC_CAP_SDIO_IRQ support
    mmc: renesas_sdhi_internal_dmac: Whitelist r8a774c0
    dt-bindings: mmc: renesas_sdhi: Add r8a774c0 support
    mmc: core: Cleanup BKOPS support
    mmc: core: Drop redundant check in mmc_send_hpi_cmd()
    mmc: sdhci-omap: Workaround errata regarding SDR104/HS200 tuning failures (i929)
    dt-bindings: sdhci-omap: Add note for cpu_thermal
    mmc: sdhci-acpi: Disable LED control for Intel BYT-based controllers
    mmc: sdhci-pci: Disable LED control for Intel BYT-based controllers
    mmc: sdhci: Add quirk to disable LED control
    mmc: mmci: add variant property to set command stop bit
    misc: alcor_pci: fix spelling mistake "invailid" -> "invalid"
    mmc: meson-gx: add signal resampling
    mmc: meson-gx: align default phase on soc vendor tree
    mmc: meson-gx: remove useless lock
    mmc: meson-gx: make sure the descriptor is stopped on errors
    mmc: sdhci_am654: Add Initial Support for AM654 SDHCI driver
    dt-bindings: mmc: sdhci-of-arasan: Add deprecated message for AM65
    dt-bindings: mmc: sdhci-am654: Document bindings for the host controllers on TI's AM654 SOCs
    mmc: sdhci-msm: avoid unused function warning
    ...

    Linus Torvalds
     

17 Dec, 2018

1 commit

  • We can use MEMSTICK_POWER_{ON,OFF} along with pm_runtime_{get,put}
    helpers to let memstick host support runtime pm.

    The rpm count may go down to zero before the memstick host powers on, so
    the host can be runtime suspended.

    So before doing card detection, increment the rpm count to avoid the
    host gets runtime suspended. Balance the rpm count after card detection
    is done.

    Signed-off-by: Kai-Heng Feng
    Tested-by: Oleksandr Natalenko
    Signed-off-by: Ulf Hansson

    Kai-Heng Feng
     

08 Nov, 2018

3 commits

  • Pointer 'set' is declared but not used, remove it. Cleans up warning:

    warning: unused variable ‘set’ [-Wunused-variable]

    Signed-off-by: Colin Ian King
    Signed-off-by: Jens Axboe

    Colin Ian King
     
  • Straight forward conversion, there's room for improvement.

    Reviewed-by: Hannes Reinecke
    Tested-by: Ming Lei
    Reviewed-by: Omar Sandoval
    Signed-off-by: Jens Axboe

    Jens Axboe
     
  • Straight forward conversion, room for optimization in how everything
    is punted to a work queue. Also looks plenty racy all over the map,
    with the state changes. I fixed a bunch of them up while doing the
    conversion, but there are surely more.

    Cc: Maxim Levitsky
    Reviewed-by: Hannes Reinecke
    Tested-by: Ming Lei
    Reviewed-by: Omar Sandoval
    Signed-off-by: Jens Axboe

    Jens Axboe
     

28 Sep, 2018

1 commit

  • Update device_add_disk() to take an 'groups' argument so that
    individual drivers can register a device with additional sysfs
    attributes.
    This avoids race condition the driver would otherwise have if these
    groups were to be created with sysfs_add_groups().

    Signed-off-by: Martin Wilck
    Signed-off-by: Hannes Reinecke
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Bart Van Assche
    Signed-off-by: Jens Axboe

    Hannes Reinecke
     

13 Jun, 2018

1 commit

  • The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
    patch replaces cases of:

    kmalloc(a * b, gfp)

    with:
    kmalloc_array(a * b, gfp)

    as well as handling cases of:

    kmalloc(a * b * c, gfp)

    with:

    kmalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kmalloc_array(array_size(a, b), c, gfp)

    This does, however, attempt to ignore constant size factors like:

    kmalloc(4 * 1024, gfp)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The tools/ directory was manually excluded, since it has its own
    implementation of kmalloc().

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    kmalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    kmalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    kmalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    - kmalloc
    + kmalloc_array
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    kmalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    kmalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    kmalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products,
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kmalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kmalloc(sizeof(THING) * C2, ...)
    |
    kmalloc(sizeof(TYPE) * C2, ...)
    |
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(C1 * C2, ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

14 May, 2018

1 commit


12 May, 2018

1 commit


22 Nov, 2017

1 commit

  • This converts all remaining cases of the old setup_timer() API into using
    timer_setup(), where the callback argument is the structure already
    holding the struct timer_list. These should have no behavioral changes,
    since they just change which pointer is passed into the callback with
    the same available pointers after conversion. It handles the following
    examples, in addition to some other variations.

    Casting from unsigned long:

    void my_callback(unsigned long data)
    {
    struct something *ptr = (struct something *)data;
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, ptr);

    and forced object casts:

    void my_callback(struct something *ptr)
    {
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);

    become:

    void my_callback(struct timer_list *t)
    {
    struct something *ptr = from_timer(ptr, t, my_timer);
    ...
    }
    ...
    timer_setup(&ptr->my_timer, my_callback, 0);

    Direct function assignments:

    void my_callback(unsigned long data)
    {
    struct something *ptr = (struct something *)data;
    ...
    }
    ...
    ptr->my_timer.function = my_callback;

    have a temporary cast added, along with converting the args:

    void my_callback(struct timer_list *t)
    {
    struct something *ptr = from_timer(ptr, t, my_timer);
    ...
    }
    ...
    ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;

    And finally, callbacks without a data assignment:

    void my_callback(unsigned long data)
    {
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, 0);

    have their argument renamed to verify they're unused during conversion:

    void my_callback(struct timer_list *unused)
    {
    ...
    }
    ...
    timer_setup(&ptr->my_timer, my_callback, 0);

    The conversion is done with the following Coccinelle script:

    spatch --very-quiet --all-includes --include-headers \
    -I ./arch/x86/include -I ./arch/x86/include/generated \
    -I ./include -I ./arch/x86/include/uapi \
    -I ./arch/x86/include/generated/uapi -I ./include/uapi \
    -I ./include/generated/uapi --include ./include/linux/kconfig.h \
    --dir . \
    --cocci-file ~/src/data/timer_setup.cocci

    @fix_address_of@
    expression e;
    @@

    setup_timer(
    -&(e)
    +&e
    , ...)

    // Update any raw setup_timer() usages that have a NULL callback, but
    // would otherwise match change_timer_function_usage, since the latter
    // will update all function assignments done in the face of a NULL
    // function initialization in setup_timer().
    @change_timer_function_usage_NULL@
    expression _E;
    identifier _timer;
    type _cast_data;
    @@

    (
    -setup_timer(&_E->_timer, NULL, _E);
    +timer_setup(&_E->_timer, NULL, 0);
    |
    -setup_timer(&_E->_timer, NULL, (_cast_data)_E);
    +timer_setup(&_E->_timer, NULL, 0);
    |
    -setup_timer(&_E._timer, NULL, &_E);
    +timer_setup(&_E._timer, NULL, 0);
    |
    -setup_timer(&_E._timer, NULL, (_cast_data)&_E);
    +timer_setup(&_E._timer, NULL, 0);
    )

    @change_timer_function_usage@
    expression _E;
    identifier _timer;
    struct timer_list _stl;
    identifier _callback;
    type _cast_func, _cast_data;
    @@

    (
    -setup_timer(&_E->_timer, _callback, _E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, &_callback, _E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, _callback, (_cast_data)_E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, (_cast_func)_callback, _E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E._timer, _callback, (_cast_data)_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, _callback, (_cast_data)&_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, &_callback, (_cast_data)_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
    +timer_setup(&_E._timer, _callback, 0);
    |
    _E->_timer@_stl.function = _callback;
    |
    _E->_timer@_stl.function = &_callback;
    |
    _E->_timer@_stl.function = (_cast_func)_callback;
    |
    _E->_timer@_stl.function = (_cast_func)&_callback;
    |
    _E._timer@_stl.function = _callback;
    |
    _E._timer@_stl.function = &_callback;
    |
    _E._timer@_stl.function = (_cast_func)_callback;
    |
    _E._timer@_stl.function = (_cast_func)&_callback;
    )

    // callback(unsigned long arg)
    @change_callback_handle_cast
    depends on change_timer_function_usage@
    identifier change_timer_function_usage._callback;
    identifier change_timer_function_usage._timer;
    type _origtype;
    identifier _origarg;
    type _handletype;
    identifier _handle;
    @@

    void _callback(
    -_origtype _origarg
    +struct timer_list *t
    )
    {
    (
    ... when != _origarg
    _handletype *_handle =
    -(_handletype *)_origarg;
    +from_timer(_handle, t, _timer);
    ... when != _origarg
    |
    ... when != _origarg
    _handletype *_handle =
    -(void *)_origarg;
    +from_timer(_handle, t, _timer);
    ... when != _origarg
    |
    ... when != _origarg
    _handletype *_handle;
    ... when != _handle
    _handle =
    -(_handletype *)_origarg;
    +from_timer(_handle, t, _timer);
    ... when != _origarg
    |
    ... when != _origarg
    _handletype *_handle;
    ... when != _handle
    _handle =
    -(void *)_origarg;
    +from_timer(_handle, t, _timer);
    ... when != _origarg
    )
    }

    // callback(unsigned long arg) without existing variable
    @change_callback_handle_cast_no_arg
    depends on change_timer_function_usage &&
    !change_callback_handle_cast@
    identifier change_timer_function_usage._callback;
    identifier change_timer_function_usage._timer;
    type _origtype;
    identifier _origarg;
    type _handletype;
    @@

    void _callback(
    -_origtype _origarg
    +struct timer_list *t
    )
    {
    + _handletype *_origarg = from_timer(_origarg, t, _timer);
    +
    ... when != _origarg
    - (_handletype *)_origarg
    + _origarg
    ... when != _origarg
    }

    // Avoid already converted callbacks.
    @match_callback_converted
    depends on change_timer_function_usage &&
    !change_callback_handle_cast &&
    !change_callback_handle_cast_no_arg@
    identifier change_timer_function_usage._callback;
    identifier t;
    @@

    void _callback(struct timer_list *t)
    { ... }

    // callback(struct something *handle)
    @change_callback_handle_arg
    depends on change_timer_function_usage &&
    !match_callback_converted &&
    !change_callback_handle_cast &&
    !change_callback_handle_cast_no_arg@
    identifier change_timer_function_usage._callback;
    identifier change_timer_function_usage._timer;
    type _handletype;
    identifier _handle;
    @@

    void _callback(
    -_handletype *_handle
    +struct timer_list *t
    )
    {
    + _handletype *_handle = from_timer(_handle, t, _timer);
    ...
    }

    // If change_callback_handle_arg ran on an empty function, remove
    // the added handler.
    @unchange_callback_handle_arg
    depends on change_timer_function_usage &&
    change_callback_handle_arg@
    identifier change_timer_function_usage._callback;
    identifier change_timer_function_usage._timer;
    type _handletype;
    identifier _handle;
    identifier t;
    @@

    void _callback(struct timer_list *t)
    {
    - _handletype *_handle = from_timer(_handle, t, _timer);
    }

    // We only want to refactor the setup_timer() data argument if we've found
    // the matching callback. This undoes changes in change_timer_function_usage.
    @unchange_timer_function_usage
    depends on change_timer_function_usage &&
    !change_callback_handle_cast &&
    !change_callback_handle_cast_no_arg &&
    !change_callback_handle_arg@
    expression change_timer_function_usage._E;
    identifier change_timer_function_usage._timer;
    identifier change_timer_function_usage._callback;
    type change_timer_function_usage._cast_data;
    @@

    (
    -timer_setup(&_E->_timer, _callback, 0);
    +setup_timer(&_E->_timer, _callback, (_cast_data)_E);
    |
    -timer_setup(&_E._timer, _callback, 0);
    +setup_timer(&_E._timer, _callback, (_cast_data)&_E);
    )

    // If we fixed a callback from a .function assignment, fix the
    // assignment cast now.
    @change_timer_function_assignment
    depends on change_timer_function_usage &&
    (change_callback_handle_cast ||
    change_callback_handle_cast_no_arg ||
    change_callback_handle_arg)@
    expression change_timer_function_usage._E;
    identifier change_timer_function_usage._timer;
    identifier change_timer_function_usage._callback;
    type _cast_func;
    typedef TIMER_FUNC_TYPE;
    @@

    (
    _E->_timer.function =
    -_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E->_timer.function =
    -&_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E->_timer.function =
    -(_cast_func)_callback;
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E->_timer.function =
    -(_cast_func)&_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E._timer.function =
    -_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E._timer.function =
    -&_callback;
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E._timer.function =
    -(_cast_func)_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    |
    _E._timer.function =
    -(_cast_func)&_callback
    +(TIMER_FUNC_TYPE)_callback
    ;
    )

    // Sometimes timer functions are called directly. Replace matched args.
    @change_timer_function_calls
    depends on change_timer_function_usage &&
    (change_callback_handle_cast ||
    change_callback_handle_cast_no_arg ||
    change_callback_handle_arg)@
    expression _E;
    identifier change_timer_function_usage._timer;
    identifier change_timer_function_usage._callback;
    type _cast_data;
    @@

    _callback(
    (
    -(_cast_data)_E
    +&_E->_timer
    |
    -(_cast_data)&_E
    +&_E._timer
    |
    -_E
    +&_E->_timer
    )
    )

    // If a timer has been configured without a data argument, it can be
    // converted without regard to the callback argument, since it is unused.
    @match_timer_function_unused_data@
    expression _E;
    identifier _timer;
    identifier _callback;
    @@

    (
    -setup_timer(&_E->_timer, _callback, 0);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, _callback, 0L);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E->_timer, _callback, 0UL);
    +timer_setup(&_E->_timer, _callback, 0);
    |
    -setup_timer(&_E._timer, _callback, 0);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, _callback, 0L);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_E._timer, _callback, 0UL);
    +timer_setup(&_E._timer, _callback, 0);
    |
    -setup_timer(&_timer, _callback, 0);
    +timer_setup(&_timer, _callback, 0);
    |
    -setup_timer(&_timer, _callback, 0L);
    +timer_setup(&_timer, _callback, 0);
    |
    -setup_timer(&_timer, _callback, 0UL);
    +timer_setup(&_timer, _callback, 0);
    |
    -setup_timer(_timer, _callback, 0);
    +timer_setup(_timer, _callback, 0);
    |
    -setup_timer(_timer, _callback, 0L);
    +timer_setup(_timer, _callback, 0);
    |
    -setup_timer(_timer, _callback, 0UL);
    +timer_setup(_timer, _callback, 0);
    )

    @change_callback_unused_data
    depends on match_timer_function_unused_data@
    identifier match_timer_function_unused_data._callback;
    type _origtype;
    identifier _origarg;
    @@

    void _callback(
    -_origtype _origarg
    +struct timer_list *unused
    )
    {
    ... when != _origarg
    }

    Signed-off-by: Kees Cook

    Kees Cook
     

09 Jun, 2017

1 commit

  • Currently we use nornal Linux errno values in the block layer, and while
    we accept any error a few have overloaded magic meanings. This patch
    instead introduces a new blk_status_t value that holds block layer specific
    status codes and explicitly explains their meaning. Helpers to convert from
    and to the previous special meanings are provided for now, but I suspect
    we want to get rid of them in the long run - those drivers that have a
    errno input (e.g. networking) usually get errnos that don't know about
    the special block layer overloads, and similarly returning them to userspace
    will usually return somethings that strictly speaking isn't correct
    for file system operations, but that's left as an exercise for later.

    For now the set of errors is a very limited set that closely corresponds
    to the previous overloaded errno values, but there is some low hanging
    fruite to improve it.

    blk_status_t (ab)uses the sparse __bitwise annotations to allow for sparse
    typechecking, so that we can easily catch places passing the wrong values.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

18 Feb, 2017

1 commit


01 Feb, 2017

2 commits


25 Jan, 2017

1 commit

  • gcc-7 produces a harmless false-postive warning about a possible NULL
    pointer access:

    drivers/memstick/core/memstick.c: In function 'h_memstick_read_dev_id':
    drivers/memstick/core/memstick.c:309:3: error: argument 2 null where non-null expected [-Werror=nonnull]
    memcpy(mrq->data, buf, mrq->data_len);

    This can't happen because the caller sets the command to 'MS_TPC_READ_REG',
    which causes the data direction to be 'READ' and the NULL pointer not
    accessed.

    As a simple workaround for the warning, we can pass a pointer to the
    data that we actually want to read into. This is not needed here, but
    also harmless, and lets the compiler know that the access is ok.

    Link: http://lkml.kernel.org/r/20170111144143.548867-1-arnd@arndb.de
    Signed-off-by: Arnd Bergmann
    Cc: Alex Dubov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arnd Bergmann
     

28 Oct, 2016

1 commit

  • A lot of the REQ_* flags are only used on struct requests, and only of
    use to the block layer and a few drivers that dig into struct request
    internals.

    This patch adds a new req_flags_t rq_flags field to struct request for
    them, and thus dramatically shrinks the number of common requests. It
    also removes the unfortunate situation where we have to fit the fields
    from the same enum into 32 bits for struct bio and 64 bits for
    struct request.

    Signed-off-by: Christoph Hellwig
    Reviewed-by: Shaun Tancheff
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

03 Aug, 2016

1 commit

  • When alloc_disk(0) is used the ->major number is completely ignored.
    All devices are allocated with a major of BLOCK_EXT_MAJOR.

    So remove registration and deregistration of 'major'.

    Link: http://lkml.kernel.org/r/20160602064318.4403.49955.stgit@noble
    Signed-off-by: NeilBrown
    Cc: Keith Busch
    Cc: Jens Axboe
    Cc: Maxim Levitsky
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    NeilBrown
     

21 Jul, 2016

1 commit


28 Jun, 2016

1 commit

  • For block drivers that specify a parent device, convert them to use
    device_add_disk().

    This conversion was done with the following semantic patch:

    @@
    struct gendisk *disk;
    expression E;
    @@

    - disk->driverfs_dev = E;
    ...
    - add_disk(disk);
    + device_add_disk(E, disk);

    @@
    struct gendisk *disk;
    expression E1, E2;
    @@

    - disk->driverfs_dev = E1;
    ...
    E2 = disk;
    ...
    - add_disk(E2);
    + device_add_disk(E1, E2);

    ...plus some manual fixups for a few missed conversions.

    Cc: Jens Axboe
    Cc: Keith Busch
    Cc: Michael S. Tsirkin
    Cc: David Woodhouse
    Cc: David S. Miller
    Cc: James Bottomley
    Cc: Ross Zwisler
    Cc: Konrad Rzeszutek Wilk
    Cc: Martin K. Petersen
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Johannes Thumshirn
    Signed-off-by: Dan Williams

    Dan Williams
     

24 May, 2016

1 commit

  • Use kmemdup when some other buffer is immediately copied into allocated
    region. It replaces call to allocation followed by memcpy, by a single
    call to kmemdup.

    [akpm@linux-foundation.org: remove unneeded cast to void*]
    Link: http://lkml.kernel.org/r/1463665743-16269-1-git-send-email-falakreyaz@gmail.com
    Signed-off-by: Muhammad Falak R Wani
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Muhammad Falak R Wani
     

28 Apr, 2016

1 commit


21 Jan, 2016

1 commit

  • do_div is the wrong way to divide a sector_t, as it is less efficient
    when sector_t is 32-bit wide. With the upcoming do_div optimizations,
    the kernel starts warning about this:

    drivers/memstick/core/ms_block.c: In function 'msb_io_work':
    include/asm-generic/div64.h:207:28: warning: comparison of distinct pointer types lacks a cast

    This changes the code to use sector_div instead, which always produces
    optimal code.

    Signed-off-by: Arnd Bergmann
    Cc: Maxim Levitsky
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arnd Bergmann
     

17 Apr, 2015

1 commit

  • Using the indenting we can see the curly braces were obviously intended.
    This is a static checker fix, but my guess is that we don't read enough
    bytes, because we don't calculate "t_len" correctly.

    Fixes: f1d82698029b ('memstick: use fully asynchronous request processing')
    Signed-off-by: Dan Carpenter
    Cc: Alex Dubov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Carpenter
     

15 Nov, 2013

2 commits


13 Nov, 2013

2 commits

  • In h_msb_read_page() in ms_block.c, flow never reaches case
    MSB_RP_RECIVE_STATUS_REG. This causes error when MEMSTICK_INT_ERR is
    encountered and status error bits are going to be examined, but the status
    will never be copied back.

    Fix it by transitioning to MSB_RP_RECIVE_STATUS_REG right after
    MSB_RP_SEND_READ_STATUS_REG.

    Signed-off-by: Roger Tseng
    Acked-by: Maxim Levitsky
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Roger Tseng
     
  • attrs field of attribute_group structure is a pointer to a pointer (as in
    an array of pointers) rather than pointer to attribute struct (as in an
    array of structures), so when allocating size of the pointer sholud be
    used instead of the structure it is pointing to.

    While at it, also change the call to use kcalloc rather than kzalloc.

    Signed-off-by: Michal Nazarewicz
    Cc: Tejun Heo
    Cc: Al Viro
    Cc: Alex Dubov
    Cc: Maxim Levitsky
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michal Nazarewicz
     

17 Oct, 2013

1 commit