linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] serial: imx: fix error handling in console_setup
@ 2018-11-14 17:49 Stefan Agner
  2018-11-14 17:49 ` [PATCH 2/3] serial: imx: unprepare console clocks on remove Stefan Agner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stefan Agner @ 2018-11-14 17:49 UTC (permalink / raw)
  To: gregkh, jslaby
  Cc: fabio.estevam, u.kleine-koenig, s.hauer, linux-serial,
	linux-kernel, Stefan Agner

The ipg clock only needs to be unprepared in case preparing
per clock fails. The ipg clock has already disabled at the point.

Fixes: 1cf93e0d5488 ("serial: imx: remove the uart_console() check")
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/tty/serial/imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 0f67197a3783..313c3b1900a8 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2068,7 +2068,7 @@ imx_uart_console_setup(struct console *co, char *options)
 
 	retval = clk_prepare(sport->clk_per);
 	if (retval)
-		clk_disable_unprepare(sport->clk_ipg);
+		clk_unprepare(sport->clk_ipg);
 
 error_console:
 	return retval;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] serial: imx: unprepare console clocks on remove
  2018-11-14 17:49 [PATCH 1/3] serial: imx: fix error handling in console_setup Stefan Agner
@ 2018-11-14 17:49 ` Stefan Agner
  2018-11-23  8:08   ` Uwe Kleine-König
  2018-11-14 17:49 ` [PATCH 3/3] serial: imx: avoid crash when un/re-binding serial console device Stefan Agner
  2018-11-23  8:03 ` [PATCH 1/3] serial: imx: fix error handling in console_setup Uwe Kleine-König
  2 siblings, 1 reply; 5+ messages in thread
From: Stefan Agner @ 2018-11-14 17:49 UTC (permalink / raw)
  To: gregkh, jslaby
  Cc: fabio.estevam, u.kleine-koenig, s.hauer, linux-serial,
	linux-kernel, Stefan Agner

Currently imx_uart_console_setup() prepares clocks which do not
get unprepared anywhere. Check whether the console has been used
by testing if index is set and unprepare clocks in this case.

This makes sure that clocks are properly unprepared after the
console device has been unbound.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
 drivers/tty/serial/imx.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 313c3b1900a8..757c91e5105a 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2085,7 +2085,7 @@ static struct console imx_uart_console = {
 	.data		= &imx_uart_uart_driver,
 };
 
-#define IMX_CONSOLE	&imx_uart_console
+#define IMX_CONSOLE	(&imx_uart_console)
 
 #ifdef CONFIG_OF
 static void imx_uart_console_early_putchar(struct uart_port *port, int ch)
@@ -2378,8 +2378,17 @@ static int imx_uart_probe(struct platform_device *pdev)
 static int imx_uart_remove(struct platform_device *pdev)
 {
 	struct imx_port *sport = platform_get_drvdata(pdev);
+	int ret;
+
+	ret = uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
+
+	if (IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE) && IMX_CONSOLE->index >= 0) {
+		clk_unprepare(sport->clk_ipg);
+		clk_unprepare(sport->clk_per);
+		IMX_CONSOLE->index = -1;
+	}
 
-	return uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
+	return ret;
 }
 
 static void imx_uart_restore_context(struct imx_port *sport)
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] serial: imx: avoid crash when un/re-binding serial console device
  2018-11-14 17:49 [PATCH 1/3] serial: imx: fix error handling in console_setup Stefan Agner
  2018-11-14 17:49 ` [PATCH 2/3] serial: imx: unprepare console clocks on remove Stefan Agner
@ 2018-11-14 17:49 ` Stefan Agner
  2018-11-23  8:03 ` [PATCH 1/3] serial: imx: fix error handling in console_setup Uwe Kleine-König
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Agner @ 2018-11-14 17:49 UTC (permalink / raw)
  To: gregkh, jslaby
  Cc: fabio.estevam, u.kleine-koenig, s.hauer, linux-serial,
	linux-kernel, Stefan Agner

If the device used as a serial console gets un/re-binded, then
register_console() will call imx_uart_setup_console() again.
Drop __init so that imx_uart_setup_console() can be safely called
at runtime.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
This addresses a kernel panic seen when unbinding/rebinding the i.MX
UART which is serial console on i.MX 6/7 via SSH:
# cd /sys/bus/platform/drivers/imx-uart/
# echo 30860000.serial > unbind && echo 30860000.serial > bind

console [ttymxc0] disabled
30860000.serial: ttymxc0 at MMIO 0x30860000 (irq = 52, base_baud = 1500000) is a IMX
Unable to handle kernel paging request at virtual address c0c4b830
pgd = 5e12e3d4
[c0c4b830] *pgd=80c1141e(bad)
Internal error: Oops: 8000000d [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 866 Comm: sh Not tainted 4.18.15-00048-gb3b505988801-dirty #403
Hardware name: Freescale i.MX7 Dual (Device Tree)
PC is at imx_uart_console_setup+0x0/0x274
LR is at register_console+0x184/0x3c4
pc : [<c0c4b830>]    lr : [<c0171314>]    psr: a0070013
sp : e8015db8  ip : c0d06548  fp : c0b4a158
r10: ec1d9380  r9 : 00000001  r8 : 00000000
r7 : 00000000  r6 : c0d819e0  r5 : c0d81e48  r4 : c0d47d68
r3 : c0c4b830  r2 : 00000000  r1 : efffca03  r0 : c0d47d68
Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: a803806a  DAC: 00000051
Process sh (pid: 866, stack limit = 0x9c2f1d49)

It seems that also other drivers are affected. An alternative might be
to disallow unbinding/rebinding instead.

 drivers/tty/serial/imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 757c91e5105a..674bd0ea2491 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1966,7 +1966,7 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
  * If the port was already initialised (eg, by a boot loader),
  * try to determine the current setup.
  */
-static void __init
+static void
 imx_uart_console_get_options(struct imx_port *sport, int *baud,
 			     int *parity, int *bits)
 {
@@ -2025,7 +2025,7 @@ imx_uart_console_get_options(struct imx_port *sport, int *baud,
 	}
 }
 
-static int __init
+static int
 imx_uart_console_setup(struct console *co, char *options)
 {
 	struct imx_port *sport;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] serial: imx: fix error handling in console_setup
  2018-11-14 17:49 [PATCH 1/3] serial: imx: fix error handling in console_setup Stefan Agner
  2018-11-14 17:49 ` [PATCH 2/3] serial: imx: unprepare console clocks on remove Stefan Agner
  2018-11-14 17:49 ` [PATCH 3/3] serial: imx: avoid crash when un/re-binding serial console device Stefan Agner
@ 2018-11-23  8:03 ` Uwe Kleine-König
  2 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2018-11-23  8:03 UTC (permalink / raw)
  To: Stefan Agner
  Cc: gregkh, jslaby, fabio.estevam, s.hauer, linux-serial, linux-kernel

On Wed, Nov 14, 2018 at 06:49:38PM +0100, Stefan Agner wrote:
> The ipg clock only needs to be unprepared in case preparing
> per clock fails. The ipg clock has already disabled at the point.
> 
> Fixes: 1cf93e0d5488 ("serial: imx: remove the uart_console() check")
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/tty/serial/imx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 0f67197a3783..313c3b1900a8 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -2068,7 +2068,7 @@ imx_uart_console_setup(struct console *co, char *options)
>  
>  	retval = clk_prepare(sport->clk_per);
>  	if (retval)
> -		clk_disable_unprepare(sport->clk_ipg);
> +		clk_unprepare(sport->clk_ipg);

good catch,

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] serial: imx: unprepare console clocks on remove
  2018-11-14 17:49 ` [PATCH 2/3] serial: imx: unprepare console clocks on remove Stefan Agner
@ 2018-11-23  8:08   ` Uwe Kleine-König
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2018-11-23  8:08 UTC (permalink / raw)
  To: Stefan Agner
  Cc: gregkh, jslaby, fabio.estevam, s.hauer, linux-serial, linux-kernel

On Wed, Nov 14, 2018 at 06:49:39PM +0100, Stefan Agner wrote:
> Currently imx_uart_console_setup() prepares clocks which do not
> get unprepared anywhere. Check whether the console has been used
> by testing if index is set and unprepare clocks in this case.
> 
> This makes sure that clocks are properly unprepared after the
> console device has been unbound.
> 
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  drivers/tty/serial/imx.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 313c3b1900a8..757c91e5105a 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -2085,7 +2085,7 @@ static struct console imx_uart_console = {
>  	.data		= &imx_uart_uart_driver,
>  };
>  
> -#define IMX_CONSOLE	&imx_uart_console
> +#define IMX_CONSOLE	(&imx_uart_console)
>  
>  #ifdef CONFIG_OF
>  static void imx_uart_console_early_putchar(struct uart_port *port, int ch)
> @@ -2378,8 +2378,17 @@ static int imx_uart_probe(struct platform_device *pdev)
>  static int imx_uart_remove(struct platform_device *pdev)
>  {
>  	struct imx_port *sport = platform_get_drvdata(pdev);
> +	int ret;
> +
> +	ret = uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
> +
> +	if (IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE) && IMX_CONSOLE->index >= 0) {
> +		clk_unprepare(sport->clk_ipg);
> +		clk_unprepare(sport->clk_per);
> +		IMX_CONSOLE->index = -1;
> +	}
>  
> -	return uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
> +	return ret;

I doubt this is right. imx_uart_console_setup is called once, and
if the console is on (say) ttymxc0 you don't want to unprepare the
clocks if ttymxc3 gets unbound.

So I think this cleanup must go into imx_uart_exit().

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-23  8:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 17:49 [PATCH 1/3] serial: imx: fix error handling in console_setup Stefan Agner
2018-11-14 17:49 ` [PATCH 2/3] serial: imx: unprepare console clocks on remove Stefan Agner
2018-11-23  8:08   ` Uwe Kleine-König
2018-11-14 17:49 ` [PATCH 3/3] serial: imx: avoid crash when un/re-binding serial console device Stefan Agner
2018-11-23  8:03 ` [PATCH 1/3] serial: imx: fix error handling in console_setup Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).