21 Feb, 2019

1 commit


12 Feb, 2019

7 commits


10 Jan, 2019

1 commit

  • commit 3cc9ffbb1f51eb4320575a48e4805a8f52e0e26b upstream.

    Add the missing adjustment of the month range on alarm reads from the
    RTC, correcting an issue coming from commit 9c6dfed92c3e ("rtc: m41t80:
    add alarm functionality"). The range is 1-12 for hardware and 0-11 for
    `struct rtc_time', and is already correctly handled on alarm writes to
    the RTC.

    It was correct up until commit 48e9766726eb ("drivers/rtc/rtc-m41t80.c:
    remove disabled alarm functionality") too, which removed the previous
    implementation of alarm support.

    Signed-off-by: Maciej W. Rozycki
    Fixes: 9c6dfed92c3e ("rtc: m41t80: add alarm functionality")
    References: 48e9766726eb ("drivers/rtc/rtc-m41t80.c: remove disabled alarm functionality")
    Cc: stable@vger.kernel.org # 4.7+
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Greg Kroah-Hartman

    Maciej W. Rozycki
     

21 Dec, 2018

1 commit

  • [ Upstream commit cd7f3a249dbed2858e6c2f30e5be7f1f7a709ee2 ]

    In order to read correctly from asynchronously updated RTC registers,
    it's necessary to read repeatedly until their values do not change from
    read to read. It's also necessary to wait for three RTC clock ticks for
    certain operations. There are no timeouts in this code and these
    operations could possibly loop forever.

    To avoid kernel hangs, put in timeouts.

    The iMX7d can be configured to stop the SRTC on a tamper event, which
    will lockup the kernel inside this driver as described above.

    These hangs can happen when running under qemu, which doesn't emulate
    the SNVS RTC, though currently the driver will refuse to load on qemu
    due to a timeout in the driver probe method.

    It could also happen if the SRTC block where somehow placed into reset
    or the slow speed clock that drives the SRTC counter (but not the CPU)
    were to stop.

    The symptoms on a two core iMX7d are a work queue hang on
    rtc_timer_do_work(), which eventually blocks a systemd fsnotify
    operation that triggers a work queue flush, causing systemd to hang and
    thus causing all services that should be started by systemd, like a
    console getty, to fail to start or stop.

    Also optimize the wait code to wait less. It only needs to wait for the
    clock to advance three ticks, not to see it change three times.

    Cc: Alexandre Belloni
    Cc: Alessandro Zummo
    Cc: Fabio Estevam
    Cc: Shawn Guo
    Cc: Bryan O'Donoghue
    Signed-off-by: Trent Piepho
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin

    Trent Piepho
     

17 Dec, 2018

1 commit

  • [ Upstream commit 0145b50566e7de5637e80ecba96c7f0e6fff1aad ]

    Before this commit sensor_hub_input_attr_get_raw_value() failed to take
    the signedness of 16 and 8 bit values into account, returning e.g.
    65436 instead of -100 for the z-axis reading of an accelerometer.

    This commit adds a new is_signed parameter to the function and makes all
    callers pass the appropriate value for this.

    While at it, this commit also fixes up some neighboring lines where
    statements were needlessly split over 2 lines to improve readability.

    Signed-off-by: Hans de Goede
    Acked-by: Srinivas Pandruvada
    Acked-by: Benjamin Tissoires
    Cc:
    Signed-off-by: Jonathan Cameron
    Signed-off-by: Sasha Levin

    Hans de Goede
     

01 Dec, 2018

2 commits

  • commit 26e480f7bb7840fc0daa9c3af7c4501b2cf5902f upstream.

    If pinctrl_register() fails probe will return with an error without locking
    the RTC and disabling pm_runtime.
    Set ret and jump to err instead.

    Fixes: 97ea1906b3c2 ("rtc: omap: Support ext_wakeup configuration")
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sudip Mukherjee
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 9bde0afb7a906f1dabdba37162551565740b862d ]

    pcf2127_i2c_gather_write() allocates memory as local variable
    for i2c_master_send(), after finishing the master transfer,
    the allocated memory should be freed. The kmemleak is reported:

    unreferenced object 0xffff80231e7dba80 (size 64):
    comm "hwclock", pid 27762, jiffies 4296880075 (age 356.944s)
    hex dump (first 32 bytes):
    03 00 12 03 19 02 11 13 00 80 98 18 00 00 ff ff ................
    00 50 00 00 00 00 00 00 02 00 00 00 00 00 00 00 .P..............
    backtrace:
    [] create_object+0xf8/0x278
    [] kmemleak_alloc+0x74/0xa0
    [] __kmalloc+0x1ac/0x348
    [] pcf2127_i2c_gather_write+0x54/0xf8
    [] _regmap_raw_write+0x464/0x850
    [] regmap_bulk_write+0x1a4/0x348
    [] pcf2127_rtc_set_time+0xac/0xe8
    [] rtc_set_time+0x80/0x138
    [] rtc_dev_ioctl+0x398/0x610
    [] do_vfs_ioctl+0xb0/0x848
    [] SyS_ioctl+0x8c/0xa8
    [] el0_svc_naked+0x34/0x38
    [] 0xffffffffffffffff

    Signed-off-by: Xulin Sun
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin

    Xulin Sun
     

21 Nov, 2018

1 commit

  • commit 7ce9a992ffde8ce93d5ae5767362a5c7389ae895 upstream.

    Fix an issue with the 32-bit range error path in `rtc_hctosys' where no
    error code is set and consequently the successful preceding call result
    from `rtc_read_time' is propagated to `rtc_hctosys_ret'. This in turn
    makes any subsequent call to `hctosys_show' incorrectly report in sysfs
    that the system time has been set from this RTC while it has not.

    Set the error to ERANGE then if we can't express the result due to an
    overflow.

    Signed-off-by: Maciej W. Rozycki
    Fixes: b3a5ac42ab18 ("rtc: hctosys: Ensure system time doesn't overflow time_t")
    Cc: stable@vger.kernel.org # 4.17+
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Greg Kroah-Hartman

    Maciej W. Rozycki
     

26 Sep, 2018

1 commit

  • [ Upstream commit 7874b919866ba91bac253fa219d3d4c82bb944df ]

    When devm_ioremap fails, the lack of error-handling code may
    cause unexpected results.

    This patch adds error-handling code after calling devm_ioremap.

    Signed-off-by: Zhouyang Jia
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Zhouyang Jia
     

10 Sep, 2018

1 commit

  • commit 5c8b84f410b3819d14cb1ebf32e4b3714b5a6e0b upstream.

    Do not set the system power-off callback and omap power-off rtc pointer
    until we're done setting up our device to avoid leaving stale pointers
    around after a late probe error.

    Fixes: 97ea1906b3c2 ("rtc: omap: Support ext_wakeup configuration")
    Cc: stable # 4.9
    Cc: Marcin Niestroj
    Cc: Tony Lindgren
    Signed-off-by: Johan Hovold
    Acked-by: Tony Lindgren
    Reviewed-by: Marcin Niestroj
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Greg Kroah-Hartman

    Johan Hovold
     

03 Aug, 2018

4 commits

  • [ Upstream commit e6000a438e534ee0afd9e83b67f4e23a26dd1067 ]

    The IRQ is requested before the struct rtc is allocated and registered, but
    this struct is used in the IRQ handler. This may lead to a NULL pointer
    dereference.

    Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
    before requesting the IRQ.

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 9a99247c9c1d1c95c6e8153d013979aac6111c6e ]

    The probe function is not allowed to fail after the RTC is registered
    because the following may happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 63d22063073b0ab46d1e06fe633fb5de8f5c58e1 ]

    The probe function is not allowed to fail after the RTC is registered
    because the following may happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit abfdff44bc38e9e2ef7929f633fb8462632299d4 ]

    When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set,
    rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the
    subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that
    case.

    Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting
    programs think the alarms are working for a particular RTC when they are
    not.

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     

03 Jul, 2018

1 commit

  • commit 09018d4bd7994c2c9f775029bc24589bc85f76fa upstream.

    clk-gate core will take bit_idx through clk_register_gate
    and then do clk_gate_ops by using BIT(bit_idx), but rtc-sun6i
    is passing bit_idx as BIT(bit_idx) it becomes BIT(BIT(bit_idx)
    which is wrong and eventually external gate clock is not enabling.

    This patch fixed by passing bit index and the original change
    introduced from below commit.
    "rtc: sun6i: Add support for the external oscillator gate"
    (sha1: 17ecd246414b3a0fe0cb248c86977a8bda465b7b)

    Signed-off-by: Michael Trimarchi
    Fixes: 17ecd246414b ("rtc: sun6i: Add support for the external oscillator gate")
    Cc: stable@vger.kernel.org
    Signed-off-by: Jagan Teki
    Acked-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Greg Kroah-Hartman

    Michael Trimarchi
     

25 May, 2018

7 commits

  • [ Upstream commit 82d632b85eb89f97051530f556cb49ee1c04bde7 ]

    Fix the following warning in MIPS allmodconfig by adding a
    MODULE_LICENSE() at the end of rtc-goldfish.c, based on the file header
    comment which says GNU General Public License version 2:

    WARNING: modpost: missing MODULE_LICENSE() in drivers/rtc/rtc-goldfish.o

    Fixes: f22d9cdcb5eb ("rtc: goldfish: Add RTC driver for Android emulator")
    Signed-off-by: James Hogan
    Cc: Miodrag Dinic
    Cc: Alessandro Zummo
    Cc: Alexandre Belloni
    Cc: linux-rtc@vger.kernel.org
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    James Hogan
     
  • [ Upstream commit bcdd559268039d8340d38fa58668393596e29fdc ]

    The probe function is not allowed to fail after registering the RTC because
    the following may happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
    as late as possible.

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 347876ad47b9923ce26e686173bbf46581802ffa ]

    The shifting of buf[5] by 24 bits to the left will be promoted to
    a 32 bit signed int and then sign-extended to an unsigned long. If
    the top bit of buf[5] is set then all then all the upper bits sec
    end up as also being set because of the sign-extension. Fix this by
    casting buf[5] to an unsigned long before the shift.

    Detected by CoverityScan, CID#1465292 ("Unintended sign extension")

    Fixes: 0e1492330cd2 ("rtc: add rtc-tx4939 driver")
    Signed-off-by: Colin Ian King
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Colin Ian King
     
  • [ Upstream commit 10d0c768cc6d581523d673b9d1b54213f8a5eb24 ]

    The IRQ is requested before the struct rtc is allocated and registered, but
    this struct is used in the IRQ handler, leading to:

    Unable to handle kernel NULL pointer dereference at virtual address 0000017c
    pgd = a38a2f9b
    [0000017c] *pgd=00000000
    Internal error: Oops: 5 [#1] ARM
    Modules linked in:
    CPU: 0 PID: 613 Comm: irq/48-m41t80 Not tainted 4.16.0-rc1+ #42
    Hardware name: Atmel SAMA5
    PC is at mutex_lock+0x14/0x38
    LR is at m41t80_handle_irq+0x1c/0x9c
    pc : [] lr : [] psr: 20000013
    sp : dec73f30 ip : 00000000 fp : dec56d98
    r10: df437cf0 r9 : c0a03008 r8 : c0145ffc
    r7 : df5c4300 r6 : dec568d0 r5 : df593000 r4 : 0000017c
    r3 : df592800 r2 : 60000013 r1 : df593000 r0 : 0000017c
    Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
    Control: 10c53c7d Table: 20004059 DAC: 00000051
    Process irq/48-m41t80 (pid: 613, stack limit = 0xb52d091e)
    Stack: (0xdec73f30 to 0xdec74000)
    3f20: dec56840 df5c4300 00000001 df5c4300
    3f40: c0145ffc c0146018 dec56840 ffffe000 00000001 c0146290 dec567c0 00000000
    3f60: c0146084 ed7c9a62 c014615c dec56d80 dec567c0 00000000 dec72000 dec56840
    3f80: c014615c c012ffc0 dec72000 dec567c0 c012fe80 00000000 00000000 00000000
    3fa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 00000000
    3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 29282726 2d2c2b2a
    [] (mutex_lock) from [] (m41t80_handle_irq+0x1c/0x9c)
    [] (m41t80_handle_irq) from [] (irq_thread_fn+0x1c/0x54)
    [] (irq_thread_fn) from [] (irq_thread+0x134/0x1c0)
    [] (irq_thread) from [] (kthread+0x140/0x148)
    [] (kthread) from [] (ret_from_fork+0x14/0x2c)
    Exception stack(0xdec73fb0 to 0xdec73ff8)
    3fa0: 00000000 00000000 00000000 00000000
    3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
    Code: e3c33d7f e3c3303f f5d0f000 e593300c (e1901f9f)
    ---[ end trace 22b027302eb7c604 ]---
    genirq: exiting task "irq/48-m41t80" (613) is an active IRQ thread (irq 48)

    Also, there is another possible race condition. The probe function is not
    allowed to fail after the RTC is registered because the following may
    happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
    before requesting the IRQ and register it as late as possible.

    Signed-off-by: Alexandre Belloni

    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 201fac95e799c3d0304ec724d555e1251b9f6e84 ]

    The probe function is not allowed to fail after registering the RTC because
    the following may happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
    as late as possible.

    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit b3a5ac42ab18b7d1a8f2f072ca0ee76a3b754a43 ]

    On 32bit platforms, time_t is still a signed 32bit long. If it is
    overflowed, userspace and the kernel cant agree on the current system time.
    This causes multiple issues, in particular with systemd:
    https://github.com/systemd/systemd/issues/1143

    A good workaround is to simply avoid using hctosys which is something I
    greatly encourage as the time is better set by userspace.

    However, many distribution enable it and use systemd which is rendering the
    system unusable in case the RTC holds a date after 2038 (and more so after
    2106). Many drivers have workaround for this case and they should be
    eliminated so there is only one place left to fix when userspace is able to
    cope with dates after the 31bit overflow.

    Acked-by: Arnd Bergmann
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 1485991c024603b2fb4ae77beb7a0d741128a48e ]

    commit 179a502f8c46 ("rtc: snvs: add Freescale rtc-snvs driver") introduces
    the SNVS RTC driver with a function snvs_rtc_enable().

    snvs_rtc_enable() can return an error on the enable path however this
    driver does not currently trap that failure on the probe() path and
    consequently if enabling the RTC fails we encounter a later error spinning
    forever in rtc_write_sync_lp().

    [ 36.093481] [] (__irq_svc) from [] (_raw_spin_unlock_irqrestore+0x34/0x44)
    [ 36.102122] [] (_raw_spin_unlock_irqrestore) from [] (regmap_read+0x4c/0x5c)
    [ 36.110938] [] (regmap_read) from [] (rtc_write_sync_lp+0x6c/0x98)
    [ 36.118881] [] (rtc_write_sync_lp) from [] (snvs_rtc_alarm_irq_enable+0x40/0x4c)
    [ 36.128041] [] (snvs_rtc_alarm_irq_enable) from [] (rtc_timer_do_work+0xd8/0x1a8)
    [ 36.137291] [] (rtc_timer_do_work) from [] (process_one_work+0x28c/0x76c)
    [ 36.145840] [] (process_one_work) from [] (worker_thread+0x34/0x58c)
    [ 36.153961] [] (worker_thread) from [] (kthread+0x138/0x150)
    [ 36.161388] [] (kthread) from [] (ret_from_fork+0x14/0x20)
    [ 36.168635] rcu_sched kthread starved for 2602 jiffies! g496 c495 f0x2 RCU_GP_WAIT_FQS(3) ->state=0x0 ->cpu=0
    [ 36.178564] rcu_sched R running task 0 8 2 0x00000000
    [ 36.185664] [] (__schedule) from [] (schedule+0x3c/0xa0)
    [ 36.192739] [] (schedule) from [] (schedule_timeout+0x78/0x4e0)
    [ 36.200422] [] (schedule_timeout) from [] (rcu_gp_kthread+0x648/0x1864)
    [ 36.208800] [] (rcu_gp_kthread) from [] (kthread+0x138/0x150)
    [ 36.216309] [] (kthread) from [] (ret_from_fork+0x14/0x20)

    This patch fixes by parsing the result of rtc_write_sync_lp() and
    propagating both in the probe and elsewhere. If the RTC doesn't start we
    don't proceed loading the driver and don't get into this loop mess later
    on.

    Fixes: 179a502f8c46 ("rtc: snvs: add Freescale rtc-snvs driver")
    Signed-off-by: Bryan O'Donoghue
    Acked-by: Shawn Guo
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Bryan O'Donoghue
     

02 May, 2018

1 commit

  • commit 682e6b4da5cbe8e9a53f979a58c2a9d7dc997175 upstream.

    The OPAL RTC driver does not sleep in case it gets OPAL_BUSY or
    OPAL_BUSY_EVENT from firmware, which causes large scheduling
    latencies, up to 50 seconds have been observed here when RTC stops
    responding (BMC reboot can do it).

    Fix this by converting it to the standard form OPAL_BUSY loop that
    sleeps.

    Fixes: 628daa8d5abf ("powerpc/powernv: Add RTC and NVRAM support plus RTAS fallbacks")
    Cc: stable@vger.kernel.org # v3.2+
    Signed-off-by: Nicholas Piggin
    Acked-by: Alexandre Belloni
    Signed-off-by: Michael Ellerman
    Signed-off-by: Greg Kroah-Hartman

    Nicholas Piggin
     

12 Apr, 2018

1 commit

  • [ Upstream commit 12a26c298d2a8b1cab498533fa65198e49e3afd3 ]

    divider_recalc_rate() is an helper function used by clock divider of
    different types, so the structure containing the 'hw' pointer is not
    always a 'struct clk_divider'

    At the following line:
    > div = _get_div(table, val, flags, divider->width);

    in several cases, the value of 'divider->width' is garbage as the actual
    structure behind this memory is not a 'struct clk_divider'

    Fortunately, this width value is used by _get_val() only when
    CLK_DIVIDER_MAX_AT_ZERO flag is set. This has never been the case so
    far when the structure is not a 'struct clk_divider'. This is probably
    why we did not notice this bug before

    Fixes: afe76c8fd030 ("clk: allow a clk divider with max divisor when zero")
    Signed-off-by: Jerome Brunet
    Acked-by: Alexandre Belloni
    Acked-by: Sylvain Lemieux
    Signed-off-by: Stephen Boyd
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Jerome Brunet
     

24 Mar, 2018

1 commit

  • [ Upstream commit 994ec64c0a193940be7a6fd074668b9446d3b6c3 ]

    The probe function is not allowed to fail after registering the RTC because
    the following may happen:

    CPU0: CPU1:
    sys_load_module()
    do_init_module()
    do_one_initcall()
    cmos_do_probe()
    rtc_device_register()
    __register_chrdev()
    cdev->owner = struct module*
    open("/dev/rtc0")
    rtc_device_unregister()
    module_put()
    free_module()
    module_free(mod->module_core)
    /* struct module *module is now
    freed */
    chrdev_open()
    spin_lock(cdev_lock)
    cdev_get()
    try_module_get()
    module_is_live()
    /* dereferences already
    freed struct module* */

    Also, the interrupt handler: ac100_rtc_irq() is dereferencing chip->rtc but
    this may still be NULL when it is called, resulting in:
    Unable to handle kernel NULL pointer dereference at virtual address 00000194
    pgd = (ptrval)
    [00000194] *pgd=00000000
    Internal error: Oops: 5 [#1] SMP ARM
    Modules linked in:
    CPU: 0 PID: 72 Comm: irq/71-ac100-rt Not tainted 4.15.0-rc1-next-20171201-dirty #120
    Hardware name: Allwinner sun8i Family
    task: (ptrval) task.stack: (ptrval)
    PC is at mutex_lock+0x14/0x3c
    LR is at ac100_rtc_irq+0x38/0xc8
    pc : [] lr : [] psr: 60000053
    sp : ee9c9f28 ip : 00000000 fp : ee9adfdc
    r10: 00000000 r9 : c0a04c48 r8 : c015ed18
    r7 : ee9bd600 r6 : ee9c9f28 r5 : ee9af590 r4 : c0a04c48
    r3 : ef3cb3c0 r2 : 00000000 r1 : ee9af590 r0 : 00000194
    Flags: nZCv IRQs on FIQs off Mode SVC_32 ISA ARM Segment none
    Control: 10c5387d Table: 4000406a DAC: 00000051
    Process irq/71-ac100-rt (pid: 72, stack limit = 0x(ptrval))
    Stack: (0xee9c9f28 to 0xee9ca000)
    9f20: 00000000 7c2fd1be c015ed18 ee9adf40 ee9c0400 ee9c0400
    9f40: ee9adf40 c015ed34 ee9c8000 ee9adf64 ee9c0400 c015f040 ee9adf80 00000000
    9f60: c015ee24 7c2fd1be ee9adfc0 ee9adf80 00000000 ee9c8000 ee9adf40 c015eef4
    9f80: ef1eba34 c0138f14 ee9c8000 ee9adf80 c0138df4 00000000 00000000 00000000
    9fa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 00000000
    9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffffffff ffffffff
    [] (mutex_lock) from [] (ac100_rtc_irq+0x38/0xc8)
    [] (ac100_rtc_irq) from [] (irq_thread_fn+0x1c/0x54)
    [] (irq_thread_fn) from [] (irq_thread+0x14c/0x214)
    [] (irq_thread) from [] (kthread+0x120/0x150)
    [] (kthread) from [] (ret_from_fork+0x14/0x2c)

    Solve both issues by moving to
    devm_rtc_allocate_device()/rtc_register_device()

    Reported-by: Quentin Schulz
    Tested-by: Quentin Schulz
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     

19 Mar, 2018

1 commit

  • [ Upstream commit f2eef045de9defbc6fc6b72b17f0941cbe26c81d ]

    brcmstb_waketmr_probe() does not disable timer->clk on error paths.

    Found by Linux Driver Verification project (linuxtesting.org).

    Fixes: c4f07ecee22e ("rtc: brcmstb-waketimer: Add Broadcom STB wake-timer")
    Signed-off-by: Alexey Khoroshilov
    Reviewed-by: Florian Fainelli
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexey Khoroshilov
     

22 Feb, 2018

1 commit

  • commit 5b8b58063029f02da573120ef4dc9079822e3cda upstream.

    According to the OPAL docs:
    skiboot-5.2.5/doc/opal-api/opal-rtc-read-3.txt
    skiboot-5.2.5/doc/opal-api/opal-rtc-write-4.txt

    OPAL_HARDWARE may be returned from OPAL_RTC_READ or OPAL_RTC_WRITE and
    this indicates either a transient or permanent error.

    Prior to this patch, Linux was not dealing with OPAL_HARDWARE being a
    permanent error particularly well, in that you could end up in a busy
    loop.

    This was not too hard to trigger on an AMI BMC based OpenPOWER machine
    doing a continuous "ipmitool mc reset cold" to the BMC, the result of
    that being that we'd get stuck in an infinite loop in
    opal_get_rtc_time().

    We now retry a few times before returning the error higher up the
    stack.

    Fixes: 16b1d26e77b1 ("rtc/tpo: Driver to support rtc and wakeup on PowerNV platform")
    Cc: stable@vger.kernel.org # v3.19+
    Signed-off-by: Stewart Smith
    Signed-off-by: Michael Ellerman
    Signed-off-by: Greg Kroah-Hartman

    Stewart Smith
     

05 Jan, 2018

5 commits

  • commit 05a03bf260e0480bfc0db91b1fdbc2115e3f193b upstream.

    m41t80_sqw_set_rate will be called with the result from
    m41t80_sqw_round_rate, so might as well make
    m41t80_sqw_set_rate(n) same as
    m41t80_sqw_set_rate(m41t80_sqw_round_rate(n))

    As Russell King wrote[1],
    "clk_round_rate() is supposed to tell you what you end up with if you
    ask clk_set_rate() to set the exact same value you passed in - but
    clk_round_rate() won't modify the hardware."

    [1]
    http://lists.infradead.org/pipermail/linux-arm-kernel/2012-January/080175.html

    Signed-off-by: Troy Kisky
    Signed-off-by: Alexandre Belloni
    Cc: Christoph Fritz
    Signed-off-by: Greg Kroah-Hartman

    Troy Kisky
     
  • commit 13bb1d78f2e372ec0d9b30489ac63768240140fc upstream.

    This is a little more efficient and avoids the warning

    WARNING: possible circular locking dependency detected
    4.14.0-rc7-00010 #16 Not tainted
    ------------------------------------------------------
    kworker/2:1/70 is trying to acquire lock:
    (prepare_lock){+.+.}, at: [] clk_prepare_lock+0x80/0xf4

    but task is already holding lock:
    (i2c_register_adapter){+.+.}, at: []
    i2c_adapter_lock_bus+0x14/0x18

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (i2c_register_adapter){+.+.}:
    rt_mutex_lock+0x44/0x5c
    i2c_adapter_lock_bus+0x14/0x18
    i2c_transfer+0xa8/0xbc
    i2c_smbus_xfer+0x20c/0x5d8
    i2c_smbus_read_byte_data+0x38/0x48
    m41t80_sqw_is_prepared+0x18/0x28

    Signed-off-by: Troy Kisky
    Signed-off-by: Alexandre Belloni
    Cc: Christoph Fritz
    Signed-off-by: Greg Kroah-Hartman

    Troy Kisky
     
  • commit 2cb90ed3de1e279dbaf23df141f54eb9fb1861e6 upstream.

    This is a little more efficient, and avoids the warning

    WARNING: possible circular locking dependency detected
    4.14.0-rc7-00007 #14 Not tainted
    ------------------------------------------------------
    alsactl/330 is trying to acquire lock:
    (prepare_lock){+.+.}, at: [] clk_prepare_lock+0x80/0xf4

    but task is already holding lock:
    (i2c_register_adapter){+.+.}, at: []
    i2c_adapter_lock_bus+0x14/0x18

    which lock already depends on the new lock.

    the existing dependency chain (in reverse order) is:

    -> #1 (i2c_register_adapter){+.+.}:
    rt_mutex_lock+0x44/0x5c
    i2c_adapter_lock_bus+0x14/0x18
    i2c_transfer+0xa8/0xbc
    i2c_smbus_xfer+0x20c/0x5d8
    i2c_smbus_read_byte_data+0x38/0x48
    m41t80_sqw_recalc_rate+0x24/0x58

    Signed-off-by: Troy Kisky
    Signed-off-by: Alexandre Belloni
    Cc: Christoph Fritz
    Signed-off-by: Greg Kroah-Hartman

    Troy Kisky
     
  • commit c8384bb04261b9d32fe7402a6068ddaf38913b23 upstream.

    Previously it was returning the best of
    32768, 8192, 1024, 64, 2, 0

    Now, best of
    32768, 8192, 4096, 2048, 1024, 512, 256, 128,
    64, 32, 16, 8, 4, 2, 1, 0

    Signed-off-by: Troy Kisky
    Signed-off-by: Alexandre Belloni
    Cc: Christoph Fritz
    Signed-off-by: Greg Kroah-Hartman

    Troy Kisky
     
  • commit de6042d2fa8afe22b76e3c68fd6e9584c9415a3b upstream.

    Previously it was returning -EINVAL upon success.

    Signed-off-by: Troy Kisky
    Signed-off-by: Alexandre Belloni
    Cc: Christoph Fritz
    Signed-off-by: Greg Kroah-Hartman

    Troy Kisky
     

25 Dec, 2017

2 commits

  • [ Upstream commit 74717b28cb32e1ad3c1042cafd76b264c8c0f68d ]

    If there is any non expired timer in the queue, the RTC alarm is never set.
    This is an issue when adding a timer that expires before the next non
    expired timer.

    Ensure the RTC alarm is set in that case.

    Fixes: 2b2f5ff00f63 ("rtc: interface: ignore expired timers when enqueuing new timers")
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Alexandre Belloni
     
  • [ Upstream commit 5b64a2965dfdfca8039e93303c64e2b15c19ff0c ]

    On some platforms, the interrupt for the PL031 is optional. Avoid
    trying to claim the interrupt if it's not specified.

    Reviewed-by: Linus Walleij
    Signed-off-by: Russell King
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Russell King