]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/event.c
genetlink: make multicast groups const, prevent abuse
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / event.c
CommitLineData
1da177e4
LT
1/*
2 * event.c - exporting ACPI events via procfs
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 *
7 */
8
9#include <linux/spinlock.h>
214f2c90 10#include <linux/export.h>
1da177e4
LT
11#include <linux/proc_fs.h>
12#include <linux/init.h>
13#include <linux/poll.h>
5a0e3ad6 14#include <linux/gfp.h>
1da177e4 15#include <acpi/acpi_drivers.h>
864bdfb9
ZR
16#include <net/netlink.h>
17#include <net/genetlink.h>
1da177e4 18
a192a958
LB
19#include "internal.h"
20
1da177e4 21#define _COMPONENT ACPI_SYSTEM_COMPONENT
f52fd66d 22ACPI_MODULE_NAME("event");
1da177e4 23
9ee85241 24/* ACPI notifier chain */
c8e773fa 25static BLOCKING_NOTIFIER_HEAD(acpi_chain_head);
9ee85241
ZR
26
27int acpi_notifier_call_chain(struct acpi_device *dev, u32 type, u32 data)
28{
29 struct acpi_bus_event event;
30
31 strcpy(event.device_class, dev->pnp.device_class);
32 strcpy(event.bus_id, dev->pnp.bus_id);
33 event.type = type;
34 event.data = data;
35 return (blocking_notifier_call_chain(&acpi_chain_head, 0, (void *)&event)
36 == NOTIFY_BAD) ? -EINVAL : 0;
37}
38EXPORT_SYMBOL(acpi_notifier_call_chain);
39
40int register_acpi_notifier(struct notifier_block *nb)
41{
42 return blocking_notifier_chain_register(&acpi_chain_head, nb);
43}
44EXPORT_SYMBOL(register_acpi_notifier);
45
46int unregister_acpi_notifier(struct notifier_block *nb)
47{
48 return blocking_notifier_chain_unregister(&acpi_chain_head, nb);
49}
50EXPORT_SYMBOL(unregister_acpi_notifier);
51
864bdfb9 52#ifdef CONFIG_NET
e13d8747 53static unsigned int acpi_event_seqnum;
864bdfb9
ZR
54struct acpi_genl_event {
55 acpi_device_class device_class;
56 char bus_id[15];
57 u32 type;
58 u32 data;
59};
60
61/* attributes of acpi_genl_family */
62enum {
63 ACPI_GENL_ATTR_UNSPEC,
64 ACPI_GENL_ATTR_EVENT, /* ACPI event info needed by user space */
65 __ACPI_GENL_ATTR_MAX,
66};
67#define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1)
68
69/* commands supported by the acpi_genl_family */
70enum {
71 ACPI_GENL_CMD_UNSPEC,
72 ACPI_GENL_CMD_EVENT, /* kernel->user notifications for ACPI events */
73 __ACPI_GENL_CMD_MAX,
74};
75#define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
76
9c977a45
ZR
77#define ACPI_GENL_FAMILY_NAME "acpi_event"
78#define ACPI_GENL_VERSION 0x01
79#define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group"
864bdfb9 80
2a94fe48
JB
81static const struct genl_multicast_group acpi_event_mcgrps[] = {
82 { .name = ACPI_GENL_MCAST_GROUP_NAME, },
83};
84
864bdfb9
ZR
85static struct genl_family acpi_event_genl_family = {
86 .id = GENL_ID_GENERATE,
9c977a45 87 .name = ACPI_GENL_FAMILY_NAME,
864bdfb9
ZR
88 .version = ACPI_GENL_VERSION,
89 .maxattr = ACPI_GENL_ATTR_MAX,
2a94fe48
JB
90 .mcgrps = acpi_event_mcgrps,
91 .n_mcgrps = ARRAY_SIZE(acpi_event_mcgrps),
864bdfb9
ZR
92};
93
962ce8ca
ZR
94int acpi_bus_generate_netlink_event(const char *device_class,
95 const char *bus_id,
864bdfb9
ZR
96 u8 type, int data)
97{
98 struct sk_buff *skb;
99 struct nlattr *attr;
100 struct acpi_genl_event *event;
101 void *msg_header;
102 int size;
103 int result;
104
105 /* allocate memory */
106 size = nla_total_size(sizeof(struct acpi_genl_event)) +
107 nla_total_size(0);
108
109 skb = genlmsg_new(size, GFP_ATOMIC);
110 if (!skb)
111 return -ENOMEM;
112
113 /* add the genetlink message header */
114 msg_header = genlmsg_put(skb, 0, acpi_event_seqnum++,
115 &acpi_event_genl_family, 0,
116 ACPI_GENL_CMD_EVENT);
117 if (!msg_header) {
118 nlmsg_free(skb);
119 return -ENOMEM;
120 }
121
122 /* fill the data */
123 attr =
124 nla_reserve(skb, ACPI_GENL_ATTR_EVENT,
125 sizeof(struct acpi_genl_event));
126 if (!attr) {
127 nlmsg_free(skb);
128 return -EINVAL;
129 }
130
131 event = nla_data(attr);
132 if (!event) {
133 nlmsg_free(skb);
134 return -EINVAL;
135 }
136
137 memset(event, 0, sizeof(struct acpi_genl_event));
138
962ce8ca
ZR
139 strcpy(event->device_class, device_class);
140 strcpy(event->bus_id, bus_id);
864bdfb9
ZR
141 event->type = type;
142 event->data = data;
143
144 /* send multicast genetlink message */
145 result = genlmsg_end(skb, msg_header);
146 if (result < 0) {
147 nlmsg_free(skb);
148 return result;
149 }
150
2a94fe48 151 genlmsg_multicast(&acpi_event_genl_family, skb, 0, 0, GFP_ATOMIC);
864bdfb9
ZR
152 return 0;
153}
864bdfb9 154
962ce8ca
ZR
155EXPORT_SYMBOL(acpi_bus_generate_netlink_event);
156
864bdfb9
ZR
157static int acpi_event_genetlink_init(void)
158{
2a94fe48 159 return genl_register_family(&acpi_event_genl_family);
864bdfb9
ZR
160}
161
162#else
3e069ee0
LB
163int acpi_bus_generate_netlink_event(const char *device_class,
164 const char *bus_id,
165 u8 type, int data)
864bdfb9
ZR
166{
167 return 0;
168}
864bdfb9 169
66baf327 170EXPORT_SYMBOL(acpi_bus_generate_netlink_event);
962ce8ca 171
864bdfb9
ZR
172static int acpi_event_genetlink_init(void)
173{
174 return -ENODEV;
175}
176#endif
177
1da177e4
LT
178static int __init acpi_event_init(void)
179{
1da177e4
LT
180 int error = 0;
181
1da177e4 182 if (acpi_disabled)
d550d98d 183 return 0;
1da177e4 184
864bdfb9
ZR
185 /* create genetlink for acpi event */
186 error = acpi_event_genetlink_init();
187 if (error)
188 printk(KERN_WARNING PREFIX
189 "Failed to create genetlink family for ACPI event\n");
864bdfb9 190 return 0;
1da177e4
LT
191}
192
864bdfb9 193fs_initcall(acpi_event_init);