[PATCH 32/32] ALSA: Drop unused snd_card_free_on_error()
From: Takashi Iwai
Date: Thu Oct 01 2026 - 07:11:52 EST
Now that all users of snd_card_free_on_error() are gone by refactoring
with auto-cleanup, let's drop the superfluous function.
Also, update the documentation for reflecting the recommended error
handling procedure, too.
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
include/sound/core.h | 1 -
sound/core/init.c | 36 +++++++-----------------------------
2 files changed, 7 insertions(+), 30 deletions(-)
diff --git a/include/sound/core.h b/include/sound/core.h
index 2ca24ac7e37f..dc356e1ff47a 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -314,7 +314,6 @@ void snd_card_disconnect(struct snd_card *card);
void snd_card_disconnect_sync(struct snd_card *card);
void snd_card_free(struct snd_card *card);
void snd_card_free_when_closed(struct snd_card *card);
-int snd_card_free_on_error(struct device *dev, int ret);
void snd_card_set_id(struct snd_card *card, const char *id);
int snd_card_register(struct snd_card *card);
int snd_card_info_init(void);
diff --git a/sound/core/init.c b/sound/core/init.c
index a51b71812fd9..0897b3a11617 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -216,11 +216,13 @@ static void __snd_card_release(struct device *dev, void *data)
* is added automatically. In that way, the resource disconnection is assured
* at first, then released in the expected order.
*
- * If an error happens at the probe before snd_card_register() is called and
- * there have been other devres resources, you'd need to free the card manually
- * via snd_card_free() call in the error; otherwise it may lead to UAF due to
- * devres call orders. You can use snd_card_free_on_error() helper for
- * handling it more easily.
+ * Caveat: if an error happens at the probe before snd_card_register() is
+ * called and there have been other devres resources that are referred at the
+ * card-level destructor call, you'd still need to free the card manually;
+ * otherwise it may lead to UAF due to devres call orders. Instead of a manual
+ * snd_card_free() call, you can use the automatic clean-up for the card
+ * pointer via __free(snd_card_unref), and clear it upon the successful return,
+ * too; the snd_card_unref() would work just like snd_card_free() in this case.
*
* Return: zero if successful, or a negative error code
*/
@@ -250,30 +252,6 @@ int snd_devm_card_new(struct device *parent, int idx, const char *xid,
}
EXPORT_SYMBOL_GPL(snd_devm_card_new);
-/**
- * snd_card_free_on_error - a small helper for handling devm probe errors
- * @dev: the managed device object
- * @ret: the return code from the probe callback
- *
- * This function handles the explicit snd_card_free() call at the error from
- * the probe callback. It's just a small helper for simplifying the error
- * handling with the managed devices.
- *
- * Return: zero if successful, or a negative error code
- */
-int snd_card_free_on_error(struct device *dev, int ret)
-{
- struct snd_card *card;
-
- if (!ret)
- return 0;
- card = devres_find(dev, __snd_card_release, NULL, NULL);
- if (card)
- snd_card_free(card);
- return ret;
-}
-EXPORT_SYMBOL_GPL(snd_card_free_on_error);
-
static int snd_card_init(struct snd_card *card, struct device *parent,
int idx, const char *xid, struct module *module,
size_t extra_size)
--
2.55.0