drivers/fsi: Free up allocated resources on fsi-master unbind
PATCH 1/1 drivers/fsi: Free up allocated resources on fsi-master unbind
In order to allow repeated bind/unbind operations on fsi-master the resources allocated during bind must be freed. Specifically the scan file and dynamic memory. Also check for valid pointers during unregister which is the path taken during unbind.
--- drivers/fsi/fsi-core.c | 8 ++++---- drivers/fsi/fsi-master-gpio.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/fsi/fsi-core.c +4 -4
@@ -869,11 +869,11 @@ EXPORT_SYMBOL_GPL(fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { -if (master->idx >=0 ) { -ida_simple_remove (&master_ida, master->idx); - master->idx =-1 ; - } +if (!master || !master->dev || master->idx <0 ) +return ; +ida_simple_remove (&master_ida, master->idx); + master->idx =-1 ;device_remove_file (master->dev, &dev_attr_fsi_ipoll_period);fsi_master_unscan (master);put_device (master->dev);
drivers/fsi/fsi-master-gpio.c +2 -0
@@ -566,6 +566,8 @@ static int fsi_master_gpio_remove(struct platform_device *pdev)if (master->gpio_mux)devm_gpiod_put (&pdev->dev, master->gpio_mux);fsi_master_unregister (&master->master); +device_remove_file (&pdev->dev, &dev_attr_scan); +devm_kfree (&pdev->dev, master);return 0 ; }
Signature · 1 line
1.8.2.2
Quoted 36 lines · Christopher Bostic
In order to allow repeated bind/unbind operations on fsi-master the resources allocated during bind must be freed. Specifically the scan file and dynamic memory. Also check for valid pointers during unregister which is the path taken during unbind.
Signed-off-by Christopher Bostic <[email protected]>--- drivers/fsi/fsi-core.c | 8 ++++---- drivers/fsi/fsi-master-gpio.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)drivers/fsi/fsi-core.c +4
-4@@ -869,11 +869,11 @@ EXPORT_SYMBOL_GPL(fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { -if (master->idx >=0 ) { -ida_simple_remove (&master_ida, master->idx); - master->idx =-1 ; - } +if (!master || !master->dev || master->idx <0 ) +return ; +ida_simple_remove (&master_ida, master->idx); + master->idx =-1 ;device_remove_file (master->dev, &dev_attr_fsi_ipoll_period);fsi_master_unscan (master);put_device (master->dev);drivers/fsi/fsi-master-gpio.c +0
-0
drivers/fsi/fsi-master-gpio.c static int fsi_master_gpio_remove(struct platform_device *pdev) · line 570
Quoted 5 lines
drivers/fsi/fsi-master-gpio.c +2
-0@@ -566,6 +566,8 @@ static int fsi_master_gpio_remove(struct platform_device *pdev)if (master->gpio_mux)devm_gpiod_put (&pdev->dev, master->gpio_mux);fsi_master_unregister (&master->master); +device_remove_file (&pdev->dev, &dev_attr_scan); +devm_kfree (&pdev->dev, master);
I think this devm_kfree call is unnecessary. Since this is in remove(), it should get freed automatically when the device is freed by the kernel.
Thanks,
Eddie
Quoted 3 lines
drivers/fsi/fsi-master-gpio.c +0
-0return 0 ; }
Quoted 6 lines · Christopher Bostic
In order to allow repeated bind/unbind operations on fsi-master the resources allocated during bind must be freed. Specifically the scan file and dynamic memory. Also check for valid pointers during unregister which is the path taken during unbind.
Signed-off-by Christopher Bostic <[email protected]>
This patch does not apply to dev-4.7. Can you please rebase it?
a4a89c237856e2ee3b00db7cd5febf075b695760 is the tip of dev-4.7 at the moment.
Quoted 41 lines
--- drivers/fsi/fsi-core.c | 8 ++++---- drivers/fsi/fsi-master-gpio.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)drivers/fsi/fsi-core.c +4
-4@@ -869,11 +869,11 @@ EXPORT_SYMBOL_GPL(fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { -if (master->idx >=0 ) { -ida_simple_remove (&master_ida, master->idx); - master->idx =-1 ; - } +if (!master || !master->dev || master->idx <0 ) +return ; +ida_simple_remove (&master_ida, master->idx); + master->idx =-1 ;device_remove_file (master->dev, &dev_attr_fsi_ipoll_period);fsi_master_unscan (master);put_device (master->dev);drivers/fsi/fsi-master-gpio.c +2
-1@@ -566,6 +566,8 @@ static int fsi_master_gpio_remove(struct platform_device *pdev)if (master->gpio_mux)devm_gpiod_put (&pdev->dev, master->gpio_mux);fsi_master_unregister (&master->master); +device_remove_file (&pdev->dev, &dev_attr_scan); +devm_kfree (&pdev->dev, master);return 0 ; } --1.8.2.2
Quoted 7 lines · Joel Stanley
Quoted 5 lines · Christopher Bostic
In order to allow repeated bind/unbind operations on fsi-master the resources allocated during bind must be freed. Specifically the scan file and dynamic memory. Also check for valid pointers during unregister which is the path taken during unbind.
Quoted 5 lines
Quoted 1 line
Signed-off-by Christopher Bostic <[email protected]>This patch does not apply to dev-4.7. Can you please rebase it?
a4a89c237856e2ee3b00db7cd5febf075b695760is the tip of dev-4.7 at the moment.
That should read e97a91f178e55719b08d48af7f592b18cfd4da91.
Quoted 42 lines
Quoted 42 lines
--- drivers/fsi/fsi-core.c | 8 ++++---- drivers/fsi/fsi-master-gpio.c | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)drivers/fsi/fsi-core.c +4
-4@@ -869,11 +869,11 @@ EXPORT_SYMBOL_GPL(fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { -if (master->idx >=0 ) { -ida_simple_remove (&master_ida, master->idx); - master->idx =-1 ; - } +if (!master || !master->dev || master->idx <0 ) +return ; +ida_simple_remove (&master_ida, master->idx); + master->idx =-1 ;device_remove_file (master->dev, &dev_attr_fsi_ipoll_period);fsi_master_unscan (master);put_device (master->dev);drivers/fsi/fsi-master-gpio.c +2
-1@@ -566,6 +566,8 @@ static int fsi_master_gpio_remove(struct platform_device *pdev)if (master->gpio_mux)devm_gpiod_put (&pdev->dev, master->gpio_mux);fsi_master_unregister (&master->master); +device_remove_file (&pdev->dev, &dev_attr_scan); +devm_kfree (&pdev->dev, master);return 0 ; } --1.8.2.2