Lines Matching +full:signal +full:- +full:guard

1 // SPDX-License-Identifier: GPL-2.0-or-later
13 #include <linux/sched/signal.h>
37 if (hwdep->card == card && hwdep->device == device) in snd_hwdep_search()
44 struct snd_hwdep *hw = file->private_data; in snd_hwdep_llseek()
45 if (hw->ops.llseek) in snd_hwdep_llseek()
46 return hw->ops.llseek(hw, file, offset, orig); in snd_hwdep_llseek()
47 return -ENXIO; in snd_hwdep_llseek()
53 struct snd_hwdep *hw = file->private_data; in snd_hwdep_read()
54 if (hw->ops.read) in snd_hwdep_read()
55 return hw->ops.read(hw, buf, count, offset); in snd_hwdep_read()
56 return -ENXIO; in snd_hwdep_read()
62 struct snd_hwdep *hw = file->private_data; in snd_hwdep_write()
63 if (hw->ops.write) in snd_hwdep_write()
64 return hw->ops.write(hw, buf, count, offset); in snd_hwdep_write()
65 return -ENXIO; in snd_hwdep_write()
84 return -ENXIO; in snd_hwdep_open()
86 return -ENODEV; in snd_hwdep_open()
88 if (!try_module_get(hw->card->module)) { in snd_hwdep_open()
89 snd_card_unref(hw->card); in snd_hwdep_open()
90 return -EFAULT; in snd_hwdep_open()
94 add_wait_queue(&hw->open_wait, &wait); in snd_hwdep_open()
95 mutex_lock(&hw->open_mutex); in snd_hwdep_open()
97 if (hw->exclusive && hw->used > 0) { in snd_hwdep_open()
98 err = -EBUSY; in snd_hwdep_open()
101 if (!hw->ops.open) { in snd_hwdep_open()
105 err = hw->ops.open(hw, file); in snd_hwdep_open()
108 if (err == -EAGAIN) { in snd_hwdep_open()
109 if (file->f_flags & O_NONBLOCK) { in snd_hwdep_open()
110 err = -EBUSY; in snd_hwdep_open()
116 mutex_unlock(&hw->open_mutex); in snd_hwdep_open()
118 mutex_lock(&hw->open_mutex); in snd_hwdep_open()
119 if (hw->card->shutdown) { in snd_hwdep_open()
120 err = -ENODEV; in snd_hwdep_open()
124 err = -ERESTARTSYS; in snd_hwdep_open()
128 remove_wait_queue(&hw->open_wait, &wait); in snd_hwdep_open()
130 err = snd_card_file_add(hw->card, file); in snd_hwdep_open()
132 file->private_data = hw; in snd_hwdep_open()
133 hw->used++; in snd_hwdep_open()
135 if (hw->ops.release) in snd_hwdep_open()
136 hw->ops.release(hw, file); in snd_hwdep_open()
139 mutex_unlock(&hw->open_mutex); in snd_hwdep_open()
141 module_put(hw->card->module); in snd_hwdep_open()
142 snd_card_unref(hw->card); in snd_hwdep_open()
149 struct snd_hwdep *hw = file->private_data; in snd_hwdep_release()
150 struct module *mod = hw->card->module; in snd_hwdep_release()
152 scoped_guard(mutex, &hw->open_mutex) { in snd_hwdep_release()
153 if (hw->ops.release) in snd_hwdep_release()
154 err = hw->ops.release(hw, file); in snd_hwdep_release()
155 if (hw->used > 0) in snd_hwdep_release()
156 hw->used--; in snd_hwdep_release()
158 wake_up(&hw->open_wait); in snd_hwdep_release()
160 snd_card_file_remove(hw->card, file); in snd_hwdep_release()
167 struct snd_hwdep *hw = file->private_data; in snd_hwdep_poll()
168 if (hw->ops.poll) in snd_hwdep_poll()
169 return hw->ops.poll(hw, file, wait); in snd_hwdep_poll()
179 info.card = hw->card->number; in snd_hwdep_info()
180 strscpy(info.id, hw->id, sizeof(info.id)); in snd_hwdep_info()
181 strscpy(info.name, hw->name, sizeof(info.name)); in snd_hwdep_info()
182 info.iface = hw->iface; in snd_hwdep_info()
184 return -EFAULT; in snd_hwdep_info()
194 if (! hw->ops.dsp_status) in snd_hwdep_dsp_status()
195 return -ENXIO; in snd_hwdep_dsp_status()
197 info.dsp_loaded = hw->dsp_loaded; in snd_hwdep_dsp_status()
198 err = hw->ops.dsp_status(hw, &info); in snd_hwdep_dsp_status()
202 return -EFAULT; in snd_hwdep_dsp_status()
211 if (! hw->ops.dsp_load) in snd_hwdep_dsp_load()
212 return -ENXIO; in snd_hwdep_dsp_load()
213 if (info->index >= 32) in snd_hwdep_dsp_load()
214 return -EINVAL; in snd_hwdep_dsp_load()
216 if (hw->dsp_loaded & (1u << info->index)) in snd_hwdep_dsp_load()
217 return -EBUSY; in snd_hwdep_dsp_load()
218 err = hw->ops.dsp_load(hw, info); in snd_hwdep_dsp_load()
221 hw->dsp_loaded |= (1u << info->index); in snd_hwdep_dsp_load()
231 return -EFAULT; in snd_hwdep_dsp_load_user()
239 struct snd_hwdep *hw = file->private_data; in snd_hwdep_ioctl()
251 if (hw->ops.ioctl) in snd_hwdep_ioctl()
252 return hw->ops.ioctl(hw, file, cmd, arg); in snd_hwdep_ioctl()
253 return -ENOTTY; in snd_hwdep_ioctl()
258 struct snd_hwdep *hw = file->private_data; in snd_hwdep_mmap()
259 if (hw->ops.mmap) in snd_hwdep_mmap()
260 return hw->ops.mmap(hw, file, vma); in snd_hwdep_mmap()
261 return -ENXIO; in snd_hwdep_mmap()
274 return -EFAULT; in snd_hwdep_control_ioctl()
290 device = -1; in snd_hwdep_control_ioctl()
293 return -EFAULT; in snd_hwdep_control_ioctl()
302 if (get_user(device, &info->device)) in snd_hwdep_control_ioctl()
303 return -EFAULT; in snd_hwdep_control_ioctl()
307 return -ENXIO; in snd_hwdep_control_ioctl()
313 return -ENOIOCTLCMD; in snd_hwdep_control_ioctl()
344 if (hwdep->private_free) in snd_hwdep_free()
345 hwdep->private_free(hwdep); in snd_hwdep_free()
346 put_device(hwdep->dev); in snd_hwdep_free()
351 * snd_hwdep_new - create a new hwdep instance
354 * @device: the device index (zero-based)
358 * The callbacks (hwdep->ops) must be set on the returned instance
375 return -ENXIO; in snd_hwdep_new()
380 return -ENOMEM; in snd_hwdep_new()
382 init_waitqueue_head(&hwdep->open_wait); in snd_hwdep_new()
383 mutex_init(&hwdep->open_mutex); in snd_hwdep_new()
384 hwdep->card = card; in snd_hwdep_new()
385 hwdep->device = device; in snd_hwdep_new()
387 strscpy(hwdep->id, id, sizeof(hwdep->id)); in snd_hwdep_new()
389 err = snd_device_alloc(&hwdep->dev, card); in snd_hwdep_new()
395 dev_set_name(hwdep->dev, "hwC%iD%i", card->number, device); in snd_hwdep_new()
397 hwdep->oss_type = -1; in snd_hwdep_new()
414 snd_hwdep_free(device->device_data); in snd_hwdep_dev_free()
420 struct snd_hwdep *hwdep = device->device_data; in snd_hwdep_dev_register()
421 struct snd_card *card = hwdep->card; in snd_hwdep_dev_register()
424 guard(mutex)(&register_mutex); in snd_hwdep_dev_register()
425 if (snd_hwdep_search(card, hwdep->device)) in snd_hwdep_dev_register()
426 return -EBUSY; in snd_hwdep_dev_register()
427 list_add_tail(&hwdep->list, &snd_hwdep_devices); in snd_hwdep_dev_register()
429 hwdep->card, hwdep->device, in snd_hwdep_dev_register()
430 &snd_hwdep_f_ops, hwdep, hwdep->dev); in snd_hwdep_dev_register()
432 dev_err(hwdep->dev, "unable to register\n"); in snd_hwdep_dev_register()
433 list_del(&hwdep->list); in snd_hwdep_dev_register()
438 hwdep->ossreg = 0; in snd_hwdep_dev_register()
439 if (hwdep->oss_type >= 0) { in snd_hwdep_dev_register()
440 if (hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM && in snd_hwdep_dev_register()
441 hwdep->device) in snd_hwdep_dev_register()
442 dev_warn(hwdep->dev, in snd_hwdep_dev_register()
444 else if (snd_register_oss_device(hwdep->oss_type, in snd_hwdep_dev_register()
445 card, hwdep->device, in snd_hwdep_dev_register()
447 dev_warn(hwdep->dev, in snd_hwdep_dev_register()
450 hwdep->ossreg = 1; in snd_hwdep_dev_register()
458 struct snd_hwdep *hwdep = device->device_data; in snd_hwdep_dev_disconnect()
461 return -ENXIO; in snd_hwdep_dev_disconnect()
462 guard(mutex)(&register_mutex); in snd_hwdep_dev_disconnect()
463 if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) in snd_hwdep_dev_disconnect()
464 return -EINVAL; in snd_hwdep_dev_disconnect()
465 guard(mutex)(&hwdep->open_mutex); in snd_hwdep_dev_disconnect()
466 wake_up(&hwdep->open_wait); in snd_hwdep_dev_disconnect()
468 if (hwdep->ossreg) in snd_hwdep_dev_disconnect()
469 snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device); in snd_hwdep_dev_disconnect()
471 snd_unregister_device(hwdep->dev); in snd_hwdep_dev_disconnect()
472 list_del_init(&hwdep->list); in snd_hwdep_dev_disconnect()
486 guard(mutex)(&register_mutex); in snd_hwdep_proc_read()
488 snd_iprintf(buffer, "%02i-%02i: %s\n", in snd_hwdep_proc_read()
489 hwdep->card->number, hwdep->device, hwdep->name); in snd_hwdep_proc_read()
500 entry->c.text.read = snd_hwdep_proc_read; in snd_hwdep_proc_init()