Skip to content

Commit 0bf2634

Browse files
crafcat7xiaoxiang781216
authored andcommitted
fs_lock:Reduce stack size
Signed-off-by: chenrun1 <[email protected]>
1 parent a69d3d7 commit 0bf2634

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

fs/vfs/fs_lock.c

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -548,27 +548,32 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
548548
{
549549
FAR struct file_lock_bucket_s *bucket;
550550
FAR struct file_lock_s *file_lock;
551-
char path[PATH_MAX];
551+
FAR char *path;
552552
int ret;
553553

554554
/* We need to get the unique identifier (Path) via filep */
555555

556+
path = lib_get_pathbuffer();
557+
if (path == NULL)
558+
{
559+
return -ENOMEM;
560+
}
561+
556562
ret = file_lock_get_path(filep, path);
557563
if (ret < 0)
558564
{
559-
return ret;
565+
goto out_free;
560566
}
561567

562568
/* Convert a flock to a posix lock */
563569

564570
ret = file_lock_normalize(filep, flock, flock);
565571
if (ret < 0)
566572
{
567-
return ret;
573+
goto out_free;
568574
}
569575

570576
nxmutex_lock(&g_protect_lock);
571-
572577
bucket = file_lock_find_bucket(path);
573578
if (bucket != NULL)
574579
{
@@ -602,6 +607,8 @@ int file_getlk(FAR struct file *filep, FAR struct flock *flock)
602607
flock->l_len = flock->l_end - flock->l_start + 1;
603608
}
604609

610+
out_free:
611+
lib_put_pathbuffer(path);
605612
return OK;
606613
}
607614

@@ -626,24 +633,30 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
626633
{
627634
FAR struct file_lock_bucket_s *bucket;
628635
FAR struct file_lock_s *file_lock;
636+
FAR char *path;
629637
struct flock request;
630-
char path[PATH_MAX];
631638
int ret;
632639

640+
path = lib_get_pathbuffer();
641+
if (path == NULL)
642+
{
643+
return -ENOMEM;
644+
}
645+
633646
/* We need to get the unique identifier (Path) via filep */
634647

635648
ret = file_lock_get_path(filep, path);
636649
if (ret < 0)
637650
{
638-
return ret;
651+
goto out_free;
639652
}
640653

641654
/* Convert a flock to a posix lock */
642655

643656
ret = file_lock_normalize(filep, flock, &request);
644657
if (ret < 0)
645658
{
646-
return ret;
659+
goto out_free;
647660
}
648661

649662
request.l_pid = getpid();
@@ -659,17 +672,17 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
659672

660673
if (request.l_type == F_UNLCK)
661674
{
662-
nxmutex_unlock(&g_protect_lock);
663-
return OK;
675+
ret = OK;
676+
goto out_lock;
664677
}
665678

666679
/* It looks like we didn't find a bucket, let's go create one */
667680

668681
bucket = file_lock_create_bucket(path);
669682
if (bucket == NULL)
670683
{
671-
nxmutex_unlock(&g_protect_lock);
672-
return -ENOMEM;
684+
ret = -ENOMEM;
685+
goto out_lock;
673686
}
674687
}
675688
else if (request.l_type != F_UNLCK)
@@ -711,7 +724,10 @@ int file_setlk(FAR struct file *filep, FAR struct flock *flock,
711724

712725
out:
713726
file_lock_delete_bucket(bucket, path);
727+
out_lock:
714728
nxmutex_unlock(&g_protect_lock);
729+
out_free:
730+
lib_put_pathbuffer(path);
715731
return ret;
716732
}
717733

@@ -731,26 +747,32 @@ void file_closelk(FAR struct file *filep)
731747
FAR struct file_lock_bucket_s *bucket;
732748
FAR struct file_lock_s *file_lock;
733749
FAR struct file_lock_s *temp;
734-
char path[PATH_MAX];
750+
FAR char *path;
735751
bool deleted = false;
736752
int ret;
737753

754+
path = lib_get_pathbuffer();
755+
if (path == NULL)
756+
{
757+
return;
758+
}
759+
738760
ret = file_lock_get_path(filep, path);
739761
if (ret < 0)
740762
{
741763
/* It isn't an error if fs doesn't support F_GETPATH, so we just end
742764
* it.
743765
*/
744766

745-
return;
767+
goto out;
746768
}
747769

748770
bucket = file_lock_find_bucket(path);
749771
if (bucket == NULL)
750772
{
751773
/* There is no bucket here, so we don't need to free it. */
752774

753-
return;
775+
goto out;
754776
}
755777

756778
nxmutex_lock(&g_protect_lock);
@@ -774,6 +796,8 @@ void file_closelk(FAR struct file *filep)
774796
}
775797

776798
nxmutex_unlock(&g_protect_lock);
799+
out:
800+
lib_put_pathbuffer(path);
777801
}
778802

779803
/****************************************************************************

0 commit comments

Comments
 (0)