2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ALSA sequencer Ports
|
|
|
|
* Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl>
|
2007-10-15 15:50:19 +08:00
|
|
|
* Jaroslav Kysela <perex@perex.cz>
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <linux/slab.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "seq_system.h"
|
|
|
|
#include "seq_ports.h"
|
|
|
|
#include "seq_clientmgr.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
registration of client ports
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
NOTE: the current implementation of the port structure as a linked list is
|
|
|
|
not optimal for clients that have many ports. For sending messages to all
|
|
|
|
subscribers of a port we first need to find the address of the port
|
|
|
|
structure, which means we have to traverse the list. A direct access table
|
|
|
|
(array) would be better, but big preallocated arrays waste memory.
|
|
|
|
|
|
|
|
Possible actions:
|
|
|
|
|
|
|
|
1) leave it this way, a client does normaly does not have more than a few
|
|
|
|
ports
|
|
|
|
|
|
|
|
2) replace the linked list of ports by a array of pointers which is
|
|
|
|
dynamicly kmalloced. When a port is added or deleted we can simply allocate
|
|
|
|
a new array, copy the corresponding pointers, and delete the old one. We
|
|
|
|
then only need a pointer to this array, and an integer that tells us how
|
|
|
|
much elements are in array.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* return pointer to port structure - port is locked if found */
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_client_port *snd_seq_port_use_ptr(struct snd_seq_client *client,
|
|
|
|
int num)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_client_port *port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (client == NULL)
|
|
|
|
return NULL;
|
|
|
|
read_lock(&client->ports_lock);
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry(port, &client->ports_list_head, list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (port->addr.port == num) {
|
|
|
|
if (port->closing)
|
|
|
|
break; /* deleting now */
|
|
|
|
snd_use_lock_use(&port->use_lock);
|
|
|
|
read_unlock(&client->ports_lock);
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_unlock(&client->ports_lock);
|
|
|
|
return NULL; /* not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* search for the next port - port is locked if found */
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_port_info *pinfo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int num;
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_client_port *port, *found;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
num = pinfo->addr.port;
|
|
|
|
found = NULL;
|
|
|
|
read_lock(&client->ports_lock);
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry(port, &client->ports_list_head, list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (port->addr.port < num)
|
|
|
|
continue;
|
|
|
|
if (port->addr.port == num) {
|
|
|
|
found = port;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (found == NULL || port->addr.port < found->addr.port)
|
|
|
|
found = port;
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
if (found->closing)
|
|
|
|
found = NULL;
|
|
|
|
else
|
|
|
|
snd_use_lock_use(&found->use_lock);
|
|
|
|
}
|
|
|
|
read_unlock(&client->ports_lock);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-17 21:04:02 +08:00
|
|
|
/* initialize snd_seq_port_subs_info */
|
|
|
|
static void port_subs_info_init(struct snd_seq_port_subs_info *grp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&grp->list_head);
|
|
|
|
grp->count = 0;
|
|
|
|
grp->exclusive = 0;
|
|
|
|
rwlock_init(&grp->list_lock);
|
|
|
|
init_rwsem(&grp->list_mutex);
|
|
|
|
grp->open = NULL;
|
|
|
|
grp->close = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-23 15:53:42 +08:00
|
|
|
/* create a port, port number or a negative error code is returned
|
2017-10-09 17:09:20 +08:00
|
|
|
* the caller needs to unref the port via snd_seq_port_unlock() appropriately
|
|
|
|
*/
|
2023-05-23 15:53:42 +08:00
|
|
|
int snd_seq_create_port(struct snd_seq_client *client, int port,
|
|
|
|
struct snd_seq_client_port **port_ret)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-05 22:02:22 +08:00
|
|
|
struct snd_seq_client_port *new_port, *p;
|
2023-05-23 15:53:42 +08:00
|
|
|
int num;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-05-23 15:53:42 +08:00
|
|
|
*port_ret = NULL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* sanity check */
|
2008-08-08 23:09:09 +08:00
|
|
|
if (snd_BUG_ON(!client))
|
2023-05-23 15:53:42 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-01-25 21:35:24 +08:00
|
|
|
if (client->num_ports >= SNDRV_SEQ_MAX_PORTS) {
|
2014-02-05 01:24:34 +08:00
|
|
|
pr_warn("ALSA: seq: too many ports for client %d\n", client->number);
|
2023-05-23 15:53:42 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new port */
|
2005-09-09 20:20:49 +08:00
|
|
|
new_port = kzalloc(sizeof(*new_port), GFP_KERNEL);
|
2015-03-10 22:41:18 +08:00
|
|
|
if (!new_port)
|
2023-05-23 15:53:42 +08:00
|
|
|
return -ENOMEM; /* failure, out of memory */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* init port data */
|
|
|
|
new_port->addr.client = client->number;
|
|
|
|
new_port->addr.port = -1;
|
|
|
|
new_port->owner = THIS_MODULE;
|
|
|
|
snd_use_lock_init(&new_port->use_lock);
|
|
|
|
port_subs_info_init(&new_port->c_src);
|
|
|
|
port_subs_info_init(&new_port->c_dest);
|
2017-10-09 17:09:20 +08:00
|
|
|
snd_use_lock_use(&new_port->use_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2022-05-17 14:25:17 +08:00
|
|
|
num = max(port, 0);
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_lock(&client->ports_mutex);
|
2019-03-28 23:21:01 +08:00
|
|
|
write_lock_irq(&client->ports_lock);
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry(p, &client->ports_list_head, list) {
|
2023-05-23 15:53:42 +08:00
|
|
|
if (p->addr.port == port) {
|
|
|
|
num = -EBUSY;
|
|
|
|
goto unlock;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (p->addr.port > num)
|
|
|
|
break;
|
|
|
|
if (port < 0) /* auto-probe mode */
|
|
|
|
num = p->addr.port + 1;
|
|
|
|
}
|
|
|
|
/* insert the new port */
|
2006-10-05 22:02:22 +08:00
|
|
|
list_add_tail(&new_port->list, &p->list);
|
2005-04-17 06:20:36 +08:00
|
|
|
client->num_ports++;
|
|
|
|
new_port->addr.port = num; /* store the port number in the port */
|
2017-10-09 17:09:20 +08:00
|
|
|
sprintf(new_port->name, "port-%d", num);
|
2023-05-23 15:53:42 +08:00
|
|
|
*port_ret = new_port;
|
|
|
|
unlock:
|
2019-03-28 23:21:01 +08:00
|
|
|
write_unlock_irq(&client->ports_lock);
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_unlock(&client->ports_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-05-23 15:53:42 +08:00
|
|
|
return num;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* */
|
2005-11-17 21:04:02 +08:00
|
|
|
static int subscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_port_subs_info *grp,
|
|
|
|
struct snd_seq_port_subscribe *info, int send_ack);
|
|
|
|
static int unsubscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_port_subs_info *grp,
|
|
|
|
struct snd_seq_port_subscribe *info, int send_ack);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2005-11-17 21:04:02 +08:00
|
|
|
static struct snd_seq_client_port *get_client_port(struct snd_seq_addr *addr,
|
|
|
|
struct snd_seq_client **cp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_client_port *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
*cp = snd_seq_client_use_ptr(addr->client);
|
|
|
|
if (*cp) {
|
|
|
|
p = snd_seq_port_use_ptr(*cp, addr->port);
|
|
|
|
if (! p) {
|
|
|
|
snd_seq_client_unlock(*cp);
|
|
|
|
*cp = NULL;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
static void delete_and_unsubscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_subscribers *subs,
|
|
|
|
bool is_src, bool ack);
|
|
|
|
|
|
|
|
static inline struct snd_seq_subscribers *
|
|
|
|
get_subscriber(struct list_head *p, bool is_src)
|
|
|
|
{
|
|
|
|
if (is_src)
|
|
|
|
return list_entry(p, struct snd_seq_subscribers, src_list);
|
|
|
|
else
|
|
|
|
return list_entry(p, struct snd_seq_subscribers, dest_list);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* remove all subscribers on the list
|
|
|
|
* this is called from port_delete, for each src and dest list.
|
|
|
|
*/
|
2005-11-17 21:04:02 +08:00
|
|
|
static void clear_subscriber_list(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_port_subs_info *grp,
|
2016-02-03 15:32:44 +08:00
|
|
|
int is_src)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct list_head *p, *n;
|
|
|
|
|
|
|
|
list_for_each_safe(p, n, &grp->list_head) {
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_subscribers *subs;
|
|
|
|
struct snd_seq_client *c;
|
|
|
|
struct snd_seq_client_port *aport;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
subs = get_subscriber(p, is_src);
|
|
|
|
if (is_src)
|
2005-04-17 06:20:36 +08:00
|
|
|
aport = get_client_port(&subs->info.dest, &c);
|
2016-02-03 15:32:44 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
aport = get_client_port(&subs->info.sender, &c);
|
2016-02-03 15:32:44 +08:00
|
|
|
delete_and_unsubscribe_port(client, port, subs, is_src, false);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!aport) {
|
|
|
|
/* looks like the connected port is being deleted.
|
|
|
|
* we decrease the counter, and when both ports are deleted
|
|
|
|
* remove the subscriber info
|
|
|
|
*/
|
|
|
|
if (atomic_dec_and_test(&subs->ref_count))
|
|
|
|
kfree(subs);
|
2016-02-03 15:32:44 +08:00
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2016-02-03 15:32:44 +08:00
|
|
|
|
|
|
|
/* ok we got the connected port */
|
|
|
|
delete_and_unsubscribe_port(c, aport, subs, !is_src, true);
|
|
|
|
kfree(subs);
|
|
|
|
snd_seq_port_unlock(aport);
|
|
|
|
snd_seq_client_unlock(c);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete port data */
|
2005-11-17 21:04:02 +08:00
|
|
|
static int port_delete(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* set closing flag and wait for all port access are gone */
|
|
|
|
port->closing = 1;
|
|
|
|
snd_use_lock_sync(&port->use_lock);
|
|
|
|
|
|
|
|
/* clear subscribers info */
|
2016-02-03 15:32:44 +08:00
|
|
|
clear_subscriber_list(client, port, &port->c_src, true);
|
|
|
|
clear_subscriber_list(client, port, &port->c_dest, false);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (port->private_free)
|
|
|
|
port->private_free(port->private_data);
|
|
|
|
|
2008-08-08 23:09:09 +08:00
|
|
|
snd_BUG_ON(port->c_src.count != 0);
|
|
|
|
snd_BUG_ON(port->c_dest.count != 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
kfree(port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* delete a port with the given port id */
|
2005-11-17 21:04:02 +08:00
|
|
|
int snd_seq_delete_port(struct snd_seq_client *client, int port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-05 22:02:22 +08:00
|
|
|
struct snd_seq_client_port *found = NULL, *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_lock(&client->ports_mutex);
|
2019-03-28 23:21:01 +08:00
|
|
|
write_lock_irq(&client->ports_lock);
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry(p, &client->ports_list_head, list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (p->addr.port == port) {
|
|
|
|
/* ok found. delete from the list at first */
|
2006-10-05 22:02:22 +08:00
|
|
|
list_del(&p->list);
|
2005-04-17 06:20:36 +08:00
|
|
|
client->num_ports--;
|
|
|
|
found = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-28 23:21:01 +08:00
|
|
|
write_unlock_irq(&client->ports_lock);
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_unlock(&client->ports_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (found)
|
|
|
|
return port_delete(client, found);
|
|
|
|
else
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete the all ports belonging to the given client */
|
2005-11-17 21:04:02 +08:00
|
|
|
int snd_seq_delete_all_ports(struct snd_seq_client *client)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-05 22:02:22 +08:00
|
|
|
struct list_head deleted_list;
|
|
|
|
struct snd_seq_client_port *port, *tmp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* move the port list to deleted_list, and
|
|
|
|
* clear the port list in the client data.
|
|
|
|
*/
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_lock(&client->ports_mutex);
|
2019-03-28 23:21:01 +08:00
|
|
|
write_lock_irq(&client->ports_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (! list_empty(&client->ports_list_head)) {
|
2006-06-27 19:07:04 +08:00
|
|
|
list_add(&deleted_list, &client->ports_list_head);
|
|
|
|
list_del_init(&client->ports_list_head);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
INIT_LIST_HEAD(&deleted_list);
|
|
|
|
}
|
|
|
|
client->num_ports = 0;
|
2019-03-28 23:21:01 +08:00
|
|
|
write_unlock_irq(&client->ports_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* remove each port in deleted_list */
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry_safe(port, tmp, &deleted_list, list) {
|
|
|
|
list_del(&port->list);
|
2005-04-17 06:20:36 +08:00
|
|
|
snd_seq_system_client_ev_port_exit(port->addr.client, port->addr.port);
|
|
|
|
port_delete(client, port);
|
|
|
|
}
|
2006-01-16 23:29:08 +08:00
|
|
|
mutex_unlock(&client->ports_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set port info fields */
|
2005-11-17 21:04:02 +08:00
|
|
|
int snd_seq_set_port_info(struct snd_seq_client_port * port,
|
|
|
|
struct snd_seq_port_info * info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-08-08 23:09:09 +08:00
|
|
|
if (snd_BUG_ON(!port || !info))
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* set port name */
|
|
|
|
if (info->name[0])
|
ALSA: Convert strlcpy to strscpy when return value is unused
strlcpy is deprecated. see: Documentation/process/deprecated.rst
Change the calls that do not use the strlcpy return value to the
preferred strscpy.
Done with cocci script:
@@
expression e1, e2, e3;
@@
- strlcpy(
+ strscpy(
e1, e2, e3);
This cocci script leaves the instances where the return value is
used unchanged.
After this patch, sound/ has 3 uses of strlcpy() that need to be
manually inspected for conversion and changed one day.
$ git grep -w strlcpy sound/
sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname));
sound/usb/mixer.c: return strlcpy(buf, p->name, buflen);
sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen);
Miscellenea:
o Remove trailing whitespace in conversion of sound/core/hwdep.c
Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-01-05 01:17:34 +08:00
|
|
|
strscpy(port->name, info->name, sizeof(port->name));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* set capabilities */
|
|
|
|
port->capability = info->capability;
|
|
|
|
|
|
|
|
/* get port type */
|
|
|
|
port->type = info->type;
|
|
|
|
|
|
|
|
/* information about supported channels/voices */
|
|
|
|
port->midi_channels = info->midi_channels;
|
|
|
|
port->midi_voices = info->midi_voices;
|
|
|
|
port->synth_voices = info->synth_voices;
|
|
|
|
|
|
|
|
/* timestamping */
|
|
|
|
port->timestamping = (info->flags & SNDRV_SEQ_PORT_FLG_TIMESTAMP) ? 1 : 0;
|
|
|
|
port->time_real = (info->flags & SNDRV_SEQ_PORT_FLG_TIME_REAL) ? 1 : 0;
|
|
|
|
port->time_queue = info->time_queue;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get port info fields */
|
2005-11-17 21:04:02 +08:00
|
|
|
int snd_seq_get_port_info(struct snd_seq_client_port * port,
|
|
|
|
struct snd_seq_port_info * info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-08-08 23:09:09 +08:00
|
|
|
if (snd_BUG_ON(!port || !info))
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* get port name */
|
ALSA: Convert strlcpy to strscpy when return value is unused
strlcpy is deprecated. see: Documentation/process/deprecated.rst
Change the calls that do not use the strlcpy return value to the
preferred strscpy.
Done with cocci script:
@@
expression e1, e2, e3;
@@
- strlcpy(
+ strscpy(
e1, e2, e3);
This cocci script leaves the instances where the return value is
used unchanged.
After this patch, sound/ has 3 uses of strlcpy() that need to be
manually inspected for conversion and changed one day.
$ git grep -w strlcpy sound/
sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname));
sound/usb/mixer.c: return strlcpy(buf, p->name, buflen);
sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen);
Miscellenea:
o Remove trailing whitespace in conversion of sound/core/hwdep.c
Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-01-05 01:17:34 +08:00
|
|
|
strscpy(info->name, port->name, sizeof(info->name));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* get capabilities */
|
|
|
|
info->capability = port->capability;
|
|
|
|
|
|
|
|
/* get port type */
|
|
|
|
info->type = port->type;
|
|
|
|
|
|
|
|
/* information about supported channels/voices */
|
|
|
|
info->midi_channels = port->midi_channels;
|
|
|
|
info->midi_voices = port->midi_voices;
|
|
|
|
info->synth_voices = port->synth_voices;
|
|
|
|
|
|
|
|
/* get subscriber counts */
|
|
|
|
info->read_use = port->c_src.count;
|
|
|
|
info->write_use = port->c_dest.count;
|
|
|
|
|
|
|
|
/* timestamping */
|
|
|
|
info->flags = 0;
|
|
|
|
if (port->timestamping) {
|
|
|
|
info->flags |= SNDRV_SEQ_PORT_FLG_TIMESTAMP;
|
|
|
|
if (port->time_real)
|
|
|
|
info->flags |= SNDRV_SEQ_PORT_FLG_TIME_REAL;
|
|
|
|
info->time_queue = port->time_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call callback functions (if any):
|
|
|
|
* the callbacks are invoked only when the first (for connection) or
|
|
|
|
* the last subscription (for disconnection) is done. Second or later
|
|
|
|
* subscription results in increment of counter, but no callback is
|
|
|
|
* invoked.
|
|
|
|
* This feature is useful if these callbacks are associated with
|
|
|
|
* initialization or termination of devices (see seq_midi.c).
|
|
|
|
*/
|
|
|
|
|
2005-11-17 21:04:02 +08:00
|
|
|
static int subscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_port_subs_info *grp,
|
|
|
|
struct snd_seq_port_subscribe *info,
|
|
|
|
int send_ack)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (!try_module_get(port->owner))
|
|
|
|
return -EFAULT;
|
|
|
|
grp->count++;
|
2015-01-25 21:36:27 +08:00
|
|
|
if (grp->open && grp->count == 1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = grp->open(port->private_data, info);
|
|
|
|
if (err < 0) {
|
|
|
|
module_put(port->owner);
|
|
|
|
grp->count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err >= 0 && send_ack && client->type == USER_CLIENT)
|
|
|
|
snd_seq_client_notify_subscription(port->addr.client, port->addr.port,
|
|
|
|
info, SNDRV_SEQ_EVENT_PORT_SUBSCRIBED);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-11-17 21:04:02 +08:00
|
|
|
static int unsubscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_port_subs_info *grp,
|
|
|
|
struct snd_seq_port_subscribe *info,
|
|
|
|
int send_ack)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (! grp->count)
|
|
|
|
return -EINVAL;
|
|
|
|
grp->count--;
|
2015-01-25 21:36:27 +08:00
|
|
|
if (grp->close && grp->count == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
err = grp->close(port->private_data, info);
|
|
|
|
if (send_ack && client->type == USER_CLIENT)
|
|
|
|
snd_seq_client_notify_subscription(port->addr.client, port->addr.port,
|
|
|
|
info, SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED);
|
|
|
|
module_put(port->owner);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* check if both addresses are identical */
|
2005-11-17 21:04:02 +08:00
|
|
|
static inline int addr_match(struct snd_seq_addr *r, struct snd_seq_addr *s)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return (r->client == s->client) && (r->port == s->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check the two subscribe info match */
|
|
|
|
/* if flags is zero, checks only sender and destination addresses */
|
2005-11-17 21:04:02 +08:00
|
|
|
static int match_subs_info(struct snd_seq_port_subscribe *r,
|
|
|
|
struct snd_seq_port_subscribe *s)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (addr_match(&r->sender, &s->sender) &&
|
|
|
|
addr_match(&r->dest, &s->dest)) {
|
|
|
|
if (r->flags && r->flags == s->flags)
|
|
|
|
return r->queue == s->queue;
|
|
|
|
else if (! r->flags)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
static int check_and_subscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_subscribers *subs,
|
|
|
|
bool is_src, bool exclusive, bool ack)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-02-03 15:32:44 +08:00
|
|
|
struct snd_seq_port_subs_info *grp;
|
|
|
|
struct list_head *p;
|
|
|
|
struct snd_seq_subscribers *s;
|
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
grp = is_src ? &port->c_src : &port->c_dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
err = -EBUSY;
|
2016-02-03 15:32:44 +08:00
|
|
|
down_write(&grp->list_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (exclusive) {
|
2016-02-03 15:32:44 +08:00
|
|
|
if (!list_empty(&grp->list_head))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto __error;
|
|
|
|
} else {
|
2016-02-03 15:32:44 +08:00
|
|
|
if (grp->exclusive)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto __error;
|
|
|
|
/* check whether already exists */
|
2016-02-03 15:32:44 +08:00
|
|
|
list_for_each(p, &grp->list_head) {
|
|
|
|
s = get_subscriber(p, is_src);
|
|
|
|
if (match_subs_info(&subs->info, &s->info))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto __error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
err = subscribe_port(client, port, grp, &subs->info, ack);
|
|
|
|
if (err < 0) {
|
|
|
|
grp->exclusive = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto __error;
|
2016-02-03 15:32:44 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* add to list */
|
2016-02-03 15:32:44 +08:00
|
|
|
write_lock_irq(&grp->list_lock);
|
|
|
|
if (is_src)
|
|
|
|
list_add_tail(&subs->src_list, &grp->list_head);
|
|
|
|
else
|
|
|
|
list_add_tail(&subs->dest_list, &grp->list_head);
|
|
|
|
grp->exclusive = exclusive;
|
|
|
|
atomic_inc(&subs->ref_count);
|
|
|
|
write_unlock_irq(&grp->list_lock);
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
__error:
|
|
|
|
up_write(&grp->list_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
/* called with grp->list_mutex held */
|
|
|
|
static void __delete_and_unsubscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_subscribers *subs,
|
|
|
|
bool is_src, bool ack)
|
2016-02-03 15:32:44 +08:00
|
|
|
{
|
|
|
|
struct snd_seq_port_subs_info *grp;
|
2016-02-16 21:15:59 +08:00
|
|
|
struct list_head *list;
|
|
|
|
bool empty;
|
2016-02-03 15:32:44 +08:00
|
|
|
|
|
|
|
grp = is_src ? &port->c_src : &port->c_dest;
|
2016-02-16 21:15:59 +08:00
|
|
|
list = is_src ? &subs->src_list : &subs->dest_list;
|
2016-02-03 15:32:44 +08:00
|
|
|
write_lock_irq(&grp->list_lock);
|
2016-02-16 21:15:59 +08:00
|
|
|
empty = list_empty(list);
|
|
|
|
if (!empty)
|
|
|
|
list_del_init(list);
|
2016-02-03 15:32:44 +08:00
|
|
|
grp->exclusive = 0;
|
|
|
|
write_unlock_irq(&grp->list_lock);
|
|
|
|
|
2016-02-16 21:15:59 +08:00
|
|
|
if (!empty)
|
|
|
|
unsubscribe_port(client, port, grp, &subs->info, ack);
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_and_unsubscribe_port(struct snd_seq_client *client,
|
|
|
|
struct snd_seq_client_port *port,
|
|
|
|
struct snd_seq_subscribers *subs,
|
|
|
|
bool is_src, bool ack)
|
|
|
|
{
|
|
|
|
struct snd_seq_port_subs_info *grp;
|
|
|
|
|
|
|
|
grp = is_src ? &port->c_src : &port->c_dest;
|
|
|
|
down_write(&grp->list_mutex);
|
|
|
|
__delete_and_unsubscribe_port(client, port, subs, is_src, ack);
|
2019-04-12 17:37:19 +08:00
|
|
|
up_write(&grp->list_mutex);
|
2016-02-03 15:32:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* connect two ports */
|
|
|
|
int snd_seq_port_connect(struct snd_seq_client *connector,
|
|
|
|
struct snd_seq_client *src_client,
|
|
|
|
struct snd_seq_client_port *src_port,
|
|
|
|
struct snd_seq_client *dest_client,
|
|
|
|
struct snd_seq_client_port *dest_port,
|
|
|
|
struct snd_seq_port_subscribe *info)
|
|
|
|
{
|
|
|
|
struct snd_seq_subscribers *subs;
|
|
|
|
bool exclusive;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
subs = kzalloc(sizeof(*subs), GFP_KERNEL);
|
|
|
|
if (!subs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
subs->info = *info;
|
|
|
|
atomic_set(&subs->ref_count, 0);
|
|
|
|
INIT_LIST_HEAD(&subs->src_list);
|
|
|
|
INIT_LIST_HEAD(&subs->dest_list);
|
|
|
|
|
|
|
|
exclusive = !!(info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE);
|
|
|
|
|
|
|
|
err = check_and_subscribe_port(src_client, src_port, subs, true,
|
|
|
|
exclusive,
|
|
|
|
connector->number != src_client->number);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
err = check_and_subscribe_port(dest_client, dest_port, subs, false,
|
|
|
|
exclusive,
|
|
|
|
connector->number != dest_client->number);
|
|
|
|
if (err < 0)
|
|
|
|
goto error_dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2016-02-03 15:32:44 +08:00
|
|
|
error_dest:
|
|
|
|
delete_and_unsubscribe_port(src_client, src_port, subs, true,
|
|
|
|
connector->number != src_client->number);
|
|
|
|
error:
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(subs);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the connection */
|
2005-11-17 21:04:02 +08:00
|
|
|
int snd_seq_port_disconnect(struct snd_seq_client *connector,
|
|
|
|
struct snd_seq_client *src_client,
|
|
|
|
struct snd_seq_client_port *src_port,
|
|
|
|
struct snd_seq_client *dest_client,
|
|
|
|
struct snd_seq_client_port *dest_port,
|
|
|
|
struct snd_seq_port_subscribe *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
struct snd_seq_port_subs_info *dest = &dest_port->c_dest;
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_subscribers *subs;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err = -ENOENT;
|
|
|
|
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
/* always start from deleting the dest port for avoiding concurrent
|
|
|
|
* deletions
|
|
|
|
*/
|
|
|
|
down_write(&dest->list_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* look for the connection */
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
list_for_each_entry(subs, &dest->list_head, dest_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (match_subs_info(info, &subs->info)) {
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
__delete_and_unsubscribe_port(dest_client, dest_port,
|
|
|
|
subs, false,
|
|
|
|
connector->number != dest_client->number);
|
2005-04-17 06:20:36 +08:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
ALSA: seq: Fix racy deletion of subscriber
It turned out that the current implementation of the port subscription
is racy. The subscription contains two linked lists, and we have to
add to or delete from both lists. Since both connection and
disconnection procedures perform the same order for those two lists
(i.e. src list, then dest list), when a deletion happens during a
connection procedure, the src list may be deleted before the dest list
addition completes, and this may lead to a use-after-free or an Oops,
even though the access to both lists are protected via mutex.
The simple workaround for this race is to change the access order for
the disconnection, namely, dest list, then src list. This assures
that the connection has been established when disconnecting, and also
the concurrent deletion can be avoided.
Reported-and-tested-by: folkert <folkert@vanheusden.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210801182754.GP890690@belle.intranet.vanheusden.com
Link: https://lore.kernel.org/r/20210803114312.2536-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-08-03 19:43:12 +08:00
|
|
|
up_write(&dest->list_mutex);
|
2016-02-03 15:32:44 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
delete_and_unsubscribe_port(src_client, src_port, subs, true,
|
|
|
|
connector->number != src_client->number);
|
|
|
|
kfree(subs);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get matched subscriber */
|
2019-04-10 00:04:17 +08:00
|
|
|
int snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
|
|
|
|
struct snd_seq_addr *dest_addr,
|
|
|
|
struct snd_seq_port_subscribe *subs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-04-10 00:04:17 +08:00
|
|
|
struct snd_seq_subscribers *s;
|
|
|
|
int err = -ENOENT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
down_read(&src_grp->list_mutex);
|
2006-10-05 22:02:22 +08:00
|
|
|
list_for_each_entry(s, &src_grp->list_head, src_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (addr_match(dest_addr, &s->info.dest)) {
|
2019-04-10 00:04:17 +08:00
|
|
|
*subs = s->info;
|
|
|
|
err = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
up_read(&src_grp->list_mutex);
|
2019-04-10 00:04:17 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach a device driver that wants to receive events from the
|
|
|
|
* sequencer. Returns the new port number on success.
|
|
|
|
* A driver that wants to receive the events converted to midi, will
|
|
|
|
* use snd_seq_midisynth_register_port().
|
|
|
|
*/
|
|
|
|
/* exported */
|
|
|
|
int snd_seq_event_port_attach(int client,
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_port_callback *pcbp,
|
2005-04-17 06:20:36 +08:00
|
|
|
int cap, int type, int midi_channels,
|
|
|
|
int midi_voices, char *portname)
|
|
|
|
{
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_port_info portinfo;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set up the port */
|
|
|
|
memset(&portinfo, 0, sizeof(portinfo));
|
|
|
|
portinfo.addr.client = client;
|
ALSA: Convert strlcpy to strscpy when return value is unused
strlcpy is deprecated. see: Documentation/process/deprecated.rst
Change the calls that do not use the strlcpy return value to the
preferred strscpy.
Done with cocci script:
@@
expression e1, e2, e3;
@@
- strlcpy(
+ strscpy(
e1, e2, e3);
This cocci script leaves the instances where the return value is
used unchanged.
After this patch, sound/ has 3 uses of strlcpy() that need to be
manually inspected for conversion and changed one day.
$ git grep -w strlcpy sound/
sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname));
sound/usb/mixer.c: return strlcpy(buf, p->name, buflen);
sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen);
Miscellenea:
o Remove trailing whitespace in conversion of sound/core/hwdep.c
Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-01-05 01:17:34 +08:00
|
|
|
strscpy(portinfo.name, portname ? portname : "Unnamed port",
|
2005-04-17 06:20:36 +08:00
|
|
|
sizeof(portinfo.name));
|
|
|
|
|
|
|
|
portinfo.capability = cap;
|
|
|
|
portinfo.type = type;
|
|
|
|
portinfo.kernel = pcbp;
|
|
|
|
portinfo.midi_channels = midi_channels;
|
|
|
|
portinfo.midi_voices = midi_voices;
|
|
|
|
|
|
|
|
/* Create it */
|
|
|
|
ret = snd_seq_kernel_client_ctl(client,
|
|
|
|
SNDRV_SEQ_IOCTL_CREATE_PORT,
|
|
|
|
&portinfo);
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = portinfo.addr.port;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_seq_event_port_attach);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach the driver from a port.
|
|
|
|
*/
|
|
|
|
/* exported */
|
|
|
|
int snd_seq_event_port_detach(int client, int port)
|
|
|
|
{
|
2005-11-17 21:04:02 +08:00
|
|
|
struct snd_seq_port_info portinfo;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&portinfo, 0, sizeof(portinfo));
|
|
|
|
portinfo.addr.client = client;
|
|
|
|
portinfo.addr.port = port;
|
|
|
|
err = snd_seq_kernel_client_ctl(client,
|
|
|
|
SNDRV_SEQ_IOCTL_DELETE_PORT,
|
|
|
|
&portinfo);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2006-04-28 21:13:39 +08:00
|
|
|
EXPORT_SYMBOL(snd_seq_event_port_detach);
|