Skip to content

Commit 64bf69d

Browse files
sgruszkadavem330
authored andcommitted
[ATM]: deregistration removes device from atm_devs list immediately
atm_dev_deregister() removes device from atm_dev list immediately to prevent operations on a phantom device. Decision to free device based only on ->refcnt now. Remove shutdown_atm_dev() use atm_dev_deregister() instead. atm_dev_deregister() also asynchronously releases all vccs related to device. Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl> Signed-off-by: Chas Williams <chas@cmf.nrl.navy.mil> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aaaaaad commit 64bf69d

6 files changed

Lines changed: 52 additions & 57 deletions

File tree

‎drivers/atm/atmtcp.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,31 +246,15 @@ static void atmtcp_c_close(struct atm_vcc *vcc)
246246
{
247247
struct atm_dev *atmtcp_dev;
248248
struct atmtcp_dev_data *dev_data;
249-
struct sock *s;
250-
struct hlist_node *node;
251-
struct atm_vcc *walk;
252-
int i;
253249

254250
atmtcp_dev = (struct atm_dev *) vcc->dev_data;
255251
dev_data = PRIV(atmtcp_dev);
256252
dev_data->vcc = NULL;
257253
if (dev_data->persist) return;
258254
atmtcp_dev->dev_data = NULL;
259255
kfree(dev_data);
260-
shutdown_atm_dev(atmtcp_dev);
256+
atm_dev_deregister(atmtcp_dev);
261257
vcc->dev_data = NULL;
262-
read_lock(&vcc_sklist_lock);
263-
for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
264-
struct hlist_head *head = &vcc_hash[i];
265-
266-
sk_for_each(s, node, head) {
267-
walk = atm_sk(s);
268-
if (walk->dev != atmtcp_dev)
269-
continue;
270-
wake_up(s->sk_sleep);
271-
}
272-
}
273-
read_unlock(&vcc_sklist_lock);
274258
module_put(THIS_MODULE);
275259
}
276260

@@ -450,7 +434,7 @@ static int atmtcp_remove_persistent(int itf)
450434
if (PRIV(dev)->vcc) return 0;
451435
kfree(dev_data);
452436
atm_dev_put(dev);
453-
shutdown_atm_dev(dev);
437+
atm_dev_deregister(dev);
454438
return 0;
455439
}
456440

‎drivers/usb/atm/usbatm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static int usbatm_atm_init(struct usbatm_data *instance)
879879

880880
fail:
881881
instance->atm_dev = NULL;
882-
shutdown_atm_dev(atm_dev); /* usbatm_atm_dev_close will eventually be called */
882+
atm_dev_deregister(atm_dev); /* usbatm_atm_dev_close will eventually be called */
883883
return ret;
884884
}
885885

@@ -1164,7 +1164,7 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
11641164

11651165
/* ATM finalize */
11661166
if (instance->atm_dev)
1167-
shutdown_atm_dev(instance->atm_dev);
1167+
atm_dev_deregister(instance->atm_dev);
11681168

11691169
usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
11701170
}

‎include/linux/atmdev.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ enum {
274274

275275

276276
enum {
277-
ATM_DF_CLOSE, /* close device when last VCC is closed */
277+
ATM_DF_REMOVED, /* device was removed from atm_devs list */
278278
};
279279

280280

@@ -415,7 +415,6 @@ struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
415415
int number,unsigned long *flags); /* number == -1: pick first available */
416416
struct atm_dev *atm_dev_lookup(int number);
417417
void atm_dev_deregister(struct atm_dev *dev);
418-
void shutdown_atm_dev(struct atm_dev *dev);
419418
void vcc_insert_socket(struct sock *sk);
420419

421420

@@ -457,11 +456,12 @@ static inline void atm_dev_hold(struct atm_dev *dev)
457456

458457
static inline void atm_dev_put(struct atm_dev *dev)
459458
{
460-
atomic_dec(&dev->refcnt);
461-
462-
if ((atomic_read(&dev->refcnt) == 1) &&
463-
test_bit(ATM_DF_CLOSE,&dev->flags))
464-
shutdown_atm_dev(dev);
459+
if (atomic_dec_and_test(&dev->refcnt)) {
460+
BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
461+
if (dev->ops->dev_close)
462+
dev->ops->dev_close(dev);
463+
kfree(dev);
464+
}
465465
}
466466

