* ==FILEVERSION 20041108==
*/
+#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/init.h>
#include <linux/list.h>
+#include <linux/devfs_fs_kernel.h>
#include <linux/netdevice.h>
#include <linux/poll.h>
#include <linux/ppp_defs.h>
#include <linux/rwsem.h>
#include <linux/stddef.h>
#include <linux/device.h>
-#include <linux/mutex.h>
#include <net/slhc_vj.h>
#include <asm/atomic.h>
void *ptr[CARDMAP_WIDTH];
};
static void *cardmap_get(struct cardmap *map, unsigned int nr);
-static int cardmap_set(struct cardmap **map, unsigned int nr, void *ptr);
+static void cardmap_set(struct cardmap **map, unsigned int nr, void *ptr);
static unsigned int cardmap_find_first_free(struct cardmap *map);
static void cardmap_destroy(struct cardmap **map);
/*
- * all_ppp_mutex protects the all_ppp_units mapping.
+ * all_ppp_sem protects the all_ppp_units mapping.
* It also ensures that finding a ppp unit in the all_ppp_units map
* and updating its file.refcnt field is atomic.
*/
-static DEFINE_MUTEX(all_ppp_mutex);
+static DECLARE_MUTEX(all_ppp_sem);
static struct cardmap *all_ppp_units;
static atomic_t ppp_unit_count = ATOMIC_INIT(0);
/* Attach to an existing ppp unit */
if (get_user(unit, p))
break;
- mutex_lock(&all_ppp_mutex);
+ down(&all_ppp_sem);
err = -ENXIO;
ppp = ppp_find_unit(unit);
if (ppp != 0) {
file->private_data = &ppp->file;
err = 0;
}
- mutex_unlock(&all_ppp_mutex);
+ up(&all_ppp_sem);
break;
case PPPIOCATTCHAN:
goto out_chrdev;
}
class_device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
+ err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
+ S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
+ if (err)
+ goto out_class;
}
out:
printk(KERN_ERR "failed to register PPP device (%d)\n", err);
return err;
+out_class:
+ class_device_destroy(ppp_class, MKDEV(PPP_MAJOR,0));
+ class_destroy(ppp_class);
out_chrdev:
unregister_chrdev(PPP_MAJOR, "ppp");
goto out;
kfree_skb(skb);
skb = ns;
}
+ else if (!pskb_may_pull(skb, skb->len))
+ goto err;
else
skb->ip_summed = CHECKSUM_NONE;
|| ppp->npmode[npi] != NPMODE_PASS) {
kfree_skb(skb);
} else {
- /* chop off protocol */
- skb_pull_rcsum(skb, 2);
+ skb_pull(skb, 2); /* chop off protocol */
+ skb_postpull_rcsum(skb, skb->data - 2, 2);
skb->dev = ppp->dev;
skb->protocol = htons(npindex_to_ethertype[npi]);
skb->mac.raw = skb->data;
{
struct channel *pch;
- pch = kzalloc(sizeof(struct channel), GFP_KERNEL);
+ pch = kmalloc(sizeof(struct channel), GFP_KERNEL);
if (pch == 0)
return -ENOMEM;
+ memset(pch, 0, sizeof(struct channel));
pch->ppp = NULL;
pch->chan = chan;
chan->ppp = pch;
int ret = -ENOMEM;
int i;
- ppp = kzalloc(sizeof(struct ppp), GFP_KERNEL);
+ ppp = kmalloc(sizeof(struct ppp), GFP_KERNEL);
if (!ppp)
goto out;
dev = alloc_netdev(0, "", ppp_setup);
if (!dev)
goto out1;
+ memset(ppp, 0, sizeof(struct ppp));
ppp->mru = PPP_MRU;
init_ppp_file(&ppp->file, INTERFACE);
dev->do_ioctl = ppp_net_ioctl;
ret = -EEXIST;
- mutex_lock(&all_ppp_mutex);
+ down(&all_ppp_sem);
if (unit < 0)
unit = cardmap_find_first_free(all_ppp_units);
else if (cardmap_get(all_ppp_units, unit) != NULL)
}
atomic_inc(&ppp_unit_count);
- ret = cardmap_set(&all_ppp_units, unit, ppp);
- if (ret != 0)
- goto out3;
-
- mutex_unlock(&all_ppp_mutex);
+ cardmap_set(&all_ppp_units, unit, ppp);
+ up(&all_ppp_sem);
*retp = 0;
return ppp;
-out3:
- atomic_dec(&ppp_unit_count);
out2:
- mutex_unlock(&all_ppp_mutex);
+ up(&all_ppp_sem);
free_netdev(dev);
out1:
kfree(ppp);
{
struct net_device *dev;
- mutex_lock(&all_ppp_mutex);
+ down(&all_ppp_sem);
ppp_lock(ppp);
dev = ppp->dev;
ppp->dev = NULL;
ppp->file.dead = 1;
ppp->owner = NULL;
wake_up_interruptible(&ppp->file.rwait);
- mutex_unlock(&all_ppp_mutex);
+ up(&all_ppp_sem);
}
/*
/*
* Locate an existing ppp unit.
- * The caller should have locked the all_ppp_mutex.
+ * The caller should have locked the all_ppp_sem.
*/
static struct ppp *
ppp_find_unit(int unit)
list_for_each_entry(pch, &new_channels, list) {
if (pch->file.index == unit) {
- list_move(&pch->list, &all_channels);
+ list_del(&pch->list);
+ list_add(&pch->list, &all_channels);
return pch;
}
}
int ret = -ENXIO;
int hdrlen;
- mutex_lock(&all_ppp_mutex);
+ down(&all_ppp_sem);
ppp = ppp_find_unit(unit);
if (ppp == 0)
goto out;
outl:
write_unlock_bh(&pch->upl);
out:
- mutex_unlock(&all_ppp_mutex);
+ up(&all_ppp_sem);
return ret;
}
cardmap_destroy(&all_ppp_units);
if (unregister_chrdev(PPP_MAJOR, "ppp") != 0)
printk(KERN_ERR "PPP: failed to unregister PPP device\n");
+ devfs_remove("ppp");
class_device_destroy(ppp_class, MKDEV(PPP_MAJOR, 0));
class_destroy(ppp_class);
}
return NULL;
}
-static int cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
+static void cardmap_set(struct cardmap **pmap, unsigned int nr, void *ptr)
{
struct cardmap *p;
int i;
if (p == NULL || (nr >> p->shift) >= CARDMAP_WIDTH) {
do {
/* need a new top level */
- struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
- if (!np)
- goto enomem;
+ struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL);
+ memset(np, 0, sizeof(*np));
np->ptr[0] = p;
if (p != NULL) {
np->shift = p->shift + CARDMAP_ORDER;
while (p->shift > 0) {
i = (nr >> p->shift) & CARDMAP_MASK;
if (p->ptr[i] == NULL) {
- struct cardmap *np = kzalloc(sizeof(*np), GFP_KERNEL);
- if (!np)
- goto enomem;
+ struct cardmap *np = kmalloc(sizeof(*np), GFP_KERNEL);
+ memset(np, 0, sizeof(*np));
np->shift = p->shift - CARDMAP_ORDER;
np->parent = p;
p->ptr[i] = np;
set_bit(i, &p->inuse);
else
clear_bit(i, &p->inuse);
- return 0;
- enomem:
- return -ENOMEM;
}
static unsigned int cardmap_find_first_free(struct cardmap *map)