Skip to contentSkip to conversation

mmc: remove unnecessary module_init/exit functions

PATCH In review Ethan Nelson-Moore 4 participants 12 messages Jan 31 – Feb 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: remove unnecessary module_init/exit functions

Three MMC drivers have unnecessary module_init and module_exit functions that are empty or just print a message. Remove them. Note that if a module_init function exists, a module_exit function must also exist; otherwise, the module cannot be unloaded.

---
 drivers/mmc/host/dw_mmc.c      | 13 -------------
 drivers/mmc/host/sdhci-pltfm.c | 13 -------------
 drivers/mmc/host/sdhci-uhs2.c  | 13 +------------
 3 files changed, 1 insertion(+), 38 deletions(-)
drivers/mmc/host/dw_mmc.c +0 -13
index 9e74b675e92d..613d74d2e946 100644
@@ -3693,19 +3693,6 @@ int dw_mci_runtime_resume(struct device *dev)
 EXPORT_SYMBOL(dw_mci_runtime_resume);
 #endif /* CONFIG_PM */
 
-static int __init dw_mci_init(void)
-{
-	pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
-	return 0;
-}
-
-static void __exit dw_mci_exit(void)
-{
-}
-
-module_init(dw_mci_init);
-module_exit(dw_mci_exit);
-
 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
 MODULE_AUTHOR("NXP Semiconductor VietNam");
 MODULE_AUTHOR("Imagination Technologies Ltd");
drivers/mmc/host/sdhci-pltfm.c +0 -13
index 7f6ac636f040..d4fb60c1ef69 100644
@@ -215,19 +215,6 @@ const struct dev_pm_ops sdhci_pltfm_pmops = {
 };
 EXPORT_SYMBOL_GPL(sdhci_pltfm_pmops);
 
-static int __init sdhci_pltfm_drv_init(void)
-{
-	pr_info("sdhci-pltfm: SDHCI platform and OF driver helper\n");
-
-	return 0;
-}
-module_init(sdhci_pltfm_drv_init);
-
-static void __exit sdhci_pltfm_drv_exit(void)
-{
-}
-module_exit(sdhci_pltfm_drv_exit);
-
 MODULE_DESCRIPTION("SDHCI platform and OF driver helper");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
drivers/mmc/host/sdhci-uhs2.c +1 -12
index c459a08d01da..41e49c6cc751 100644
@@ -1126,7 +1126,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id)
 
 /*****************************************************************************\
  *                                                                           *
- * Driver init/exit                                                          *
+ * Driver init                                                               *
  *                                                                           *
 \*****************************************************************************/
 
@@ -1138,17 +1138,6 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host)
 	return 0;
 }
 
-static int __init sdhci_uhs2_mod_init(void)
-{
-	return 0;
-}
-module_init(sdhci_uhs2_mod_init);
-
-static void __exit sdhci_uhs2_mod_exit(void)
-{
-}
-module_exit(sdhci_uhs2_mod_exit);
-
 /*****************************************************************************\
  *
  * Device allocation/registration                                            *
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ethan Nelson-Moore

Three MMC drivers have unnecessary module_init and module_exit functions that are empty or just print a message. Remove them. Note that if a module_init function exists, a module_exit function must also exist; otherwise, the module cannot be unloaded.

---
  drivers/mmc/host/dw_mmc.c      | 13 -------------

Thanks for you patch. For dw_mmc,

Quoted 83 lines
  drivers/mmc/host/sdhci-pltfm.c | 13 -------------
  drivers/mmc/host/sdhci-uhs2.c  | 13 +------------
  3 files changed, 1 insertion(+), 38 deletions(-)
drivers/mmc/host/dw_mmc.c +0 -13
index 9e74b675e92d..613d74d2e946 100644
@@ -3693,19 +3693,6 @@ int dw_mci_runtime_resume(struct device *dev)
  EXPORT_SYMBOL(dw_mci_runtime_resume);
  #endif /* CONFIG_PM */
 
-static int __init dw_mci_init(void)
-{
-	pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
-	return 0;
-}
-
-static void __exit dw_mci_exit(void)
-{
-}
-
-module_init(dw_mci_init);
-module_exit(dw_mci_exit);
-
  MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
  MODULE_AUTHOR("NXP Semiconductor VietNam");
  MODULE_AUTHOR("Imagination Technologies Ltd");
drivers/mmc/host/sdhci-pltfm.c +0 -13
index 7f6ac636f040..d4fb60c1ef69 100644
@@ -215,19 +215,6 @@ const struct dev_pm_ops sdhci_pltfm_pmops = {
  };
  EXPORT_SYMBOL_GPL(sdhci_pltfm_pmops);
 
-static int __init sdhci_pltfm_drv_init(void)
-{
-	pr_info("sdhci-pltfm: SDHCI platform and OF driver helper\n");
-
-	return 0;
-}
-module_init(sdhci_pltfm_drv_init);
-
-static void __exit sdhci_pltfm_drv_exit(void)
-{
-}
-module_exit(sdhci_pltfm_drv_exit);
-
  MODULE_DESCRIPTION("SDHCI platform and OF driver helper");
  MODULE_AUTHOR("Intel Corporation");
  MODULE_LICENSE("GPL v2");
drivers/mmc/host/sdhci-uhs2.c +1 -12
index c459a08d01da..41e49c6cc751 100644
@@ -1126,7 +1126,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id)
 
  /*****************************************************************************\
   *                                                                           *
- * Driver init/exit                                                          *
+ * Driver init                                                               *
   *                                                                           *
  \*****************************************************************************/
 
@@ -1138,17 +1138,6 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host)
  	return 0;
  }
 
-static int __init sdhci_uhs2_mod_init(void)
-{
-	return 0;
-}
-module_init(sdhci_uhs2_mod_init);
-
-static void __exit sdhci_uhs2_mod_exit(void)
-{
-}
-module_exit(sdhci_uhs2_mod_exit);
-
  /*****************************************************************************\
   *
   * Device allocation/registration                                            *
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Ethan Nelson-Moore
Quoted 6 lines · Ethan Nelson-Moore

Three MMC drivers have unnecessary module_init and module_exit functions that are empty or just print a message. Remove them. Note that if a module_init function exists, a module_exit function must also exist; otherwise, the module cannot be unloaded.

Doesn't seem to apply cleanly to mmc 'next' branch:

https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/log/?h=next

Fix that and you can add:

Quoted 85 lines
---
 drivers/mmc/host/dw_mmc.c      | 13 -------------
 drivers/mmc/host/sdhci-pltfm.c | 13 -------------
 drivers/mmc/host/sdhci-uhs2.c  | 13 +------------
 3 files changed, 1 insertion(+), 38 deletions(-)
drivers/mmc/host/dw_mmc.c +0 -13
index 9e74b675e92d..613d74d2e946 100644
@@ -3693,19 +3693,6 @@ int dw_mci_runtime_resume(struct device *dev)
 EXPORT_SYMBOL(dw_mci_runtime_resume);
 #endif /* CONFIG_PM */
 
-static int __init dw_mci_init(void)
-{
-	pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
-	return 0;
-}
-
-static void __exit dw_mci_exit(void)
-{
-}
-
-module_init(dw_mci_init);
-module_exit(dw_mci_exit);
-
 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
 MODULE_AUTHOR("NXP Semiconductor VietNam");
 MODULE_AUTHOR("Imagination Technologies Ltd");
drivers/mmc/host/sdhci-pltfm.c +0 -13
index 7f6ac636f040..d4fb60c1ef69 100644
@@ -215,19 +215,6 @@ const struct dev_pm_ops sdhci_pltfm_pmops = {
 };
 EXPORT_SYMBOL_GPL(sdhci_pltfm_pmops);
 