467467

‎net/atm/common.c‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@ void vcc_release_async(struct atm_vcc *vcc, int reply)
221221
EXPORT_SYMBOL(vcc_release_async);
222222

223223

224+
void atm_dev_release_vccs(struct atm_dev *dev)
225+
{
226+
int i;
227+
228+
write_lock_irq(&vcc_sklist_lock);
229+
for (i = 0; i < VCC_HTABLE_SIZE; i++) {
230+
struct hlist_head *head = &vcc_hash[i];
231+
struct hlist_node *node, *tmp;
232+
struct sock *s;
233+
struct atm_vcc *vcc;
234+
235+
sk_for_each_safe(s, node, tmp, head) {
236+
vcc = atm_sk(s);
237+
if (vcc->dev == dev) {
238+
vcc_release_async(vcc, -EPIPE);
239+
sk_del_node_init(s);
240+
}
241+
}
242+
}
243+
write_unlock_irq(&vcc_sklist_lock);
244+
}
245+
246+
224247
static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
225248
{
226249
int max_sdu;
@@ -332,12 +355,13 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
332355
return -EINVAL;
333356
if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
334357
return -EPERM;
335-
error = 0;
358+
error = -ENODEV;
336359
if (!try_module_get(dev->ops->owner))
337-
return -ENODEV;
360+
return error;
338361
vcc->dev = dev;
339362
write_lock_irq(&vcc_sklist_lock);
340-
if ((error = find_ci(vcc, &vpi, &vci))) {
363+
if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
364+
(error = find_ci(vcc, &vpi, &vci))) {
341365
write_unlock_irq(&vcc_sklist_lock);
342366
goto fail_module_put;
343367
}

‎net/atm/common.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ static inline void atm_proc_exit(void)
4747
/* SVC */
4848
int svc_change_qos(struct atm_vcc *vcc,struct atm_qos *qos);
4949

50+
void atm_dev_release_vccs(struct atm_dev *dev);
51+
5052
#endif

‎net/atm/resources.c‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct atm_dev *atm_dev_lookup(int number)
7070
return dev;
7171
}
7272

73+
7374
struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
7475
int number, unsigned long *flags)
7576
{
@@ -123,37 +124,22 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
123124

124125
void atm_dev_deregister(struct atm_dev *dev)
125126
{
126-
unsigned long warning_time;
127-
128-
atm_proc_dev_deregister(dev);
129-
127+
BUG_ON(test_bit(ATM_DF_REMOVED, &dev->flags));
128+
set_bit(ATM_DF_REMOVED, &dev->flags);
129+
130+
/*
131+
* if we remove current device from atm_devs list, new device
132+
* with same number can appear, such we need deregister proc,
133+
* release async all vccs and remove them from vccs list too
134+
*/
130135
down(&atm_dev_mutex);
131136
list_del(&dev->dev_list);
132137
up(&atm_dev_mutex);
133138

134-
warning_time = jiffies;
135-
while (atomic_read(&dev->refcnt) != 1) {
136-
msleep(250);
137-
if ((jiffies - warning_time) > 10 * HZ) {
138-
printk(KERN_EMERG "atm_dev_deregister: waiting for "
139-
"dev %d to become free. Usage count = %d\n",
140-
dev->number, atomic_read(&dev->refcnt));
141-
warning_time = jiffies;
142-
}
143-
}
144-
145-
kfree(dev);
146-
}
139+
atm_dev_release_vccs(dev);
140+
atm_proc_dev_deregister(dev);
147141

148-
void shutdown_atm_dev(struct atm_dev *dev)
149-
{
150-
if (atomic_read(&dev->refcnt) > 1) {
151-
set_bit(ATM_DF_CLOSE, &dev->flags);
152-
return;
153-
}
154-
if (dev->ops->dev_close)
155-
dev->ops->dev_close(dev);
156-
atm_dev_deregister(dev);
142+
atm_dev_put(dev);
157143
}
158144

159145

@@ -433,4 +419,3 @@ void *atm_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
433419
EXPORT_SYMBOL(atm_dev_register);
434420
EXPORT_SYMBOL(atm_dev_deregister);
435421
EXPORT_SYMBOL(atm_dev_lookup);
436-
EXPORT_SYMBOL(shutdown_atm_dev);

0 commit comments

Comments
 (0)