Skip to contentSkip to conversation

extcon: driver model release call not needed

PATCH In review anish kumar 3 participants 7 messages Oct 18, 2012 – Oct 22, 2012 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extcon: driver model release call not needed

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +1 -3
index 946a318..cf30eb1 100644
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }
 
 static const char *muex_name = "mutually_exclusive";
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 16 lines · anish kumar

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +0 -0
index 946a318..cf30eb1 100644

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 591

Quoted 10 lines
drivers/extcon/extcon-class.c +1 -3
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }
 
 static const char *muex_name = "mutually_exclusive";

I can't agree this patch. The extcon_dev_release() function is used for dev->release. If some case without calling extcon_dev_unregister(), I think dev->release function is needed to free memory of edev->dev.

The edev->dev->release store the function pointer of extcon_dev_release() in extcon_dev_register().
edev->dev->parent = dev;
edev->dev->class = extcon_class;
edev->dev->release = extcon_dev_release;

Thanks,
Chanwoo Choi

#2 lore raw
Quoted 26 lines · Chanwoo Choi
Quoted 25 lines · anish kumar

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +1 -3
index 946a318..cf30eb1 100644
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }
 
Quoted 5 lines

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 591

Quoted 1 line
drivers/extcon/extcon-class.c +0 -0
 static const char *muex_name = "mutually_exclusive";

I can't agree this patch. The extcon_dev_release() function is used for dev->release. If some case without calling extcon_dev_unregister(), I think dev->release function is needed to free memory of edev->dev.

Is it not being released by extcon_dev_unregister?
I think it is released by that and we will do two times free and list_del(&edev->entry) as it is called by extcon_dev_release also.

Quoted 10 lines

The edev->dev->release store the function pointer of extcon_dev_release() in extcon_dev_register().
edev->dev->parent = dev;
edev->dev->class = extcon_class;
edev->dev->release = extcon_dev_release;

Thanks,
Chanwoo Choi

maintainer
#3 lore raw
Quoted 27 lines · anish kumar
Quoted 26 lines · Chanwoo Choi
Quoted 25 lines · anish kumar

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +1 -3
index 946a318..cf30eb1 100644
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }
 
Quoted 8 lines
Quoted 5 lines

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 591

Quoted 1 line
drivers/extcon/extcon-class.c +0 -0
 static const char *muex_name = "mutually_exclusive";

I can't agree this patch. The extcon_dev_release() function is used for dev->release. If some case without calling extcon_dev_unregister(), I think dev->release function is needed to free memory of edev->dev.

Is it not being released by extcon_dev_unregister?
I think it is released by that and we will do two times free and list_del(&edev->entry) as it is called by extcon_dev_release also.

I think that this patch should modify it as below patch to remove two call of kfree(). How about you?

drivers/extcon/extcon-class.c +2 -3
index e717bbc..efca0b4 100644
@@ -597,9 +597,8 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 #endif
                device_unregister(edev->dev);
                put_device(edev->dev);
-       }
-
-       kfree(edev->dev);
+       } else {
+               kfree(edev->dev);
 
#4 lore raw
Quoted 45 lines · Chanwoo Choi
Quoted 27 lines · anish kumar
Quoted 26 lines · Chanwoo Choi
Quoted 25 lines · anish kumar

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +1 -3
index 946a318..cf30eb1 100644
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }
 
Quoted 8 lines
Quoted 5 lines

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 591

Quoted 1 line
drivers/extcon/extcon-class.c +0 -0
 static const char *muex_name = "mutually_exclusive";

I can't agree this patch. The extcon_dev_release() function is used for dev->release. If some case without calling extcon_dev_unregister(), I think dev->release function is needed to free memory of edev->dev.

Is it not being released by extcon_dev_unregister?
I think it is released by that and we will do two times free and list_del(&edev->entry) as it is called by extcon_dev_release also.

I think that this patch should modify it as below patch to remove two call of kfree(). How about you?

drivers/extcon/extcon-class.c +0 -0
index e717bbc..efca0b4 100644

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 601

