console: console: Complete exception handling in newport_probe()
Subsystems (2)
PATCH v2 1/1 console: console: Complete exception handling in newport_probe()
A call of the function ¡°do_take_over_console¡± can fail here. The corresponding system resources were not released then. Thus add a call of the function ¡°iounmap¡± together with the check of a failure predicate.
---
v1 -> v2:
- modify the commit comments by Markus'suggestion.
drivers/video/console/newport_con.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/video/console/newport_con.c +3 -0
@@ -720,6 +720,9 @@ static int newport_probe(struct gio_device *dev,console_lock (); err =do_take_over_console (&newport_con,0 ,MAX_NR_CONSOLES -1 ,1 );console_unlock (); + +if (err) +iounmap ((void *)npregs);return err; }
Signature · 1 line
2.25.0
Quoted 5 lines · Dejin Zheng
A call of the function ¡°do_take_over_console¡± can fail here. The corresponding system resources were not released then. Thus add a call of the function ¡°iounmap¡± together with the check of a failure predicate.
...
Quoted 1 line
CC Andy Shevchenko <[email protected]>
Use Cc: Better to read.
...
Quoted 2 lines
v1 -> v2:
- modify the commit comments by Markus'suggestion.
What suggestion? You need to be clear in changelog what exactly has been done without looking to any previous mail.
...
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 727
Quoted 8 lines
console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock();drivers/video/console/newport_con.c +3
-0+ +if (err) +iounmap ((void *)npregs);return err; }
I have briefly looked at the code (it is actually quite old one!), and I think this is half-baked solution, besides the fact of missed __iomem annotation and useless explicit casting.
The proper one seems to switch to memremap() and do memunmap() here.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Dejin Zheng
A call of the function
do_take_over_console()can fail here. The corresponding system resources were not released then. Thus add a call of the functioniounmap()together with the check of a failure predicate.
Quoted 6 lines
...
Quoted 1 line
CC Andy Shevchenko <[email protected]>Use Cc: Better to read.
I will pay attention to the next submission, thanks.
Quoted 8 lines
...
Quoted 2 lines
v1 -> v2:
- modify the commit comments by Markus'suggestion.What suggestion? You need to be clear in changelog what exactly has been done without looking to any previous mail.
The commit comments have some more appropriate instructions by Markus'suggestion. here is my first version commit comments:
if do_take_over_console() return an error in the newport_probe(), due to the io virtual address is not released, it will cause a leak.
Thnaks!
Quoted 19 lines
...
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 727
Quoted 8 lines
console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock();drivers/video/console/newport_con.c +3
-0+ +if (err) +iounmap ((void *)npregs);return err; }I have briefly looked at the code (it is actually quite old one!), and I think this is half-baked solution, besides the fact of missed
__iomemannotation and useless explicit casting.
The proper one seems to switch tomemremap()and domemunmap()here.Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
I believe that the patch summary line should be:
"[PATCH v2] console: newport_con: ..."
Quoted 6 lines · Dejin Zheng
A call of the function ¡°do_take_over_console¡± can fail here. The corresponding system resources were not released then. Thus add a call of the function ¡°iounmap¡± together with the check of a failure predicate.
Fixes e84de0c6190503 ("MIPS: GIO bus support for SGI IP22/28")
I cannot see how this patch fixes commit e84de0c6190503 (AFAICS npregs has also been leaked on error before)?
Quoted 14 lines
CC Andy Shevchenko <[email protected]>Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- modify the commit comments by Markus'suggestion.drivers/video/console/newport_con.c | 3 +++ 1 file changed, 3 insertions(+)drivers/video/console/newport_con.c +0
-0
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 725
Quoted 6 lines
drivers/video/console/newport_con.c +3
-0@@ -720,6 +720,9 @@ static int newport_probe(struct gio_device *dev,console_lock (); err =do_take_over_console (&newport_con,0 ,MAX_NR_CONSOLES -1 ,1 );console_unlock (); + +if (err) +iounmap ((void *)npregs);
Looks OK but while you are at it, could you please also add missing release_mem_region() on error and on device removal:
newport_addr = dev->resource.start + 0xF0000; if (!request_mem_region(newport_addr, 0x10000, "Newport")) return -ENODEV; npregs = (struct newport_regs *)/* ioremap cannot fail */ ioremap(newport_addr, sizeof(struct newport_regs)); console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock(); return err; }
static void newport_remove(struct gio_device *dev)
{
give_up_console(&newport_con);
iounmap((void *)npregs);
}?
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 728
Quoted 3 lines
drivers/video/console/newport_con.c +0
-0return err; }
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
Quoted 18 lines · Bartlomiej Zolnierkiewicz
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 725
Quoted 2 lines
drivers/video/console/newport_con.c +2
-0+if (err) +iounmap ((void *)npregs);Looks OK but while you are at it, could you please also add missing
release_mem_region()on error and on device removal:newport_addr = dev->resource.start + 0xF0000; if (!request_mem_region(newport_addr, 0x10000, "Newport")) return -ENODEV; npregs = (struct newport_regs *)/* ioremap cannot fail */ ioremap(newport_addr, sizeof(struct newport_regs)); console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock(); return err; }
Quoted 7 lines
static void
newport_remove(struct gio_device *dev){ give_up_console(&newport_con); iounmap((void *)npregs); }?
Don't you think that proper solution is rather switch to memremap()?
Quoted 2 lines
Quoted 2 lines
return err;}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 27 lines · Andy Shevchenko
Quoted 24 lines · Bartlomiej Zolnierkiewicz
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 725
Quoted 2 lines
drivers/video/console/newport_con.c +2
-0+if (err) +iounmap ((void *)npregs);Looks OK but while you are at it, could you please also add missing
release_mem_region()on error and on device removal:newport_addr = dev->resource.start + 0xF0000; if (!request_mem_region(newport_addr, 0x10000, "Newport")) return -ENODEV; npregs = (struct newport_regs *)/* ioremap cannot fail */ ioremap(newport_addr, sizeof(struct newport_regs)); console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock(); return err; }static void
newport_remove(struct gio_device *dev){ give_up_console(&newport_con); iounmap((void *)npregs); }
Quoted 3 lines
Quoted 1 line
?
Don't you think that proper solution is rather switch to
memremap()?
Doesn't seem to be a case here (used memory region in uncached).
On MIPS (this is MIPS-only driver):
...
#define ioremap(offset, size) \ __ioremap_mode((offset), (size), _CACHE_UNCACHED)
#define ioremap_uc ioremap
...
While memremap() is only for cacheable memory:
...
* memremap() - remap an iomem_resource as cacheable memory
* @offset: iomem resource start address
* @size: size of remap
* @flags: any of MEMREMAP_WB, MEMREMAP_WT, MEMREMAP_WC,
* MEMREMAP_ENC, MEMREMAP_DEC
...
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
return err;}
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
Quoted 7 lines · Bartlomiej Zolnierkiewicz
Hi,
I believe that the patch summary line should be:
"[PATCH v2] console:
newport_con: ..."
OK, thanks!
Quoted 11 lines · Dejin Zheng
Quoted 6 lines
A call of the function ¡°do_take_over_console¡± can fail here. The corresponding system resources were not released then. Thus add a call of the function ¡°iounmap¡± together with the check of a failure predicate.
Fixes e84de0c6190503 ("MIPS: GIO bus support for SGI IP22/28")I cannot see how this patch fixes commit
e84de0c6190503(AFAICS npregs has also been leaked on error before)?
yes, you are right, the commit should be e86bb8acc0fdca82d2 ("[PATCH] VT binding: Make newport_con support binding")
- move register ioremap from newport_startup() to newport_console_init()
Quoted 9 lines
Quoted 9 lines
CC Andy Shevchenko <[email protected]>Signed-off-by Dejin Zheng <[email protected]>---
v1 -> v2:
- modify the commit comments by Markus'suggestion.drivers/video/console/newport_con.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 15 lines
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 725
Quoted 11 lines
drivers/video/console/newport_con.c +3
-0@@ -720,6 +720,9 @@ static int newport_probe(struct gio_device *dev,console_lock (); err =do_take_over_console (&newport_con,0 ,MAX_NR_CONSOLES -1 ,1 );console_unlock (); + +if (err) +iounmap ((void *)npregs);Looks OK but while you are at it, could you please also add missing
release_mem_region()on error and on device removal:
Ok, Thanks, I will send the patch v3 for it.
Quoted 29 lines
newport_addr = dev->resource.start + 0xF0000; if (!request_mem_region(newport_addr, 0x10000, "Newport")) return -ENODEV; npregs = (struct newport_regs *)/* ioremap cannot fail */ ioremap(newport_addr, sizeof(struct newport_regs)); console_lock(); err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); console_unlock(); return err; }static void
newport_remove(struct gio_device *dev){ give_up_console(&newport_con); iounmap((void *)npregs); }?
drivers/video/console/newport_con.c static int newport_probe(struct gio_device *dev, · line 728
Quoted 3 lines
drivers/video/console/newport_con.c +0
-0return err; }Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics