~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/connector/cn_queue.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <linux/connector.h>
32
32
#include <linux/delay.h>
33
33
 
34
 
void cn_queue_wrapper(struct work_struct *work)
35
 
{
36
 
        struct cn_callback_entry *cbq =
37
 
                container_of(work, struct cn_callback_entry, work);
38
 
        struct cn_callback_data *d = &cbq->data;
39
 
        struct cn_msg *msg = NLMSG_DATA(nlmsg_hdr(d->skb));
40
 
        struct netlink_skb_parms *nsp = &NETLINK_CB(d->skb);
41
 
 
42
 
        d->callback(msg, nsp);
43
 
 
44
 
        kfree_skb(d->skb);
45
 
        d->skb = NULL;
46
 
 
47
 
        kfree(d->free);
48
 
}
49
 
 
50
34
static struct cn_callback_entry *
51
 
cn_queue_alloc_callback_entry(char *name, struct cb_id *id,
 
35
cn_queue_alloc_callback_entry(struct cn_queue_dev *dev, const char *name,
 
36
                              struct cb_id *id,
52
37
                              void (*callback)(struct cn_msg *, struct netlink_skb_parms *))
53
38
{
54
39
        struct cn_callback_entry *cbq;
59
44
                return NULL;
60
45
        }
61
46
 
 
47
        atomic_set(&cbq->refcnt, 1);
 
48
 
 
49
        atomic_inc(&dev->refcnt);
 
50
        cbq->pdev = dev;
 
51
 
62
52
        snprintf(cbq->id.name, sizeof(cbq->id.name), "%s", name);
63
53
        memcpy(&cbq->id.id, id, sizeof(struct cb_id));
64
 
        cbq->data.callback = callback;
65
 
 
66
 
        INIT_WORK(&cbq->work, &cn_queue_wrapper);
 
54
        cbq->callback = callback;
67
55
        return cbq;
68
56
}
69
57
 
70
 
static void cn_queue_free_callback(struct cn_callback_entry *cbq)
 
58
void cn_queue_release_callback(struct cn_callback_entry *cbq)
71
59
{
72
 
        flush_workqueue(cbq->pdev->cn_queue);
 
60
        if (!atomic_dec_and_test(&cbq->refcnt))
 
61
                return;
 
62
 
 
63
        atomic_dec(&cbq->pdev->refcnt);
73
64
        kfree(cbq);
74
65
}
75
66
 
78
69
        return ((i1->idx == i2->idx) && (i1->val == i2->val));
79
70
}
80
71
 
81
 
int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id,
 
72
int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name,
 
73
                          struct cb_id *id,
82
74
                          void (*callback)(struct cn_msg *, struct netlink_skb_parms *))
83
75
{
84
76
        struct cn_callback_entry *cbq, *__cbq;
85
77
        int found = 0;
86
78
 
87
 
        cbq = cn_queue_alloc_callback_entry(name, id, callback);
 
79
        cbq = cn_queue_alloc_callback_entry(dev, name, id, callback);
88
80
        if (!cbq)
89
81
                return -ENOMEM;
90
82
 
91
 
        atomic_inc(&dev->refcnt);
92
 
        cbq->pdev = dev;
93
 
 
94
83
        spin_lock_bh(&dev->queue_lock);
95
84
        list_for_each_entry(__cbq, &dev->queue_list, callback_entry) {
96
85
                if (cn_cb_equal(&__cbq->id.id, id)) {
103
92
        spin_unlock_bh(&dev->queue_lock);
104
93
 
105
94
        if (found) {
106
 
                cn_queue_free_callback(cbq);
107
 
                atomic_dec(&dev->refcnt);
 
95
                cn_queue_release_callback(cbq);
108
96
                return -EINVAL;
109
97
        }
110
98
 
129
117
        }
130
118
        spin_unlock_bh(&dev->queue_lock);
131
119
 
132
 
        if (found) {
133
 
                cn_queue_free_callback(cbq);
134
 
                atomic_dec(&dev->refcnt);
135
 
        }
 
120
        if (found)
 
121
                cn_queue_release_callback(cbq);
136
122
}
137
123
 
138
 
struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *nls)
 
124
struct cn_queue_dev *cn_queue_alloc_dev(const char *name, struct sock *nls)
139
125
{
140
126
        struct cn_queue_dev *dev;
141
127
 
150
136
 
151
137
        dev->nls = nls;
152
138
 
153
 
        dev->cn_queue = alloc_ordered_workqueue(dev->name, 0);
154
 
        if (!dev->cn_queue) {
155
 
                kfree(dev);
156
 
                return NULL;
157
 
        }
158
 
 
159
139
        return dev;
160
140
}
161
141
 
163
143
{
164
144
        struct cn_callback_entry *cbq, *n;
165
145
 
166
 
        flush_workqueue(dev->cn_queue);
167
 
        destroy_workqueue(dev->cn_queue);
168
 
 
169
146
        spin_lock_bh(&dev->queue_lock);
170
147
        list_for_each_entry_safe(cbq, n, &dev->queue_list, callback_entry)
171
148
                list_del(&cbq->callback_entry);