[PATCH 6/8] mmc: Handle return value from cyclic_register()

Marek Vasut marek.vasut+renesas at mailbox.org
Sat Jan 18 05:01:00 CET 2025


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 <marek.vasut+renesas at mailbox.org>
---
Cc: Aaron Williams <awilliams at marvell.com>
Cc: Anatolij Gustschin <agust at denx.de>
Cc: Angelo Dureghello <angelo at kernel-space.org>
Cc: Christian Marangi <ansuelsmth at gmail.com>
Cc: Devarsh Thakkar <devarsht at ti.com>
Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
Cc: Jaehoon Chung <jh80.chung at samsung.com>
Cc: Michael Polyntsov <michael.polyntsov at iopsys.eu>
Cc: Michael Trimarchi <michael at amarulasolutions.com>
Cc: Nikhil M Jain <n-jain1 at ti.com>
Cc: Peng Fan <peng.fan at nxp.com>
Cc: Peter Robinson <pbrobinson at gmail.com>
Cc: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
Cc: Ronald Wahl <ronald.wahl at legrand.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Stefan Roese <sr at denx.de>
Cc: Tim Harvey <tharvey at gateworks.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: u-boot at lists.denx.de
---
 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



More information about the U-Boot mailing list