Commit 506b99cb authored by Chas Williams's avatar Chas Williams Committed by David S. Miller

[ATM]: change atm address functions to use list_add

Signed-off-by: default avatarChas Williams <chas@cmf.nrl.navy.mil>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ce3074f4
...@@ -313,7 +313,7 @@ struct atm_vcc { ...@@ -313,7 +313,7 @@ struct atm_vcc {
struct atm_dev_addr { struct atm_dev_addr {
struct sockaddr_atmsvc addr; /* ATM address */ struct sockaddr_atmsvc addr; /* ATM address */
struct atm_dev_addr *next; /* next address */ struct list_head entry; /* next address */
}; };
struct atm_dev { struct atm_dev {
...@@ -325,7 +325,7 @@ struct atm_dev { ...@@ -325,7 +325,7 @@ struct atm_dev {
void *dev_data; /* per-device data */ void *dev_data; /* per-device data */
void *phy_data; /* private PHY date */ void *phy_data; /* private PHY date */
unsigned long flags; /* device flags (ATM_DF_*) */ unsigned long flags; /* device flags (ATM_DF_*) */
struct atm_dev_addr *local; /* local ATM addresses */ struct list_head local; /* local ATM addresses */
unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */ unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
struct atm_cirange ci_range; /* VPI/VCI range */ struct atm_cirange ci_range; /* VPI/VCI range */
struct k_atm_dev_stats stats; /* statistics */ struct k_atm_dev_stats stats; /* statistics */
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
#include <linux/atm.h> #include <linux/atm.h>
#include <linux/atmdev.h> #include <linux/atmdev.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -11,127 +10,121 @@ ...@@ -11,127 +10,121 @@
#include "signaling.h" #include "signaling.h"
#include "addr.h" #include "addr.h"
static int check_addr(struct sockaddr_atmsvc *addr) static int check_addr(struct sockaddr_atmsvc *addr)
{ {
int i; int i;
if (addr->sas_family != AF_ATMSVC) return -EAFNOSUPPORT; if (addr->sas_family != AF_ATMSVC)
return -EAFNOSUPPORT;
if (!*addr->sas_addr.pub) if (!*addr->sas_addr.pub)
return *addr->sas_addr.prv ? 0 : -EINVAL; return *addr->sas_addr.prv ? 0 : -EINVAL;
for (i = 1; i < ATM_E164_LEN+1; i++) /* make sure it's \0-terminated */ for (i = 1; i < ATM_E164_LEN + 1; i++) /* make sure it's \0-terminated */
if (!addr->sas_addr.pub[i]) return 0; if (!addr->sas_addr.pub[i])
return 0;
return -EINVAL; return -EINVAL;
} }
static int identical(struct sockaddr_atmsvc *a, struct sockaddr_atmsvc *b)
static int identical(struct sockaddr_atmsvc *a,struct sockaddr_atmsvc *b)
{ {
if (*a->sas_addr.prv) if (*a->sas_addr.prv)
if (memcmp(a->sas_addr.prv,b->sas_addr.prv,ATM_ESA_LEN)) if (memcmp(a->sas_addr.prv, b->sas_addr.prv, ATM_ESA_LEN))
return 0; return 0;
if (!*a->sas_addr.pub) return !*b->sas_addr.pub; if (!*a->sas_addr.pub)
if (!*b->sas_addr.pub) return 0; return !*b->sas_addr.pub;
return !strcmp(a->sas_addr.pub,b->sas_addr.pub); if (!*b->sas_addr.pub)
return 0;
return !strcmp(a->sas_addr.pub, b->sas_addr.pub);
} }
static void notify_sigd(struct atm_dev *dev) static void notify_sigd(struct atm_dev *dev)
{ {
struct sockaddr_atmpvc pvc; struct sockaddr_atmpvc pvc;
pvc.sap_addr.itf = dev->number; pvc.sap_addr.itf = dev->number;
sigd_enq(NULL,as_itf_notify,NULL,&pvc,NULL); sigd_enq(NULL, as_itf_notify, NULL, &pvc, NULL);
} }
void atm_reset_addr(struct atm_dev *dev) void atm_reset_addr(struct atm_dev *dev)
{ {
unsigned long flags; unsigned long flags;
struct atm_dev_addr *this; struct atm_dev_addr *this, *p;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
while (dev->local) { list_for_each_entry_safe(this, p, &dev->local, entry)
this = dev->local; kfree(this);
dev->local = this->next;
kfree(this);
}
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
notify_sigd(dev); notify_sigd(dev);
} }
int atm_add_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
int atm_add_addr(struct atm_dev *dev,struct sockaddr_atmsvc *addr)
{ {
unsigned long flags; unsigned long flags;
struct atm_dev_addr **walk; struct atm_dev_addr *this;
int error; int error;
error = check_addr(addr); error = check_addr(addr);
if (error) if (error)
return error; return error;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
for (walk = &dev->local; *walk; walk = &(*walk)->next) list_for_each_entry(this, &dev->local, entry) {
if (identical(&(*walk)->addr,addr)) { if (identical(&this->addr, addr)) {
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
return -EEXIST; return -EEXIST;
} }
*walk = kmalloc(sizeof(struct atm_dev_addr), GFP_ATOMIC); }
if (!*walk) { this = kmalloc(sizeof(struct atm_dev_addr), GFP_ATOMIC);
if (!this) {
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
return -ENOMEM; return -ENOMEM;
} }
(*walk)->addr = *addr; this->addr = *addr;
(*walk)->next = NULL; list_add(&this->entry, &dev->local);
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
notify_sigd(dev); notify_sigd(dev);
return 0; return 0;
} }
int atm_del_addr(struct atm_dev *dev, struct sockaddr_atmsvc *addr)
int atm_del_addr(struct atm_dev *dev,struct sockaddr_atmsvc *addr)
{ {
unsigned long flags; unsigned long flags;
struct atm_dev_addr **walk,*this; struct atm_dev_addr *this;
int error; int error;
error = check_addr(addr); error = check_addr(addr);
if (error) if (error)
return error; return error;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
for (walk = &dev->local; *walk; walk = &(*walk)->next) list_for_each_entry(this, &dev->local, entry) {
if (identical(&(*walk)->addr,addr)) break; if (identical(&this->addr, addr)) {
if (!*walk) { list_del(&this->entry);
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
return -ENOENT; kfree(this);
notify_sigd(dev);
return 0;
}
} }
this = *walk;
*walk = this->next;
kfree(this);
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
notify_sigd(dev); return -ENOENT;
return 0;
} }
int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
int atm_get_addr(struct atm_dev *dev,struct sockaddr_atmsvc __user *buf,int size) int size)
{ {
unsigned long flags; unsigned long flags;
struct atm_dev_addr *walk; struct atm_dev_addr *this;
int total = 0, error; int total = 0, error;
struct sockaddr_atmsvc *tmp_buf, *tmp_bufp; struct sockaddr_atmsvc *tmp_buf, *tmp_bufp;
spin_lock_irqsave(&dev->lock, flags); spin_lock_irqsave(&dev->lock, flags);
for (walk = dev->local; walk; walk = walk->next) list_for_each_entry(this, &dev->local, entry)
total += sizeof(struct sockaddr_atmsvc); total += sizeof(struct sockaddr_atmsvc);
tmp_buf = tmp_bufp = kmalloc(total, GFP_ATOMIC); tmp_buf = tmp_bufp = kmalloc(total, GFP_ATOMIC);
if (!tmp_buf) { if (!tmp_buf) {
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
return -ENOMEM; return -ENOMEM;
} }
for (walk = dev->local; walk; walk = walk->next) list_for_each_entry(this, &dev->local, entry)
memcpy(tmp_bufp++, &walk->addr, sizeof(struct sockaddr_atmsvc)); memcpy(tmp_bufp++, &this->addr, sizeof(struct sockaddr_atmsvc));
spin_unlock_irqrestore(&dev->lock, flags); spin_unlock_irqrestore(&dev->lock, flags);
error = total > size ? -E2BIG : total; error = total > size ? -E2BIG : total;
if (copy_to_user(buf, tmp_buf, total < size ? total : size)) if (copy_to_user(buf, tmp_buf, total < size ? total : size))
......
...@@ -38,6 +38,7 @@ static struct atm_dev *__alloc_atm_dev(const char *type) ...@@ -38,6 +38,7 @@ static struct atm_dev *__alloc_atm_dev(const char *type)
dev->signal = ATM_PHY_SIG_UNKNOWN; dev->signal = ATM_PHY_SIG_UNKNOWN;
dev->link_rate = ATM_OC3_PCR; dev->link_rate = ATM_OC3_PCR;
spin_lock_init(&dev->lock); spin_lock_init(&dev->lock);
INIT_LIST_HEAD(&dev->local);
return dev; return dev;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment