mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	clocksource/drivers/bcm2835_timer: Fix memory leak of timer
Currently when setup_irq fails the error exit path will leak the
recently allocated timer structure.  Originally the code would
throw a panic but a later commit changed the behaviour to return
via the err_iounmap path and hence we now have a memory leak. Fix
this by adding a err_timer_free error path that kfree's timer.
Addresses-Coverity: ("Resource Leak")
Fixes: 524a7f0898 ("clocksource/drivers/bcm2835_timer: Convert init function to return error")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20191219213246.34437-1-colin.king@canonical.com
			
			
This commit is contained in:
		
							parent
							
								
									f5ac896b6a
								
							
						
					
					
						commit
						2052d032c0
					
				
					 1 changed files with 4 additions and 1 deletions
				
			
		| 
						 | 
					@ -121,7 +121,7 @@ static int __init bcm2835_timer_init(struct device_node *node)
 | 
				
			||||||
	ret = setup_irq(irq, &timer->act);
 | 
						ret = setup_irq(irq, &timer->act);
 | 
				
			||||||
	if (ret) {
 | 
						if (ret) {
 | 
				
			||||||
		pr_err("Can't set up timer IRQ\n");
 | 
							pr_err("Can't set up timer IRQ\n");
 | 
				
			||||||
		goto err_iounmap;
 | 
							goto err_timer_free;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
 | 
						clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
 | 
				
			||||||
| 
						 | 
					@ -130,6 +130,9 @@ static int __init bcm2835_timer_init(struct device_node *node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_timer_free:
 | 
				
			||||||
 | 
						kfree(timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_iounmap:
 | 
					err_iounmap:
 | 
				
			||||||
	iounmap(base);
 | 
						iounmap(base);
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue