@@ -283,7 +283,7 @@ static struct channel *ppp_find_channel(struct ppp_net *pn, int unit);
283
283
static int ppp_connect_channel (struct channel * pch , int unit );
284
284
static int ppp_disconnect_channel (struct channel * pch );
285
285
static void ppp_destroy_channel (struct channel * pch );
286
- static int unit_get (struct idr * p , void * ptr );
286
+ static int unit_get (struct idr * p , void * ptr , int min );
287
287
static int unit_set (struct idr * p , void * ptr , int n );
288
288
static void unit_put (struct idr * p , int n );
289
289
static void * unit_find (struct idr * p , int n );
@@ -1045,9 +1045,20 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
1045
1045
mutex_lock (& pn -> all_ppp_mutex );
1046
1046
1047
1047
if (unit < 0 ) {
1048
- ret = unit_get (& pn -> units_idr , ppp );
1048
+ ret = unit_get (& pn -> units_idr , ppp , 0 );
1049
1049
if (ret < 0 )
1050
1050
goto err ;
1051
+ if (!ifname_is_set ) {
1052
+ while (1 ) {
1053
+ snprintf (ppp -> dev -> name , IFNAMSIZ , "ppp%i" , ret );
1054
+ if (!__dev_get_by_name (ppp -> ppp_net , ppp -> dev -> name ))
1055
+ break ;
1056
+ unit_put (& pn -> units_idr , ret );
1057
+ ret = unit_get (& pn -> units_idr , ppp , ret + 1 );
1058
+ if (ret < 0 )
1059
+ goto err ;
1060
+ }
1061
+ }
1051
1062
} else {
1052
1063
/* Caller asked for a specific unit number. Fail with -EEXIST
1053
1064
* if unavailable. For backward compatibility, return -EEXIST
@@ -3378,9 +3389,9 @@ static int unit_set(struct idr *p, void *ptr, int n)
3378
3389
}
3379
3390
3380
3391
/* get new free unit number and associate pointer with it */
3381
- static int unit_get (struct idr * p , void * ptr )
3392
+ static int unit_get (struct idr * p , void * ptr , int min )
3382
3393
{
3383
- return idr_alloc (p , ptr , 0 , 0 , GFP_KERNEL );
3394
+ return idr_alloc (p , ptr , min , 0 , GFP_KERNEL );
3384
3395
}
3385
3396
3386
3397
/* put unit number back to a pool */
0 commit comments