From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: [PATCH v2] xen/serial: Don't leak memory mapping if the serial initialization has failed Date: Wed, 19 Feb 2014 18:07:10 +0000 Message-ID: <1392833230-28706-1-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WGBYE-0006CH-AG for xen-devel@lists.xenproject.org; Wed, 19 Feb 2014 18:07:18 +0000 Received: by mail-ea0-f169.google.com with SMTP id h10so545609eak.0 for ; Wed, 19 Feb 2014 10:07:16 -0800 (PST) List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org The memory mapping is leaking when the serial driver failed to retrieve the IRQ. We can safely move the call to ioremap after. Also use ioremap_cache instead of ioremap_attr in some serial drivers. Signed-off-by: Julien Grall --- Ian, I have dropped your ack because the patch fundamentaly changed. Changes in v2: - s/ioremap_attr/ioremap_nocache - Move ioremap call after retrieve the IRQ --- xen/drivers/char/exynos4210-uart.c | 13 +++++++------ xen/drivers/char/omap-uart.c | 15 ++++++++------- xen/drivers/char/pl011.c | 15 +++++++-------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/xen/drivers/char/exynos4210-uart.c b/xen/drivers/char/exynos4210-uart.c index 0619575..150d49b 100644 --- a/xen/drivers/char/exynos4210-uart.c +++ b/xen/drivers/char/exynos4210-uart.c @@ -334,12 +334,6 @@ static int __init exynos4210_uart_init(struct dt_device_node *dev, return res; } - uart->regs = ioremap_nocache(addr, size); - if ( !uart->regs ) - { - early_printk("exynos4210: Unable to map the UART memory\n"); - return -ENOMEM; - } res = dt_device_get_irq(dev, 0, &uart->irq); if ( res ) { @@ -347,6 +341,13 @@ static int __init exynos4210_uart_init(struct dt_device_node *dev, return res; } + uart->regs = ioremap_nocache(addr, size); + if ( !uart->regs ) + { + early_printk("exynos4210: Unable to map the UART memory\n"); + return -ENOMEM; + } + uart->vuart.base_addr = addr; uart->vuart.size = size; uart->vuart.data_off = UTXH; diff --git a/xen/drivers/char/omap-uart.c b/xen/drivers/char/omap-uart.c index c1580ef..b29f610 100644 --- a/xen/drivers/char/omap-uart.c +++ b/xen/drivers/char/omap-uart.c @@ -326,13 +326,6 @@ static int __init omap_uart_init(struct dt_device_node *dev, return res; } - uart->regs = ioremap_attr(addr, size, PAGE_HYPERVISOR_NOCACHE); - if ( !uart->regs ) - { - early_printk("omap-uart: Unable to map the UART memory\n"); - return -ENOMEM; - } - res = dt_device_get_irq(dev, 0, &uart->irq); if ( res ) { @@ -340,6 +333,14 @@ static int __init omap_uart_init(struct dt_device_node *dev, return res; } + uart->regs = ioremap_nocache(addr, size); + if ( !uart->regs ) + { + early_printk("omap-uart: Unable to map the UART memory\n"); + return -ENOMEM; + } + + uart->vuart.base_addr = addr; uart->vuart.size = size; uart->vuart.data_off = UART_THR; diff --git a/xen/drivers/char/pl011.c b/xen/drivers/char/pl011.c index fd82511..fe99af6 100644 --- a/xen/drivers/char/pl011.c +++ b/xen/drivers/char/pl011.c @@ -248,14 +248,6 @@ static int __init pl011_uart_init(struct dt_device_node *dev, return res; } - uart->regs = ioremap_attr(addr, size, PAGE_HYPERVISOR_NOCACHE); - if ( !uart->regs ) - { - early_printk("pl011: Unable to map the UART memory\n"); - - return -ENOMEM; - } - res = dt_device_get_irq(dev, 0, &uart->irq); if ( res ) { @@ -263,6 +255,13 @@ static int __init pl011_uart_init(struct dt_device_node *dev, return res; } + uart->regs = ioremap_nocache(addr, size); + if ( !uart->regs ) + { + early_printk("pl011: Unable to map the UART memory\n"); + return -ENOMEM; + } + uart->vuart.base_addr = addr; uart->vuart.size = size; uart->vuart.data_off = DR; -- 1.7.10.4