From e242125d71cf543b3c80dfa64b62d0d53678d18a Mon Sep 17 00:00:00 2001
From: Sungbo Eo <mans0n@gorani.run>
Date: Fri, 6 Dec 2019 23:25:48 +0900
Subject: [PATCH] kernel: fix *-gpio-custom module unloading

Unloading and reloading the modules fails, as platform_device_put() does not
release resources fully.

root@OpenWrt:/# insmod i2c-gpio-custom bus0=0,18,0,5
[  196.860620] Custom GPIO-based I2C driver version 0.1.1
[  196.871162] ------------[ cut here ]------------
[  196.880517] WARNING: CPU: 0 PID: 1365 at fs/sysfs/dir.c:31 0x80112158
[  196.893431] sysfs: cannot create duplicate filename '/devices/platform/i2c-gpio.0'
...
[  197.513200] kobject_add_internal failed for i2c-gpio.0 with -EEXIST, don't try to register things with the same name in the same directory.

This patch fixes it by replacing platform_device_put() to
platform_device_unregister().

Fixes: da7740853715 ("i2c-gpio-custom: minor bugfix")
Fixes: 3bc81edc70e8 ("package: fix w1-gpio-custom package (closes #6770)")

Signed-off-by: Sungbo Eo <mans0n@gorani.run>
(cherry picked from commit a22b7a60d98836343c4f7b9ec0fcae68d9131522)
---
 package/kernel/i2c-gpio-custom/Makefile              | 2 +-
 package/kernel/i2c-gpio-custom/src/i2c-gpio-custom.c | 4 ++--
 package/kernel/w1-gpio-custom/Makefile               | 2 +-
 package/kernel/w1-gpio-custom/src/w1-gpio-custom.c   | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/package/kernel/i2c-gpio-custom/Makefile b/package/kernel/i2c-gpio-custom/Makefile
index d1123cc3fb..b075712bbb 100644
--- a/package/kernel/i2c-gpio-custom/Makefile
+++ b/package/kernel/i2c-gpio-custom/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=i2c-gpio-custom
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 include $(INCLUDE_DIR)/package.mk
 
diff --git a/package/kernel/i2c-gpio-custom/src/i2c-gpio-custom.c b/package/kernel/i2c-gpio-custom/src/i2c-gpio-custom.c
index 921d290d52..dd5a68165c 100644
--- a/package/kernel/i2c-gpio-custom/src/i2c-gpio-custom.c
+++ b/package/kernel/i2c-gpio-custom/src/i2c-gpio-custom.c
@@ -51,7 +51,7 @@
 
 #define DRV_NAME	"i2c-gpio-custom"
 #define DRV_DESC	"Custom GPIO-based I2C driver"
-#define DRV_VERSION	"0.1.1"
+#define DRV_VERSION	"0.1.2"
 
 #define PFX		DRV_NAME ": "
 
@@ -96,7 +96,7 @@ static void i2c_gpio_custom_cleanup(void)
 
 	for (i = 0; i < nr_devices; i++)
 		if (devices[i])
-			platform_device_put(devices[i]);
+			platform_device_unregister(devices[i]);
 }
 
 static int __init i2c_gpio_custom_add_one(unsigned int id, unsigned int *params)
diff --git a/package/kernel/w1-gpio-custom/Makefile b/package/kernel/w1-gpio-custom/Makefile
index 1008cf9736..787f5aa02d 100644
--- a/package/kernel/w1-gpio-custom/Makefile
+++ b/package/kernel/w1-gpio-custom/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=w1-gpio-custom
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 include $(INCLUDE_DIR)/package.mk
 
diff --git a/package/kernel/w1-gpio-custom/src/w1-gpio-custom.c b/package/kernel/w1-gpio-custom/src/w1-gpio-custom.c
index 004c9240ba..6928769975 100644
--- a/package/kernel/w1-gpio-custom/src/w1-gpio-custom.c
+++ b/package/kernel/w1-gpio-custom/src/w1-gpio-custom.c
@@ -47,7 +47,7 @@
 
 #define DRV_NAME	"w1-gpio-custom"
 #define DRV_DESC	"Custom GPIO-based W1 driver"
-#define DRV_VERSION	"0.1.1"
+#define DRV_VERSION	"0.1.2"
 
 #define PFX		DRV_NAME ": "
 
@@ -86,7 +86,7 @@ static void w1_gpio_custom_cleanup(void)
 
 	for (i = 0; i < nr_devices; i++)
 		if (devices[i])
-			platform_device_put(devices[i]);
+			platform_device_unregister(devices[i]);
 }
 
 static int __init w1_gpio_custom_add_one(unsigned int id, unsigned int *params)
-- 
2.30.2