Handle the error code returned by cyclic_register() and propagate it,
except in case the return code is EALREADY. The cyclic_register() in
mmc.c can be called multiple times with the same parameters, and that
is not an error, so depend on the cyclic_register() to skip such a
repeated registration and consider EALREADY as non-error here.

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Aaron Williams <[email protected]>
Cc: Anatolij Gustschin <[email protected]>
Cc: Angelo Dureghello <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Devarsh Thakkar <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Jaehoon Chung <[email protected]>
Cc: Michael Polyntsov <[email protected]>
Cc: Michael Trimarchi <[email protected]>
Cc: Nikhil M Jain <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Peter Robinson <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Ronald Wahl <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stefan Roese <[email protected]>
Cc: Tim Harvey <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
 drivers/mmc/mmc.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 4ea97974383..9c58d052261 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -3078,11 +3078,17 @@ int mmc_init(struct mmc *mmc)
                return err;
        }
 
-       if (CONFIG_IS_ENABLED(CYCLIC, (!mmc->cyclic.func), (NULL))) {
-               /* Register cyclic function for card detect polling */
-               cyclic_register(&mmc->cyclic, mmc_cyclic_cd_poll, 100 * 1000,
-                               mmc->cfg->name);
-       }
+       /* Register cyclic function for card detect polling */
+       err = cyclic_register(&mmc->cyclic, mmc_cyclic_cd_poll, 100 * 1000,
+                             mmc->cfg->name);
+       /*
+        * This cyclic_register() here might be called multiple times, this
+        * is not a problem in this specific case, because the mmc subsystem
+        * always registers the same function with the same polling delay,
+        * so the EALREADY error can be ignored here.
+        */
+       if (err && err == -EALREADY)
+               err = 0;
 
        return err;
 }
@@ -3091,8 +3097,7 @@ int mmc_deinit(struct mmc *mmc)
 {
        u32 caps_filtered;
 
-       if (CONFIG_IS_ENABLED(CYCLIC, (mmc->cyclic.func), (NULL)))
-               cyclic_unregister(&mmc->cyclic);
+       cyclic_unregister(&mmc->cyclic);
 
        if (!CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) &&
            !CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) &&
-- 
2.45.2

Reply via email to