Quoted 8 lines
drivers/extcon/extcon-class.c +2 -3
@@ -597,9 +597,8 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 #endif
                device_unregister(edev->dev);
                put_device(edev->dev);
-       }
-
-       kfree(edev->dev);
+       } else {
+               kfree(edev->dev)

How about below?

(quoted diff) +0 -0

b/drivers/extcon/extcon-class.c
index 946a318..62e4ecb 100644

drivers/extcon/extcon-class.c +0 -13
@@ -551,43 +551,9 @@ static int create_extcon_class(void)
        return 0;
 }
 
-static void extcon_cleanup(struct extcon_dev *edev, bool skip)
-{
-       mutex_lock(&extcon_dev_list_lock);
-       list_del(&edev->entry);
-       mutex_unlock(&extcon_dev_list_lock);
-
-       if (!skip && get_device(edev->dev)) {
-               int index;
-
-               if (edev->mutually_exclusive && edev->max_supported) {
-                       for (index = 0; edev->mutually_exclusive[index];
-                            index++)
-

kfree(edev->d_attrs_muex[index].attr.name);
- kfree(edev->d_attrs_muex);
- kfree(edev->attrs_muex);
- }
-
- for (index = 0; index < edev->max_supported; index++)
- kfree(edev->cables[index].attr_g.name);
-
- if (edev->max_supported) {
- kfree(edev->extcon_dev_type.groups);
- kfree(edev->cables);
- }
-
- device_unregister(edev->dev);
- put_device(edev->dev);
- }
-
- kfree(edev->dev);
-}
-
static void extcon_dev_release(struct device *dev) {
- struct extcon_dev *edev = (struct extcon_dev *)
dev_get_drvdata(dev);
-
- extcon_cleanup(edev, true);
+ kfree(edev->dev);
}

static const char *muex_name = "mutually_exclusive";
@@ -813,7 +779,32 @@ EXPORT_SYMBOL_GPL(extcon_dev_register);
*/
void extcon_dev_unregister(struct extcon_dev *edev) {

-       extcon_cleanup(edev, false);
+       mutex_lock(&extcon_dev_list_lock);
+       list_del(&edev->entry);
+       mutex_unlock(&extcon_dev_list_lock);

+
+ if (!skip && get_device(edev->dev)) {
+ int index;
+
+ if (edev->mutually_exclusive && edev->max_supported) {
+ for (index = 0; edev->mutually_exclusive[index];
+ index++)
+
kfree(edev->d_attrs_muex[index].attr.name);
+ kfree(edev->d_attrs_muex);
+ kfree(edev->attrs_muex);
+ }
+
+ for (index = 0; index < edev->max_supported; index++)
+ kfree(edev->cables[index].attr_g.name);
+
+ if (edev->max_supported) {
+ kfree(edev->extcon_dev_type.groups);
+ kfree(edev->cables);
+ }
+
+ device_unregister(edev->dev);
+ put_device(edev->dev);
+ }
}
EXPORT_SYMBOL_GPL(extcon_dev_unregister);

Quoted 1 line
maintainer
#5 lore raw

On 10/20/2012 12:33 PM, anish kumar wrote:
[....]

Quoted 1 line

How about below?

I agree, but there were some minor issues,

[....]

Review EXPORT_SYMBOL_GPL(extcon_dev_register); · line 786

Quoted 12 lines

static const char *muex_name = "mutually_exclusive";

