]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: seq: Simplify internal command operation from OSS layer
authorTakashi Iwai <tiwai@suse.de>
Wed, 27 Aug 2025 08:05:07 +0000 (10:05 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 09:52:35 +0000 (11:52 +0200)
snd_seq_client_ioctl_lock() and *_unlock() are used only from a single
function of the OSS layer, and it's just to wrap the call of
snd_seq_kernel_client_ctl().

Provide another variant of snd_seq_kernel_client_ctl() that takes the
locks internally and drop the ugly snd_seq_client_ioctl_lock() and
*_unlock() implementations, instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250827080520.7544-2-tiwai@suse.de
sound/core/seq/oss/seq_oss_device.h
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_clientmgr.h

index 6163a00bc8de127b2d0c5db7f60e926e5a2ae873..935cf3df0b30f87d493b8d9266b6a1379fe3fdbc 100644 (file)
@@ -137,12 +137,7 @@ snd_seq_oss_dispatch(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, int a
 static inline int
 snd_seq_oss_control(struct seq_oss_devinfo *dp, unsigned int type, void *arg)
 {
-       int err;
-
-       snd_seq_client_ioctl_lock(dp->cseq);
-       err = snd_seq_kernel_client_ctl(dp->cseq, type, arg);
-       snd_seq_client_ioctl_unlock(dp->cseq);
-       return err;
+       return snd_seq_kernel_client_ioctl(dp->cseq, type, arg);
 }
 
 /* fill the addresses in header */
index aa9c956d258196c99ae991d619c31d98bd9651fe..7787f46616264ffcecc7ca8d86fa013f5284b15a 100644 (file)
@@ -182,41 +182,6 @@ static struct snd_seq_client *client_load_and_use_ptr(int clientid)
        return client_use_ptr(clientid, IS_ENABLED(CONFIG_MODULES));
 }
 
-/* Take refcount and perform ioctl_mutex lock on the given client;
- * used only for OSS sequencer
- * Unlock via snd_seq_client_ioctl_unlock() below
- */
-bool snd_seq_client_ioctl_lock(int clientid)
-{
-       struct snd_seq_client *client;
-
-       client = client_load_and_use_ptr(clientid);
-       if (!client)
-               return false;
-       mutex_lock(&client->ioctl_mutex);
-       /* The client isn't unrefed here; see snd_seq_client_ioctl_unlock() */
-       return true;
-}
-EXPORT_SYMBOL_GPL(snd_seq_client_ioctl_lock);
-
-/* Unlock and unref the given client; for OSS sequencer use only */
-void snd_seq_client_ioctl_unlock(int clientid)
-{
-       struct snd_seq_client *client;
-
-       client = snd_seq_client_use_ptr(clientid);
-       if (WARN_ON(!client))
-               return;
-       mutex_unlock(&client->ioctl_mutex);
-       /* The doubly unrefs below are intentional; the first one releases the
-        * leftover from snd_seq_client_ioctl_lock() above, and the second one
-        * is for releasing snd_seq_client_use_ptr() in this function
-        */
-       snd_seq_client_unlock(client);
-       snd_seq_client_unlock(client);
-}
-EXPORT_SYMBOL_GPL(snd_seq_client_ioctl_unlock);
-
 static void usage_alloc(struct snd_seq_usage *res, int num)
 {
        res->cur += num;
@@ -2558,6 +2523,21 @@ int snd_seq_kernel_client_dispatch(int client, struct snd_seq_event * ev,
 }
 EXPORT_SYMBOL(snd_seq_kernel_client_dispatch);
 
+static int call_seq_client_ctl(struct snd_seq_client *client,
+                              unsigned int cmd, void *arg)
+{
+       const struct ioctl_handler *handler;
+
+       for (handler = ioctl_handlers; handler->cmd > 0; ++handler) {
+               if (handler->cmd == cmd)
+                       return handler->func(client, arg);
+       }
+
+       pr_debug("ALSA: seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n",
+                cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
+       return -ENOTTY;
+}
+
 /**
  * snd_seq_kernel_client_ctl - operate a command for a client with data in
  *                            kernel space.
@@ -2572,24 +2552,33 @@ EXPORT_SYMBOL(snd_seq_kernel_client_dispatch);
  */
 int snd_seq_kernel_client_ctl(int clientid, unsigned int cmd, void *arg)
 {
-       const struct ioctl_handler *handler;
        struct snd_seq_client *client;
 
        client = clientptr(clientid);
        if (client == NULL)
                return -ENXIO;
 
-       for (handler = ioctl_handlers; handler->cmd > 0; ++handler) {
-               if (handler->cmd == cmd)
-                       return handler->func(client, arg);
-       }
-
-       pr_debug("ALSA: seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n",
-                cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
-       return -ENOTTY;
+       return call_seq_client_ctl(client, cmd, arg);
 }
 EXPORT_SYMBOL(snd_seq_kernel_client_ctl);
 
+/* a similar like above but taking locks; used only from OSS sequencer layer */
+int snd_seq_kernel_client_ioctl(int clientid, unsigned int cmd, void *arg)
+{
+       struct snd_seq_client *client;
+       int ret;
+
+       client = client_load_and_use_ptr(clientid);
+       if (!client)
+               return -ENXIO;
+       mutex_lock(&client->ioctl_mutex);
+       ret = call_seq_client_ctl(client, cmd, arg);
+       mutex_unlock(&client->ioctl_mutex);
+       snd_seq_client_unlock(client);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_seq_kernel_client_ioctl);
+
 /* exported (for OSS emulator) */
 int snd_seq_kernel_client_write_poll(int clientid, struct file *file, poll_table *wait)
 {
index 915b1017286e70f8a00a2432842aabda170d9304..7d0758e72aa98d0302806feadd722c3706758f13 100644 (file)
@@ -94,8 +94,7 @@ int __snd_seq_deliver_single_event(struct snd_seq_client *dest,
                                   int atomic, int hop);
 
 /* only for OSS sequencer */
-bool snd_seq_client_ioctl_lock(int clientid);
-void snd_seq_client_ioctl_unlock(int clientid);
+int snd_seq_kernel_client_ioctl(int clientid, unsigned int cmd, void *arg);
 
 extern int seq_client_load[15];