• Tony Lindgren's avatar
    serial: 8250: omap: Fix imprecise external abort for omap_8250_pm() · 398cecc2
    Tony Lindgren authored
    We must idle the uart only after serial8250_unregister_port(). Otherwise
    unbinding the uart via sysfs while doing cat on the port produces an
    imprecise external abort:
    
    mem_serial_in from omap_8250_pm+0x44/0xf4
    omap_8250_pm from uart_hangup+0xe0/0x194
    uart_hangup from __tty_hangup.part.0+0x37c/0x3a8
    __tty_hangup.part.0 from uart_remove_one_port+0x9c/0x22c
    uart_remove_one_port from serial8250_unregister_port+0x60/0xe8
    serial8250_unregister_port from omap8250_remove+0x6c/0xd0
    omap8250_remove from platform_remove+0x28/0x54
    
    Turns out the driver needs to have runtime PM functional before the
    driver probe calls serial8250_register_8250_port(). And it needs
    runtime PM after driver remove calls serial8250_unregister_port().
    
    On probe, we need to read registers before registering the port in
    omap_serial_fill_features_erratas(). We do that with custom uart_read()
    already.
    
    On remove, after serial8250_unregister_port(), we need to write to the
    uart registers to idle the device. Let's add a custom uart_write() for
    that.
    
    Currently the uart register access depends on port->membase to be
    initialized, which won't work after serial8250_unregister_port().
    Let's use priv->membase instead, and use it for runtime PM related
    functions to remove the dependency to port->membase for early and
    late register access.
    
    Note that during use, we need to check for a valid port in the runtime PM
    related functions. This is needed for the optional wakeup configuration.
    We now need to set the drvdata a bit earlier so it's available for the
    runtime PM functions.
    
    With the port checks in runtime PM functions, the old checks for priv in
    omap8250_runtime_suspend() and omap8250_runtime_resume() functions are no
    longer needed and are removed.
    Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
    Link: https://lore.kernel.org/r/20230508082014.23083-3-tony@atomide.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    398cecc2
8250_omap.c 47.2 KB