Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: mmp: Fix failure to remove sram device

Make sure in .probe() to set driver data before the function is left to
make it possible in .remove() to undo the actions done.

This fixes a potential memory leak and stops returning an error code in
.remove() that is ignored by the driver core anyhow.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Uwe Kleine-König and committed by
Arnd Bergmann
4036b29a 022e5220

+12 -10
+12 -10
arch/arm/mach-mmp/sram.c
··· 72 72 if (!info) 73 73 return -ENOMEM; 74 74 75 + platform_set_drvdata(pdev, info); 76 + 75 77 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 76 78 if (res == NULL) { 77 79 dev_err(&pdev->dev, "no memory resource defined\n"); ··· 109 107 list_add(&info->node, &sram_bank_list); 110 108 mutex_unlock(&sram_lock); 111 109 112 - platform_set_drvdata(pdev, info); 113 - 114 110 dev_info(&pdev->dev, "initialized\n"); 115 111 return 0; 116 112 ··· 127 127 struct sram_bank_info *info; 128 128 129 129 info = platform_get_drvdata(pdev); 130 - if (info == NULL) 131 - return -ENODEV; 132 130 133 - mutex_lock(&sram_lock); 134 - list_del(&info->node); 135 - mutex_unlock(&sram_lock); 131 + if (info->sram_size) { 132 + mutex_lock(&sram_lock); 133 + list_del(&info->node); 134 + mutex_unlock(&sram_lock); 136 135 137 - gen_pool_destroy(info->gpool); 138 - iounmap(info->sram_virt); 139 - kfree(info->pool_name); 136 + gen_pool_destroy(info->gpool); 137 + iounmap(info->sram_virt); 138 + kfree(info->pool_name); 139 + } 140 + 140 141 kfree(info); 142 + 141 143 return 0; 142 144 } 143 145