Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755140AbYAXMmc (ORCPT ); Thu, 24 Jan 2008 07:42:32 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753632AbYAXMmE (ORCPT ); Thu, 24 Jan 2008 07:42:04 -0500 Received: from nat-132.atmel.no ([80.232.32.132]:54820 "EHLO relay.atmel.no" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753165AbYAXMmB (ORCPT ); Thu, 24 Jan 2008 07:42:01 -0500 From: Haavard Skinnemoen To: Andrew Morton Cc: Andrew Victor , Remy Bohmer , Chip Coldwell , Marc Pignat , David Brownell , linux-kernel@vger.kernel.org, Alan Cox , Haavard Skinnemoen Subject: [PATCH -mm v4 5/9] atmel_serial: Fix bugs in probe() error path and remove() Date: Thu, 24 Jan 2008 13:41:47 +0100 Message-Id: <1201178511-12133-6-git-send-email-hskinnemoen@atmel.com> X-Mailer: git-send-email 1.5.3.8 In-Reply-To: <1201178511-12133-5-git-send-email-hskinnemoen@atmel.com> References: <1201178511-12133-1-git-send-email-hskinnemoen@atmel.com> <1201178511-12133-2-git-send-email-hskinnemoen@atmel.com> <1201178511-12133-3-git-send-email-hskinnemoen@atmel.com> <1201178511-12133-4-git-send-email-hskinnemoen@atmel.com> <1201178511-12133-5-git-send-email-hskinnemoen@atmel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2400 Lines: 88 When an error happens in probe(), the clocks should be disabled, but only if the port isn't already used as a console. In remove(), the port struct shouldn't be freed because it's defined statically. Signed-off-by: Haavard Skinnemoen --- drivers/serial/atmel_serial.c | 39 +++++++++++++++++++++++++++++---------- 1 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c index 746aea0..0e715f4 100644 --- a/drivers/serial/atmel_serial.c +++ b/drivers/serial/atmel_serial.c @@ -935,8 +935,18 @@ static int __init atmel_late_console_init(void) core_initcall(atmel_late_console_init); +static inline bool atmel_is_console_port(struct uart_port *port) +{ + return port->cons && port->cons->index == port->line; +} + #else #define ATMEL_CONSOLE_DEVICE NULL + +static inline bool atmel_is_console_port(struct uart_port *port) +{ + return false; +} #endif static struct uart_driver atmel_uart = { @@ -994,9 +1004,19 @@ static int __devinit atmel_serial_probe(struct platform_device *pdev) atmel_init_port(port, pdev); ret = uart_add_one_port(&atmel_uart, &port->uart); - if (!ret) { - device_init_wakeup(&pdev->dev, 1); - platform_set_drvdata(pdev, port); + if (ret) + goto err_add_port; + + device_init_wakeup(&pdev->dev, 1); + platform_set_drvdata(pdev, port); + + return 0; + +err_add_port: + if (!atmel_is_console_port(&port->uart)) { + clk_disable(port->clk); + clk_put(port->clk); + port->clk = NULL; } return ret; @@ -1008,16 +1028,15 @@ static int __devexit atmel_serial_remove(struct platform_device *pdev) struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port; int ret = 0; - clk_disable(atmel_port->clk); - clk_put(atmel_port->clk); - device_init_wakeup(&pdev->dev, 0); platform_set_drvdata(pdev, NULL); - if (port) { - ret = uart_remove_one_port(&atmel_uart, port); - kfree(port); - } + ret = uart_remove_one_port(&atmel_uart, port); + + /* "port" is allocated statically, so we shouldn't free it */ + + clk_disable(atmel_port->clk); + clk_put(atmel_port->clk); return ret; } -- 1.5.3.8 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/