static void button_hotplug_work(struct work_struct *work) { struct bh_event *event = container_of(work, struct bh_event, work); int ret = 0; event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL); if (!event->skb) goto out_free_event; ret = bh_event_add_var(event, 0, "%s@", event->action); if (ret) goto out_free_skb; ret = button_hotplug_fill_event(event); if (ret) goto out_free_skb; NETLINK_CB(event->skb).dst_group = 1; broadcast_uevent(event->skb, 0, 1, GFP_KERNEL); out_free_skb: if (ret) { BH_ERR("work error %d\n", ret); kfree_skb(event->skb); } out_free_event: kfree(event); }
static int bh_event_add_var(struct bh_event *event, int argv, const char *format, ...) { static char buf[128]; char *s; va_list args; int len; if (argv) return 0; va_start(args, format); len = vsnprintf(buf, sizeof(buf), format, args); va_end(args); if (len >= sizeof(buf)) { BH_ERR("buffer size too small\n"); WARN_ON(1); return -ENOMEM; } s = skb_put(event->skb, len + 1); strcpy(s, buf); BH_DBG("added variable '%s'\n", s); return 0; }