From: Julien Grall Date: Fri, 28 Mar 2014 15:11:57 +0000 (+0000) Subject: xen/serial: Don't leak memory mapping if the serial initialization has failed X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b9f1e8292185e0806378f97e2e4210e6ca311c46;p=people%2Fliuw%2Flibxenctrl-split%2Fxen.git xen/serial: Don't leak memory mapping if the serial initialization has failed The memory mapping leaked 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 Acked-by: Ian Campbell Acked-by: Keir Fraser --- diff --git a/xen/drivers/char/exynos4210-uart.c b/xen/drivers/char/exynos4210-uart.c index 061957560c..150d49bb6a 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 c1580ef294..b29f6102d3 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 fd82511bf9..fe99af6881 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;