scsi: pvscsi: check command descriptor ring buffer size (CVE-2016-4952)
[qemu.git] / util / notify.c
1 /*
2 * Notifier lists
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
14 */
15
16 #include "qemu/osdep.h"
17 #include "qemu-common.h"
18 #include "qemu/notify.h"
19
20 void notifier_list_init(NotifierList *list)
21 {
22 QLIST_INIT(&list->notifiers);
23 }
24
25 void notifier_list_add(NotifierList *list, Notifier *notifier)
26 {
27 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
28 }
29
30 void notifier_remove(Notifier *notifier)
31 {
32 QLIST_REMOVE(notifier, node);
33 }
34
35 void notifier_list_notify(NotifierList *list, void *data)
36 {
37 Notifier *notifier, *next;
38
39 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
40 notifier->notify(notifier, data);
41 }
42 }
43
44 void notifier_with_return_list_init(NotifierWithReturnList *list)
45 {
46 QLIST_INIT(&list->notifiers);
47 }
48
49 void notifier_with_return_list_add(NotifierWithReturnList *list,
50 NotifierWithReturn *notifier)
51 {
52 QLIST_INSERT_HEAD(&list->notifiers, notifier, node);
53 }
54
55 void notifier_with_return_remove(NotifierWithReturn *notifier)
56 {
57 QLIST_REMOVE(notifier, node);
58 }
59
60 int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
61 {
62 NotifierWithReturn *notifier, *next;
63 int ret = 0;
64
65 QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) {
66 ret = notifier->notify(notifier, data);
67 if (ret != 0) {
68 break;
69 }
70 }
71 return ret;
72 }