(quoted diff) +5 -1
@@ -813,7 +779,32 @@ EXPORT_SYMBOL_GPL(extcon_dev_register);
  */
 void extcon_dev_unregister(struct extcon_dev *edev)
 {
-       extcon_cleanup(edev, false);
+       mutex_lock(&extcon_dev_list_lock);
+       list_del(&edev->entry);
+       mutex_unlock(&extcon_dev_list_lock);
+
+       if (!skip && get_device(edev->dev)) {

'skip' variable isn't anymore used and fix indentation as below code

[...]

-----

drivers/extcon/extcon-class.c +32 -40
index e717bbc..ec7cc84 100644
@@ -566,47 +566,9 @@ static int create_extcon_class(void)
        return 0;
 }
 
-static void extcon_cleanup(struct extcon_dev *edev, bool skip)
-{
-       mutex_lock(&extcon_dev_list_lock);
-       list_del(&edev->entry);
-       mutex_unlock(&extcon_dev_list_lock);
-
-       if (!skip && get_device(edev->dev)) {
-               int index;
-
-               if (edev->mutually_exclusive && edev->max_supported) {
-                       for (index = 0; edev->mutually_exclusive[index];
-                            index++)
-                               kfree(edev->d_attrs_muex[index].attr.name);
-                       kfree(edev->d_attrs_muex);
-                       kfree(edev->attrs_muex);
-               }
-
-               for (index = 0; index < edev->max_supported; index++)
-                       kfree(edev->cables[index].attr_g.name);
-
-               if (edev->max_supported) {
-                       kfree(edev->extcon_dev_type.groups);
-                       kfree(edev->cables);
-               }
-
-#if defined(CONFIG_ANDROID)
-               if (switch_class)
-                       class_compat_remove_link(switch_class, edev->dev, NULL);
-#endif
-               device_unregister(edev->dev);
-               put_device(edev->dev);
-       }
-
-       kfree(edev->dev);
-}
-
 static void extcon_dev_release(struct device *dev)
 {
-       struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-       extcon_cleanup(edev, true);
+       kfree(edev->dev);
 }
 
 static const char *muex_name = "mutually_exclusive";
@@ -832,7 +794,37 @@ EXPORT_SYMBOL_GPL(extcon_dev_register);
  */
 void extcon_dev_unregister(struct extcon_dev *edev)
 {
-       extcon_cleanup(edev, false);
+       int index;
+
+       mutex_lock(&extcon_dev_list_lock);
+       list_del(&edev->entry);
+       mutex_unlock(&extcon_dev_list_lock);
+
+       if (!get_device(edev->dev))
+               return;
+
+       if (edev->mutually_exclusive && edev->max_supported) {
+               for (index = 0; edev->mutually_exclusive[index];
+                    index++)
+                       kfree(edev->d_attrs_muex[index].attr.name);
+               kfree(edev->d_attrs_muex);
+               kfree(edev->attrs_muex);
+       }
+
+       for (index = 0; index < edev->max_supported; index++)
+               kfree(edev->cables[index].attr_g.name);
+
+       if (edev->max_supported) {
+               kfree(edev->extcon_dev_type.groups);
+               kfree(edev->cables);
+       }
+
+#if defined(CONFIG_ANDROID)
+       if (switch_class)
+               class_compat_remove_link(switch_class, edev->dev, NULL);
+#endif
+       device_unregister(edev->dev);
+       put_device(edev->dev);
 }
 EXPORT_SYMBOL_GPL(extcon_dev_unregister);
 

Thanks,
Chanwoo Choi

#6 lore raw
In reply to anish kumar
Quoted 16 lines · anish kumar

From: anish kumar <[email protected]>

We don't need a release call in this file as we are doing everything needed in unregister call and we don't have any more pointer to free up.

---
 drivers/extcon/extcon-class.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/extcon/extcon-class.c +0 -0
index 946a318..cf30eb1 100644

drivers/extcon/extcon-class.c static void extcon_cleanup(struct extcon_dev *edev, bool skip) · line 589

Quoted 8 lines
drivers/extcon/extcon-class.c +1 -3
@@ -585,9 +585,7 @@ static void extcon_cleanup(struct extcon_dev *edev, bool skip)
 
 static void extcon_dev_release(struct device *dev)
 {
-	struct extcon_dev *edev = (struct extcon_dev *) dev_get_drvdata(dev);
-
-	extcon_cleanup(edev, true);
+	/* We don't have any thing to free here */
 }

In the future (I know you fixed this up), doing an empty release() function will get you in big trouble. Please read the kobject documentation for more information about why this is.

greg k-h