Skip to contentSkip to conversation

drivers/fsi: Free up allocated resources on fsi-master unbind

PATCH Superseded Christopher Bostic 3 participants 4 messages Mar 8, 2017 – Mar 9, 2017 FSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index bbdf6b8..751c767 100644
@@ -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
index 49f3399..3693b3d 100644
@@ -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
#1 lore raw
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.

---
  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
index bbdf6b8..751c767 100644
@@ -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
index 49f3399..3693b3d 100644

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 -0
  	return 0;
  }
#2 lore raw
In reply to Christopher Bostic
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.

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
index bbdf6b8..751c767 100644
@@ -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
index 49f3399..3693b3d 100644
@@ -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

#3 lore raw
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

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.

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
index bbdf6b8..751c767 100644
@@ -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
index 49f3399..3693b3d 100644
@@ -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