]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: seq: Use bus specific probe and remove
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Tue, 9 Dec 2025 12:38:43 +0000 (13:38 +0100)
committerTakashi Iwai <tiwai@suse.de>
Sun, 14 Dec 2025 10:08:09 +0000 (11:08 +0100)
Introduce a bus specific probe and remove function. For now this only
allows to get rid of a cast of the generic device to an snd_seq device
in the drivers and changes the remove prototype to return void---a
non-zero return value is ignored anyhow.

The objective is to get rid of users of struct device callbacks
.probe(), .remove() and .shutdown() to eventually remove these. Until
all snd_seq drivers are converted this results in a runtime warning
about the drivers needing an update because there is a bus probe
function and a driver probe function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/f36b01b297fc5cbb6d0ed4959143add0c13eec99.1765283601.git.u.kleine-koenig@baylibre.com
include/sound/seq_device.h
sound/core/seq_device.c

index dead74b022f4a31f6662a2bb60d9f20b7cf634cb..a72380c202e984d670f3ab729033ddb689932c5d 100644 (file)
@@ -43,6 +43,8 @@ struct snd_seq_device {
  *     Typically, call snd_device_free(dev->card, dev->driver_data)
  */
 struct snd_seq_driver {
+       int (*probe)(struct snd_seq_device *dev);
+       void (*remove)(struct snd_seq_device *dev);
        struct device_driver driver;
        char *id;
        int argsize;
index bac9f860373425199074215232af591f4fb6da96..01def5b739a62564a018232bbdad45984e11226c 100644 (file)
@@ -49,9 +49,31 @@ static int snd_seq_bus_match(struct device *dev, const struct device_driver *drv
                sdrv->argsize == sdev->argsize;
 }
 
+static int snd_seq_bus_probe(struct device *dev)
+{
+       struct snd_seq_device *sdev = to_seq_dev(dev);
+       const struct snd_seq_driver *sdrv = to_seq_drv(dev->driver);
+
+       if (sdrv->probe)
+               return sdrv->probe(sdev);
+       else
+               return 0;
+}
+
+static void snd_seq_bus_remove(struct device *dev)
+{
+       struct snd_seq_device *sdev = to_seq_dev(dev);
+       const struct snd_seq_driver *sdrv = to_seq_drv(dev->driver);
+
+       if (sdrv->remove)
+               sdrv->remove(sdev);
+}
+
 static const struct bus_type snd_seq_bus_type = {
        .name = "snd_seq",
        .match = snd_seq_bus_match,
+       .probe = snd_seq_bus_probe,
+       .remove = snd_seq_bus_remove,
 };
 
 /*
@@ -242,6 +264,25 @@ int snd_seq_device_new(struct snd_card *card, int device, const char *id,
 }
 EXPORT_SYMBOL(snd_seq_device_new);
 
+static int snd_seq_driver_legacy_probe(struct snd_seq_device *sdev)
+{
+       struct device *dev = &sdev->dev;
+       struct device_driver *driver = dev->driver;
+
+       return driver->probe(dev);
+}
+
+static void snd_seq_driver_legacy_remove(struct snd_seq_device *sdev)
+{
+       struct device *dev = &sdev->dev;
+       struct device_driver *driver = dev->driver;
+       int ret;
+
+       ret = driver->remove(dev);
+       if (unlikely(ret))
+               dev_warn(dev, "Ignoring return value of remove callback (%pe)\n", ERR_PTR(ret));
+}
+
 /*
  * driver registration
  */
@@ -251,6 +292,12 @@ int __snd_seq_driver_register(struct snd_seq_driver *drv, struct module *mod)
                return -EINVAL;
        drv->driver.bus = &snd_seq_bus_type;
        drv->driver.owner = mod;
+
+       if (!drv->probe && drv->driver.probe)
+               drv->probe = snd_seq_driver_legacy_probe;
+       if (!drv->remove && drv->driver.remove)
+               drv->remove = snd_seq_driver_legacy_remove;
+
        return driver_register(&drv->driver);
 }
 EXPORT_SYMBOL_GPL(__snd_seq_driver_register);