-static int __init sdhci_pltfm_drv_init(void)
-{
-	pr_info("sdhci-pltfm: SDHCI platform and OF driver helper\n");
-
-	return 0;
-}
-module_init(sdhci_pltfm_drv_init);
-
-static void __exit sdhci_pltfm_drv_exit(void)
-{
-}
-module_exit(sdhci_pltfm_drv_exit);
-
 MODULE_DESCRIPTION("SDHCI platform and OF driver helper");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
drivers/mmc/host/sdhci-uhs2.c +1 -12
index c459a08d01da..41e49c6cc751 100644
@@ -1126,7 +1126,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id)
 
 /*****************************************************************************\
  *                                                                           *
- * Driver init/exit                                                          *
+ * Driver init                                                               *
  *                                                                           *
 \*****************************************************************************/
 
@@ -1138,17 +1138,6 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host)
 	return 0;
 }
 
-static int __init sdhci_uhs2_mod_init(void)
-{
-	return 0;
-}
-module_init(sdhci_uhs2_mod_init);
-
-static void __exit sdhci_uhs2_mod_exit(void)
-{
-}
-module_exit(sdhci_uhs2_mod_exit);
-
 /*****************************************************************************\
  *
  * Device allocation/registration                                            *
#3 lore raw
In reply to Ethan Nelson-Moore
Quoted 5 lines · Ethan Nelson-Moore

Three MMC drivers have unnecessary module_init and module_exit functions that are empty or just print a message. Remove them. Note that if a module_init function exists, a module_exit function must also exist; otherwise, the module cannot be unloaded.

The above doesn't mention that omitting the _init/exit and functions also makes the module unloadable.

I think this should be perfectly fine for these cases, assuming that we never want to unload the modules as they are pure library functions. That said, please clarify this in the commit message.

Kind regards
Uffe

Quoted 90 lines
---
 drivers/mmc/host/dw_mmc.c      | 13 -------------
 drivers/mmc/host/sdhci-pltfm.c | 13 -------------
 drivers/mmc/host/sdhci-uhs2.c  | 13 +------------
 3 files changed, 1 insertion(+), 38 deletions(-)
drivers/mmc/host/dw_mmc.c +0 -13
index 9e74b675e92d..613d74d2e946 100644
@@ -3693,19 +3693,6 @@ int dw_mci_runtime_resume(struct device *dev)
 EXPORT_SYMBOL(dw_mci_runtime_resume);
 #endif /* CONFIG_PM */
 
-static int __init dw_mci_init(void)
-{
-       pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
-       return 0;
-}
-
-static void __exit dw_mci_exit(void)
-{
-}
-
-module_init(dw_mci_init);
-module_exit(dw_mci_exit);
-
 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
 MODULE_AUTHOR("NXP Semiconductor VietNam");
 MODULE_AUTHOR("Imagination Technologies Ltd");
drivers/mmc/host/sdhci-pltfm.c +0 -13
index 7f6ac636f040..d4fb60c1ef69 100644
@@ -215,19 +215,6 @@ const struct dev_pm_ops sdhci_pltfm_pmops = {
 };
 EXPORT_SYMBOL_GPL(sdhci_pltfm_pmops);
 
-static int __init sdhci_pltfm_drv_init(void)
-{
-       pr_info("sdhci-pltfm: SDHCI platform and OF driver helper\n");
-
-       return 0;
-}
-module_init(sdhci_pltfm_drv_init);
-
-static void __exit sdhci_pltfm_drv_exit(void)
-{
-}
-module_exit(sdhci_pltfm_drv_exit);
-
 MODULE_DESCRIPTION("SDHCI platform and OF driver helper");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
drivers/mmc/host/sdhci-uhs2.c +1 -13
index c459a08d01da..41e49c6cc751 100644
@@ -1126,7 +1126,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id)
 
 /*****************************************************************************\
  *                                                                           *
- * Driver init/exit                                                          *
+ * Driver init                                                               *
  *                                                                           *
 \*****************************************************************************/
 
