summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_udev.c
diff options
context:
space:
mode:
Diffstat (limited to 'cras/src/server/cras_udev.c')
-rw-r--r--cras/src/server/cras_udev.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/cras/src/server/cras_udev.c b/cras/src/server/cras_udev.c
index dc4c2dd8..2ba1fcd1 100644
--- a/cras/src/server/cras_udev.c
+++ b/cras/src/server/cras_udev.c
@@ -25,8 +25,8 @@ struct udev_callback_data {
int fd;
};
-static unsigned is_action(const char *desired, const char *actual)
- __attribute__((nonnull(1)));
+static unsigned is_action(const char *desired,
+ const char *actual) __attribute__((nonnull(1)));
/* Matches Alsa sound device entries generated by udev. For
* example:
@@ -77,7 +77,7 @@ static regex_t pcm_regex;
static const char card_regex_string[] = "^.*/card([0-9]+)";
static regex_t card_regex;
-static char const *const subsystem = "sound";
+static char const * const subsystem = "sound";
static const unsigned int MAX_DESC_NAME_LEN = 256;
static unsigned is_action(const char *desired, const char *actual)
@@ -98,7 +98,8 @@ static unsigned is_action_remove(const char *action)
static unsigned is_internal_bus(const char *bus)
{
return (bus != NULL &&
- (strcmp(bus, "pci") == 0 || strcmp(bus, "platform") == 0));
+ (strcmp(bus, "pci") == 0 ||
+ strcmp(bus, "platform") == 0));
}
static unsigned is_external_bus(const char *bus)
@@ -123,17 +124,19 @@ static unsigned is_internal_device(struct udev_device *dev)
return 0;
}
-static unsigned is_card_device(struct udev_device *dev, unsigned *internal,
- unsigned *card_number, const char **sysname)
+static unsigned is_card_device(struct udev_device *dev,
+ unsigned *internal,
+ unsigned *card_number,
+ const char **sysname)
{
regmatch_t m[2];
const char *devpath = udev_device_get_devpath(dev);
if (devpath != NULL &&
regexec(&card_regex, devpath, ARRAY_SIZE(m), m, 0) == 0) {
- *sysname = udev_device_get_sysname(dev);
- *internal = is_internal_device(dev);
- *card_number = (unsigned)atoi(&devpath[m[1].rm_so]);
+ *sysname = udev_device_get_sysname(dev);
+ *internal = is_internal_device(dev);
+ *card_number = (unsigned)atoi(&devpath[m[1].rm_so]);
return 1;
}
@@ -152,8 +155,8 @@ static void set_factory_default(unsigned card_number)
syslog(LOG_INFO, "%s: init card '%u' to factory default",
__FUNCTION__, card_number);
r = snprintf(cmd_buf, ARRAY_SIZE(cmd_buf),
- "%s --file %s restore %u", alsactl, asound_state,
- card_number);
+ "%s --file %s restore %u",
+ alsactl, asound_state, card_number);
cmd_buf[ARRAY_SIZE(cmd_buf) - 1] = '\0';
r = system(cmd_buf);
if (r != 0)
@@ -175,7 +178,7 @@ static inline void udev_delay_for_alsa()
*
* will be produced by cras_alsa_card_create().
*/
- usleep(125000); /* 0.125 second */
+ usleep(125000); /* 0.125 second */
}
/* Reads the "descriptors" file of the usb device and returns the
@@ -198,15 +201,15 @@ static uint32_t calculate_desc_checksum(struct udev_device *dev)
}
if (stat(path, &stat_buf) < 0) {
- syslog(LOG_ERR, "failed to stat file %s: %s", path,
- strerror(errno));
+ syslog(LOG_ERR, "failed to stat file %s: %s",
+ path, strerror(errno));
return 0;
}
fd = open(path, O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "failed to open file %s: %s", path,
- strerror(errno));
+ syslog(LOG_ERR, "failed to open file %s: %s",
+ path, strerror(errno));
return 0;
}
@@ -219,8 +222,8 @@ static uint32_t calculate_desc_checksum(struct udev_device *dev)
buf_size *= 2;
uint8_t *new_buf = realloc(buf, buf_size);
if (new_buf == NULL) {
- syslog(LOG_ERR, "no memory to read file %s",
- path);
+ syslog(LOG_ERR,
+ "no memory to read file %s", path);
goto bail;
}
buf = new_buf;
@@ -250,7 +253,8 @@ static void fill_usb_card_info(struct cras_alsa_card_info *card_info,
{
const char *sysattr;
struct udev_device *parent_dev =
- udev_device_get_parent_with_subsystem_devtype(dev, "usb",
+ udev_device_get_parent_with_subsystem_devtype(dev,
+ "usb",
"usb_device");
if (!parent_dev)
return;
@@ -265,21 +269,22 @@ static void fill_usb_card_info(struct cras_alsa_card_info *card_info,
if (sysattr) {
strncpy(card_info->usb_serial_number, sysattr,
USB_SERIAL_NUMBER_BUFFER_SIZE - 1);
- card_info->usb_serial_number[USB_SERIAL_NUMBER_BUFFER_SIZE - 1] =
- '\0';
+ card_info->usb_serial_number[USB_SERIAL_NUMBER_BUFFER_SIZE - 1]
+ = '\0';
}
card_info->usb_desc_checksum = calculate_desc_checksum(parent_dev);
- syslog(LOG_ERR,
- "USB card: vendor:%04x, product:%04x, serial num:%s, "
+ syslog(LOG_ERR, "USB card: vendor:%04x, product:%04x, serial num:%s, "
"checksum:%08x",
- card_info->usb_vendor_id, card_info->usb_product_id,
- card_info->usb_serial_number, card_info->usb_desc_checksum);
+ card_info->usb_vendor_id, card_info->usb_product_id,
+ card_info->usb_serial_number, card_info->usb_desc_checksum);
}
-static void device_add_alsa(struct udev_device *dev, const char *sysname,
- unsigned card, unsigned internal)
+static void device_add_alsa(struct udev_device *dev,
+ const char *sysname,
+ unsigned card,
+ unsigned internal)
{
struct cras_alsa_card_info card_info;
memset(&card_info, 0, sizeof(card_info));
@@ -322,9 +327,9 @@ static void change_udev_device_if_alsa_device(struct udev_device *dev)
/* If the device, 'dev' is an alsa device, add it to the set of
* devices available for I/O. Mark it as the active device.
*/
- unsigned internal;
- unsigned card_number;
- const char *sysname;
+ unsigned internal;
+ unsigned card_number;
+ const char *sysname;
if (is_card_device(dev, &internal, &card_number, &sysname) &&
udev_sound_initialized(dev) &&
@@ -337,9 +342,9 @@ static void change_udev_device_if_alsa_device(struct udev_device *dev)
static void remove_device_if_card(struct udev_device *dev)
{
- unsigned internal;
- unsigned card_number;
- const char *sysname;
+ unsigned internal;
+ unsigned card_number;
+ const char *sysname;
if (is_card_device(dev, &internal, &card_number, &sysname))
device_remove_alsa(sysname, card_number);
@@ -347,7 +352,7 @@ static void remove_device_if_card(struct udev_device *dev)
static void enumerate_devices(struct udev_callback_data *data)
{
- struct udev_enumerate *enumerate = udev_enumerate_new(data->udev);
+ struct udev_enumerate *enumerate = udev_enumerate_new(data->udev);
struct udev_list_entry *dl;
struct udev_list_entry *dev_list_entry;
@@ -355,8 +360,7 @@ static void enumerate_devices(struct udev_callback_data *data)
udev_enumerate_scan_devices(enumerate);
dl = udev_enumerate_get_list_entry(enumerate);
- udev_list_entry_foreach(dev_list_entry, dl)
- {
+ udev_list_entry_foreach(dev_list_entry, dl) {
const char *path = udev_list_entry_get_name(dev_list_entry);
struct udev_device *dev =
udev_device_new_from_syspath(data->udev, path);
@@ -384,8 +388,7 @@ static void udev_sound_subsystem_callback(void *arg)
} else
syslog(LOG_WARNING,
"%s (internal error): "
- "No device obtained",
- __FUNCTION__);
+ "No device obtained", __FUNCTION__);
}
static void compile_regex(regex_t *regex, const char *str)
@@ -408,8 +411,9 @@ void cras_udev_start_sound_subsystem_monitor()
udev_monitor_enable_receiving(udev_data.mon);
udev_data.fd = udev_monitor_get_fd(udev_data.mon);
- r = cras_system_add_select_fd(
- udev_data.fd, udev_sound_subsystem_callback, &udev_data);
+ r = cras_system_add_select_fd(udev_data.fd,
+ udev_sound_subsystem_callback,
+ &udev_data);
assert(r == 0);
compile_regex(&pcm_regex, pcm_regex_string);
compile_regex(&card_regex, card_regex_string);