diff options
Diffstat (limited to 'drivers/net/ppp_generic.c')
-rw-r--r-- | drivers/net/ppp_generic.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c index 06b448285eb5..7b2728b8f1b7 100644 --- a/drivers/net/ppp_generic.c +++ b/drivers/net/ppp_generic.c | |||
@@ -250,6 +250,7 @@ static int ppp_connect_channel(struct channel *pch, int unit); | |||
250 | static int ppp_disconnect_channel(struct channel *pch); | 250 | static int ppp_disconnect_channel(struct channel *pch); |
251 | static void ppp_destroy_channel(struct channel *pch); | 251 | static void ppp_destroy_channel(struct channel *pch); |
252 | static int unit_get(struct idr *p, void *ptr); | 252 | static int unit_get(struct idr *p, void *ptr); |
253 | static int unit_set(struct idr *p, void *ptr, int n); | ||
253 | static void unit_put(struct idr *p, int n); | 254 | static void unit_put(struct idr *p, int n); |
254 | static void *unit_find(struct idr *p, int n); | 255 | static void *unit_find(struct idr *p, int n); |
255 | 256 | ||
@@ -2432,11 +2433,18 @@ ppp_create_interface(int unit, int *retp) | |||
2432 | } else { | 2433 | } else { |
2433 | if (unit_find(&ppp_units_idr, unit)) | 2434 | if (unit_find(&ppp_units_idr, unit)) |
2434 | goto out2; /* unit already exists */ | 2435 | goto out2; /* unit already exists */ |
2435 | else { | 2436 | /* |
2436 | /* darn, someone is cheating us? */ | 2437 | * if caller need a specified unit number |
2437 | *retp = -EINVAL; | 2438 | * lets try to satisfy him, otherwise -- |
2439 | * he should better ask us for new unit number | ||
2440 | * | ||
2441 | * NOTE: yes I know that returning EEXIST it's not | ||
2442 | * fair but at least pppd will ask us to allocate | ||
2443 | * new unit in this case so user is happy :) | ||
2444 | */ | ||
2445 | unit = unit_set(&ppp_units_idr, ppp, unit); | ||
2446 | if (unit < 0) | ||
2438 | goto out2; | 2447 | goto out2; |
2439 | } | ||
2440 | } | 2448 | } |
2441 | 2449 | ||
2442 | /* Initialize the new ppp unit */ | 2450 | /* Initialize the new ppp unit */ |
@@ -2677,14 +2685,37 @@ static void __exit ppp_cleanup(void) | |||
2677 | * by holding all_ppp_mutex | 2685 | * by holding all_ppp_mutex |
2678 | */ | 2686 | */ |
2679 | 2687 | ||
2688 | /* associate pointer with specified number */ | ||
2689 | static int unit_set(struct idr *p, void *ptr, int n) | ||
2690 | { | ||
2691 | int unit, err; | ||
2692 | |||
2693 | again: | ||
2694 | if (!idr_pre_get(p, GFP_KERNEL)) { | ||
2695 | printk(KERN_ERR "PPP: No free memory for idr\n"); | ||
2696 | return -ENOMEM; | ||
2697 | } | ||
2698 | |||
2699 | err = idr_get_new_above(p, ptr, n, &unit); | ||
2700 | if (err == -EAGAIN) | ||
2701 | goto again; | ||
2702 | |||
2703 | if (unit != n) { | ||
2704 | idr_remove(p, unit); | ||
2705 | return -EINVAL; | ||
2706 | } | ||
2707 | |||
2708 | return unit; | ||
2709 | } | ||
2710 | |||
2680 | /* get new free unit number and associate pointer with it */ | 2711 | /* get new free unit number and associate pointer with it */ |
2681 | static int unit_get(struct idr *p, void *ptr) | 2712 | static int unit_get(struct idr *p, void *ptr) |
2682 | { | 2713 | { |
2683 | int unit, err; | 2714 | int unit, err; |
2684 | 2715 | ||
2685 | again: | 2716 | again: |
2686 | if (idr_pre_get(p, GFP_KERNEL) == 0) { | 2717 | if (!idr_pre_get(p, GFP_KERNEL)) { |
2687 | printk(KERN_ERR "Out of memory expanding drawable idr\n"); | 2718 | printk(KERN_ERR "PPP: No free memory for idr\n"); |
2688 | return -ENOMEM; | 2719 | return -ENOMEM; |
2689 | } | 2720 | } |
2690 | 2721 | ||