@@ -1138,17 +1138,6 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host)
        return 0;
 }
 
-static int __init sdhci_uhs2_mod_init(void)
-{
-       return 0;
-}
-module_init(sdhci_uhs2_mod_init);
-
-static void __exit sdhci_uhs2_mod_exit(void)
-{
-}
-module_exit(sdhci_uhs2_mod_exit);
-
 /*****************************************************************************\
  *
  * Device allocation/registration                                            *
--

2.43.0

#4 lore raw

Hi, Ulf,

Quoted 2 lines · Ulf Hansson

The above doesn't mention that omitting the _init/exit and functions also makes the module unloadable.

I can add that in the next version.

Quoted 3 lines

I think this should be perfectly fine for these cases, assuming that we never want to unload the modules as they are pure library functions. That said, please clarify this in the commit message.

My understanding is that modules can be unloaded if one of the following is true:
- They have neither init nor exit functions
- They have both, and the exit function returns zero
but that if a module has an init function but no exit function, it cannot be unloaded.
Therefore, this change would result in the modules being able to be unloaded as they are currently.
Feel free to correct me if I'm wrong.

Ethan

#5 lore raw
Quoted 1 line · Ethan Nelson-Moore

and the exit function returns zero

Ignore this part. I forgot that the exit function returns void.

Ethan

#6 lore raw
In reply to Ethan Nelson-Moore
Quoted 6 lines · Ethan Nelson-Moore

Hi, Ulf,

Quoted 2 lines · Ulf Hansson

The above doesn't mention that omitting the _init/exit and functions also makes the module unloadable.

Quoted 8 lines

I can add that in the next version.

Quoted 3 lines

I think this should be perfectly fine for these cases, assuming that we never want to unload the modules as they are pure library functions. That said, please clarify this in the commit message.

My understanding is that modules can be unloaded if one of the following is true:
- They have neither init nor exit functions

I don't think that's correct. At least this is my understanding of how this works.

Quoted 8 lines

- They have both, and the exit function returns zero
but that if a module has an init function but no exit function, it cannot be unloaded.
Therefore, this change would result in the modules being able to be unloaded as they are currently.
Feel free to correct me if I'm wrong.

Ethan

Kind regards
Uffe

#7 lore raw

Hi, Uffe,

Quoted 4 lines · Ulf Hansson
Quoted 1 line

- They have neither init nor exit functions

I don't think that's correct. At least this is my understanding of how this works.

Yes, it is correct. You can easily verify it - for example, drivers/net/mii.c has neither init nor exit functions, but you can still freely run "rmmod mii", assuming you don't have anything loaded that uses it.

Ethan

#8 lore raw
Quoted 6 lines · Ethan Nelson-Moore

Hi, Uffe,

Quoted 2 lines · Ulf Hansson
Quoted 1 line

- They have neither init nor exit functions

Quoted 7 lines
Quoted 2 lines

I don't think that's correct. At least this is my understanding of how this works.

Yes, it is correct. You can easily verify it - for example, drivers/net/mii.c has neither init nor exit functions, but you can still freely run "rmmod mii", assuming you don't have anything loaded that uses it.

That doesn't mean that module will be unloaded, as far as I understand.

If there is no exit function, the module will stick around in memory.

Kind regards
Uffe

#9 lore raw

Hi, Uffe,

Quoted 1 line · Ulf Hansson

If there is no exit function, the module will stick around in memory.

No, it won't:
➜ ~ sudo grep mii /proc/modules
(nothing)
➜ ~ sudo modprobe mii
➜ ~ sudo grep mii /proc/modules
mii 20480 0 - Live 0xffffffffc2549000
➜ ~ sudo rmmod mii
➜ ~ sudo grep 0xffffffffc2549000 /proc/modules
(nothing)
➜ ~

Ethan

#10 lore raw
Quoted 17 lines · Ethan Nelson-Moore

Hi, Uffe,

Quoted 1 line · Ulf Hansson

If there is no exit function, the module will stick around in memory.

No, it won't:
➜ ~ sudo grep mii /proc/modules
(nothing)
➜ ~ sudo modprobe mii
➜ ~ sudo grep mii /proc/modules
mii 20480 0 - Live 0xffffffffc2549000
➜ ~ sudo rmmod mii
➜ ~ sudo grep 0xffffffffc2549000 /proc/modules
(nothing)
➜ ~

Quoted 1 line

Ethan

Thanks for re-confirming! Yes, it seems like I was wrong, sorry for all the noise!

I had a look at the code for the delete_module sycall in kernel/module/main.c states, which confirms this too! If there is no init function, we don't need an exit function to allow a module to be unloaded.

That said, I will apply your patch as is, as soon as we have v7.0-rc1.

Kind regards
Uffe

#11 lore raw
In reply to Ethan Nelson-Moore
Quoted 7 lines · Ethan Nelson-Moore

Three MMC drivers have unnecessary module_init and module_exit functions that are empty or just print a message. Remove them. Note that if a module_init function exists, a module_exit function must also exist; otherwise, the module cannot be unloaded.

Applied for next, thanks!

Kind regards
Uffe

Quoted 88 lines
---
 drivers/mmc/host/dw_mmc.c      | 13 -------------
 drivers/mmc/host/sdhci-pltfm.c | 13 -------------
 drivers/mmc/host/sdhci-uhs2.c  | 13 +------------
 3 files changed, 1 insertion(+), 38 deletions(-)
drivers/mmc/host/dw_mmc.c +0 -13
index 9e74b675e92d..613d74d2e946 100644
@@ -3693,19 +3693,6 @@ int dw_mci_runtime_resume(struct device *dev)
 EXPORT_SYMBOL(dw_mci_runtime_resume);
 #endif /* CONFIG_PM */
 
-static int __init dw_mci_init(void)
-{
-       pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
-       return 0;
-}
-
-static void __exit dw_mci_exit(void)
-{
-}
-
-module_init(dw_mci_init);
-module_exit(dw_mci_exit);
-
 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
 MODULE_AUTHOR("NXP Semiconductor VietNam");
 MODULE_AUTHOR("Imagination Technologies Ltd");
drivers/mmc/host/sdhci-pltfm.c +0 -13
index 7f6ac636f040..d4fb60c1ef69 100644
@@ -215,19 +215,6 @@ const struct dev_pm_ops sdhci_pltfm_pmops = {
 };
 EXPORT_SYMBOL_GPL(sdhci_pltfm_pmops);
 
-static int __init sdhci_pltfm_drv_init(void)
-{
-       pr_info("sdhci-pltfm: SDHCI platform and OF driver helper\n");
-
-       return 0;
-}
-module_init(sdhci_pltfm_drv_init);
-
-static void __exit sdhci_pltfm_drv_exit(void)
-{
-}
-module_exit(sdhci_pltfm_drv_exit);
-
 MODULE_DESCRIPTION("SDHCI platform and OF driver helper");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_LICENSE("GPL v2");
drivers/mmc/host/sdhci-uhs2.c +1 -13
index c459a08d01da..41e49c6cc751 100644
@@ -1126,7 +1126,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id)
 
 /*****************************************************************************\
  *                                                                           *
- * Driver init/exit                                                          *
+ * Driver init                                                               *
  *                                                                           *
 \*****************************************************************************/
 
@@ -1138,17 +1138,6 @@ static int sdhci_uhs2_host_ops_init(struct sdhci_host *host)
        return 0;
 }
 
-static int __init sdhci_uhs2_mod_init(void)
-{
-       return 0;
-}
-module_init(sdhci_uhs2_mod_init);
-
-static void __exit sdhci_uhs2_mod_exit(void)
-{
-}
-module_exit(sdhci_uhs2_mod_exit);
-
 /*****************************************************************************\
  *
  * Device allocation/registration                                            *
--

2.43.0