13 Jun, 2018

1 commit

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

    kzalloc(a * b, gfp)

    with:
    kcalloc(a * b, gfp)

    as well as handling cases of:

    kzalloc(a * b * c, gfp)

    with:

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

    as it's slightly less ugly than:

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

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

    kzalloc(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 Coccinelle script used for this was:

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

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

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

    (
    kzalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

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

    - kzalloc
    + kcalloc
    (
    - 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;
    @@

    (
    kzalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    kzalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    kzalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(
    - (E1) * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * E3
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - (E1) * (E2) * (E3)
    + array3_size(E1, E2, E3)
    , ...)
    |
    kzalloc(
    - 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;
    @@

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

    Signed-off-by: Kees Cook

    Kees Cook
     

24 Mar, 2017

1 commit

  • With the upcoming NTP correction related rate adjustments to be implemented
    in the clockevents core, the latter needs to get informed about every rate
    change of a clockevent device made after its registration.

    Currently, sh_tmu violates this requirement in that it registers its
    clockevent device with a dummy rate and sets its final rate through
    clockevents_config() called from its ->set_state_oneshot() and
    ->set_state_periodic() functions respectively.

    This patch moves the setting of the clockevent device's rate to its
    registration.

    Note that there has been some back and forth regarding this question with
    respect to the clocksource also provided by this driver:
    commit 66f49121ffa4 ("clocksource: sh_tmu: compute mult and shift before
    registration")
    moves the rate determination from the clocksource's ->enable() function to
    before its registration. OTOH, the later
    commit 0aeac458d9eb ("clocksource: sh_tmu: __clocksource_updatefreq_hz()
    update")
    basically reverts this, saying
    "Without this patch the old code uses clocksource_register() together
    with a hack that assumes a never changing clock rate."

    However, I checked all current sh_tmu users in arch/sh as well as in
    arch/arm/mach-shmobile carefully and right now, none of them changes any
    rate in any clock tree relevant to sh_tmu after their respective
    time_init(). Since all sh_tmu instances are created after time_init(), none
    of them should ever observe any clock rate changes.

    What's more, both, a clocksource as well as a clockevent device, can
    immediately get selected for use at their registration and thus, enabled
    at this point already. So it's probably safer to assume a "never changing
    clock rate" here.

    - Move the struct sh_tmu_channel's ->rate member to struct sh_tmu_device:
    it's a property of the underlying clock which is in turn specific to
    the sh_tmu_device.
    - Determine the ->rate value in sh_tmu_setup() at device probing rather
    than at first usage.
    - Set the clockevent device's rate at its registration.
    - Although not strictly necessary for the upcoming clockevent core changes,
    set the clocksource's rate at its registration for consistency.

    Signed-off-by: Nicolai Stange
    Signed-off-by: John Stultz

    Nicolai Stange
     

25 Dec, 2016

1 commit


10 Aug, 2015

2 commits

  • Traceback in -next due to commit 'clockevents/drivers/sh_tmu: Migrate to new
    'set-state' interface'.

    Commit ("clockevents/drivers/sh_tmu: Migrate to new 'set-state' interface")
    in -next causes the following traceback. This is seen with qemu runs for the sh
    target.

    ------------[ cut here ]------------
    WARNING: at drivers/clocksource/sh_tmu.c:202
    Modules linked in:

    CPU: 0 PID: 0 Comm: swapper Not tainted 4.2.0-rc3-next-20150720 #1
    task: 8c411ed8 ti: 8c40e000 task.ti: 8c40e000
    PC is at sh_tmu_disable+0x40/0x60
    PR is at sh_tmu_clock_event_shutdown+0x8/0x20
    PC : 8c271220 SP : 8c40ff10 SR : 400081f1 TEA : 00000000
    R0 : 8c271240 R1 : 8fc08cfc R2 : 00000000 R3 : 3fffffff
    R4 : 8fc08c00 R5 : 00000001 R6 : 00000002 R7 : ffffffff
    R8 : 00000001 R9 : 8fc08c20 R10 : 00000000 R11 : 00000000
    R12 : 8c012820 R13 : 00000000 R14 : 00000000
    MACH: 3b9ac9ff MACL: 80000000 GBR : 00000000 PR : 8c271248

    Call trace:
    [] clockevents_switch_state+0x16/0x60
    [] clockevents_shutdown+0xc/0x40
    [] tick_check_new_device+0x90/0xc0
    [] clockevents_register_device+0x56/0x120
    [] tick_check_new_device+0x0/0xc0
    [] sh_tmu_probe+0x29a/0x4e0
    [] kasprintf+0x14/0x20
    [] early_platform_driver_probe+0x20e/0x2bc
    [] platform_match+0x0/0x100
    [] printk+0x0/0x24
    [] start_kernel+0x32e/0x574
    [] printk+0x0/0x24
    [] strlen+0x0/0x58
    [] unknown_bootoption+0x0/0x1e0
    [] _stext+0x24/0x30

    ---[ end trace cb88537fdc8fa200 ]---

    Signed-off-by: Viresh Kumar
    Signed-off-by: Daniel Lezcano
    Tested-by: Geert Uytterhoeven

    Viresh Kumar
     
  • Migrate sh_tmu driver to the new 'set-state' interface provided by
    clockevents core, the earlier 'set-mode' interface is marked obsolete
    now.

    This also enables us to implement callbacks for new states of clockevent
    devices, for example: ONESHOT_STOPPED.

    Cc: Magnus Damm
    Cc: Laurent Pinchart
    Cc: Paul Mundt
    Signed-off-by: Viresh Kumar
    Signed-off-by: Daniel Lezcano
    Acked-by: Laurent Pinchart

    Viresh Kumar
     

13 Mar, 2015

1 commit

  • Ingo requested this function be renamed to improve readability,
    so I've renamed __clocksource_updatefreq_scale() as well as the
    __clocksource_updatefreq_hz/khz() functions to avoid
    squishedtogethernames.

    This touches some of the sh clocksources, which I've not tested.

    The arch/arm/plat-omap change is just a comment change for
    consistency.

    Signed-off-by: John Stultz
    Cc: Daniel Lezcano
    Cc: Dave Jones
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Prarit Bhargava
    Cc: Richard Cochran
    Cc: Stephen Boyd
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/1426133800-29329-13-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    John Stultz
     

05 Jan, 2015

1 commit


04 Jul, 2014

1 commit


02 Jul, 2014

2 commits


23 May, 2014

2 commits


19 May, 2014

1 commit


16 Apr, 2014

15 commits


14 Jan, 2014

1 commit

  • Pull clocksource/clockevent updates from Daniel Lezcano:

    * Axel Lin removed an unused structure defining the ids for the
    bcm kona driver.

    * Ezequiel Garcia enabled the timer divider only when the 25MHz
    timer is not used for the armada 370 XP.

    * Jingoo Han removed a pointless platform data initialization for
    the sh_mtu and sh_mtu2.

    * Laurent Pinchart added the clk_prepare/clk_unprepare for sh_cmt.

    * Linus Walleij added a useful warning in clk_of when no clocks
    are found while the old behavior was to silently hang at boot time.

    * Maxime Ripard added the high speed timer drivers for the
    Allwinner SoCs (A10, A13, A20). He increased the rating, shared the
    irq across all available cpus and fixed the clockevent's irq
    initialization for the sun4i.

    * Michael Opdenacker removed the usage of the IRQF_DISABLED for the
    all the timers driver located in drivers/clocksource.

    * Stephen Boyd switched to sched_clock_register for the
    arm_global_timer, cadence_ttc, sun4i and orion timers.

    Conflicts:
    drivers/clocksource/clksrc-of.c

    Signed-off-by: Ingo Molnar

    Ingo Molnar
     

11 Dec, 2013

2 commits


21 Nov, 2013

2 commits


13 Mar, 2013

1 commit

  • The reason for this is to ensure that TMU is probed earlier
    than with its previous initcall level, module init.

    This came up as a problem with using CMT as a clock source kzm9g-reference
    which does not make use of early timers or devices. In that scenario
    initialisation of SDHI and MMCIF both stall on msleep() calls due to the
    absence of a initialised clock source.

    The purpose of this change is to keep the TMU code in sync with the CMT code
    which has been modified in a similar manner..

    Boot tested on: mackerel.

    Signed-off-by: Simon Horman

    Simon Horman
     

04 Jan, 2013

1 commit

  • CONFIG_HOTPLUG is going away as an option. As a result, the __dev*
    markings need to be removed.

    This change removes the use of __devinit, __devexit_p, __devinitdata,
    __devinitconst, and __devexit from these drivers.

    Based on patches originally written by Bill Pemberton, but redone by me
    in order to handle some of the coding style issues better, by hand.

    Cc: Bill Pemberton
    Cc: John Stultz
    Cc: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

04 Sep, 2012

4 commits

  • Modify the SH TMU clock source/clock event device driver to support
    runtime PM at a basic level (i.e. device clocks can be disabled and
    enabled, but domain power must be on, because the devices have to
    be marked as "irq safe").

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Magnus Damm

    Rafael J. Wysocki
     
  • The syscore device PM flag is used to mark the devices (belonging to
    a PM domain) that should never be turned off, except for the system
    core (syscore) suspend/hibernation and resume stages. That flag is
    stored in the device's struct pm_subsys_data object whose address is
    available from struct device. However, in some situations it may be
    convenient to set that flag before the device is added to a PM
    domain, so it is better to move it directly to the "power" member of
    struct device. Then, it can be checked by the routines in
    drivers/base/power/runtime.c and drivers/base/power/main.c, which is
    more straightforward.

    This also reduces the number of dev_gpd_data() invocations in the
    generic PM domains framework, so the overhead related to the syscore
    flag is slightly smaller.

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Magnus Damm

    Rafael J. Wysocki
     
  • The always_on device flag is used to mark the devices (belonging to
    a PM domain) that should never be turned off, except for the system
    core (syscore) suspend/hibernation and resume stages. Change name
    of that flag to "syscore" to better reflect its purpose.

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Magnus Damm

    Rafael J. Wysocki
     
  • Introduce suspend/resume routines for SH TMU clock source and
    clock event device such that if those devices belong to a PM domain,
    the generic PM domains framework will be notified that the given
    domain may be turned off (during system suspend) or that it has to
    be turned on (during system resume).

    This change allows the A4R domain on SH7372 to be turned off during
    system suspend (tested on the Mackerel board) if the TMU clock source
    and/or clock event device is in use.

    Signed-off-by: Rafael J. Wysocki
    Acked-by: Magnus Damm

    Rafael J. Wysocki
     

11 Jun, 2012

1 commit