@@ -529,24 +529,17 @@ static void restore_nameidata(void)
529
529
kfree (now -> stack );
530
530
}
531
531
532
- static int __nd_alloc_stack (struct nameidata * nd )
532
+ static bool nd_alloc_stack (struct nameidata * nd )
533
533
{
534
534
struct saved * p ;
535
535
536
- if (nd -> flags & LOOKUP_RCU ) {
537
- p = kmalloc_array (MAXSYMLINKS , sizeof (struct saved ),
538
- GFP_ATOMIC );
539
- if (unlikely (!p ))
540
- return - ECHILD ;
541
- } else {
542
- p = kmalloc_array (MAXSYMLINKS , sizeof (struct saved ),
543
- GFP_KERNEL );
544
- if (unlikely (!p ))
545
- return - ENOMEM ;
546
- }
536
+ p = kmalloc_array (MAXSYMLINKS , sizeof (struct saved ),
537
+ nd -> flags & LOOKUP_RCU ? GFP_ATOMIC : GFP_KERNEL );
538
+ if (unlikely (!p ))
539
+ return false;
547
540
memcpy (p , nd -> internal , sizeof (nd -> internal ));
548
541
nd -> stack = p ;
549
- return 0 ;
542
+ return true ;
550
543
}
551
544
552
545
/**
@@ -1573,30 +1566,28 @@ static inline int may_lookup(struct nameidata *nd)
1573
1566
1574
1567
static int reserve_stack (struct nameidata * nd , struct path * link , unsigned seq )
1575
1568
{
1576
- int error ;
1577
-
1578
1569
if (unlikely (nd -> total_link_count ++ >= MAXSYMLINKS ))
1579
1570
return - ELOOP ;
1580
1571
1581
1572
if (likely (nd -> depth != EMBEDDED_LEVELS ))
1582
1573
return 0 ;
1583
1574
if (likely (nd -> stack != nd -> internal ))
1584
1575
return 0 ;
1585
-
1586
- error = __nd_alloc_stack (nd );
1587
- if (likely (!error ))
1576
+ if (likely (nd_alloc_stack (nd )))
1588
1577
return 0 ;
1589
- if (error == - ECHILD ) {
1590
- // we must grab link first
1578
+
1579
+ if (nd -> flags & LOOKUP_RCU ) {
1580
+ // we need to grab link before we do unlazy. And we can't skip
1581
+ // unlazy even if we fail to grab the link - cleanup needs it
1591
1582
bool grabbed_link = legitimize_path (nd , link , seq );
1592
- // ... and we must unlazy to be able to clean up
1593
- error = unlazy_walk (nd );
1594
- if ( unlikely (! grabbed_link ))
1595
- error = - ECHILD ;
1596
- if (! error )
1597
- error = __nd_alloc_stack ( nd ) ;
1583
+
1584
+ if ( unlazy_walk (nd ) != 0 || ! grabbed_link )
1585
+ return - ECHILD ;
1586
+
1587
+ if (nd_alloc_stack ( nd ) )
1588
+ return 0 ;
1598
1589
}
1599
- return error ;
1590
+ return - ENOMEM ;
1600
1591
}
1601
1592
1602
1593
enum {WALK_TRAILING = 1 , WALK_MORE = 2 , WALK_NOFOLLOW = 4 };
0 commit comments