Skip to contentSkip to conversation

f2fs: avoid to use a NULL point in destroy_segment_manager

PATCH In review Chao Yu 2 participants 5 messages Nov 6, 2013

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: avoid to use a NULL point in destroy_segment_manager

A NULL point should avoid to be used in destroy_segment_manager after allocating memory fail for f2fs_sm_info.

---
 fs/f2fs/segment.c |    2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/segment.c +2 -0
index 3d4d5fc..ff363e6
@@ -1744,6 +1744,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
 void destroy_segment_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_sm_info *sm_info = SM_I(sbi);
+	if (!sm_info)
+		return;
 	destroy_dirty_segmap(sbi);
 	destroy_curseg(sbi);
 	destroy_free_segmap(sbi);
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 1 line · Chao Yu

A NULL point should avoid to be used in destroy_segment_manager after allocating memory fail for f2fs_sm_info.

Though without this patch it still can work well, because if it failed to allocate f2fs_sm_info, the sit_info, free_info... all were NULL, and the destory path(e.g. destroy_dirty_segmap) can deal with them well. IMO, this patch is still a good catch.

Regards,
Gu

Quoted 11 lines
---
 fs/f2fs/segment.c |    2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/segment.c +0 -0
index 3d4d5fc..ff363e6

fs/f2fs/segment.c static void destroy_sit_info(struct f2fs_sb_info *sbi) · line 1751

Quoted 8 lines
fs/f2fs/segment.c +2 -0
@@ -1744,6 +1744,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
 void destroy_segment_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_sm_info *sm_info = SM_I(sbi);
+	if (!sm_info)
+		return;
 	destroy_dirty_segmap(sbi);
 	destroy_curseg(sbi);
 	destroy_free_segmap(sbi);

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk

author
#2 lore raw

Hi Gu,

Quoted 7 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 06, 2013 11:41 AM
To: Chao Yu
Cc: ???; [email protected]; [email protected]; [email protected]; 谭姝
Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid to use a NULL point in destroy_segment_manager

Quoted 7 lines
Quoted 1 line · Chao Yu

A NULL point should avoid to be used in destroy_segment_manager after allocating memory fail for f2fs_sm_info.

Though without this patch it still can work well, because if it failed to allocate f2fs_sm_info, the sit_info, free_info... all were NULL, and the destory path(e.g. destroy_dirty_segmap) can deal with them well.

I think it could not work well. Without this patch we may got a segment fault in DIRTY_I(sbi) at the following code if it failed to allocate f2fs_sm_info memory(sbi->sm_info). Right?

static void destroy_dirty_segmap(struct f2fs_sb_info *sbi)

{
	struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
Quoted 11 lines

IMO, this patch is still a good catch.

Regards,
Gu

Quoted 6 lines
---
 fs/f2fs/segment.c |    2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines

fs/f2fs/segment.c static void destroy_sit_info(struct f2fs_sb_info *sbi) · line 1751

Quoted 13 lines
fs/f2fs/segment.c +2 -0
index 3d4d5fc..ff363e6
@@ -1744,6 +1744,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
 void destroy_segment_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_sm_info *sm_info = SM_I(sbi);
+	if (!sm_info)
+		return;
 	destroy_dirty_segmap(sbi);
 	destroy_curseg(sbi);
 	destroy_free_segmap(sbi);

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 13 lines · Chao Yu

Hi Gu,

Quoted 11 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 06, 2013 11:41 AM
To: Chao Yu
Cc: ???; [email protected]; [email protected]; [email protected]; 谭姝
Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid to use a NULL point in destroy_segment_manager

Quoted 1 line · Chao Yu

A NULL point should avoid to be used in destroy_segment_manager after allocating memory fail for f2fs_sm_info.

Quoted 7 lines
Quoted 3 lines

Though without this patch it still can work well, because if it failed to allocate f2fs_sm_info, the sit_info, free_info... all were NULL, and the destory path(e.g. destroy_dirty_segmap) can deal with them well.

I think it could not work well. Without this patch we may got a segment fault in DIRTY_I(sbi) at the following code if it failed to allocate f2fs_sm_info memory(sbi->sm_info). Right?

Yes, you're right. SIT_I generates sit_info from f2fs_sm_info. Sorry for my mistake.:(

Regards,
Gu

Quoted 32 lines

static void destroy_dirty_segmap(struct f2fs_sb_info *sbi)

{
	struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
Quoted 24 lines

IMO, this patch is still a good catch.

Regards,
Gu

Quoted 19 lines
---
 fs/f2fs/segment.c |    2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/segment.c +2 -0
index 3d4d5fc..ff363e6
@@ -1744,6 +1744,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
 void destroy_segment_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_sm_info *sm_info = SM_I(sbi);
+	if (!sm_info)
+		return;
 	destroy_dirty_segmap(sbi);
 	destroy_curseg(sbi);
 	destroy_free_segmap(sbi);
author
#4 lore raw

Hi Gu,

Thanks for your reviewing!

Regards
Yu

Quoted 71 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 06, 2013 1:16 PM
To: Chao Yu
Cc: '???'; [email protected]; [email protected]; [email protected]; '谭姝'
Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid to use a NULL point in destroy_segment_manager

Quoted 13 lines · Chao Yu

Hi Gu,

Quoted 11 lines

-----Original Message-----
From: Gu Zheng [mailto:[email protected]]
Sent: Wednesday, November 06, 2013 11:41 AM
To: Chao Yu
Cc: ???; [email protected]; [email protected]; [email protected]; 谭姝
Subject: Re: [f2fs-dev] [PATCH] f2fs: avoid to use a NULL point in destroy_segment_manager

Quoted 1 line · Chao Yu

A NULL point should avoid to be used in destroy_segment_manager after allocating memory fail for f2fs_sm_info.

Quoted 7 lines
Quoted 3 lines

Though without this patch it still can work well, because if it failed to allocate f2fs_sm_info, the sit_info, free_info... all were NULL, and the destory path(e.g. destroy_dirty_segmap) can deal with them well.

I think it could not work well. Without this patch we may got a segment fault in DIRTY_I(sbi) at the following code if it failed to allocate f2fs_sm_info memory(sbi->sm_info). Right?

Yes, you're right. SIT_I generates sit_info from f2fs_sm_info. Sorry for my mistake.:(

Regards,
Gu

Quoted 16 lines

static void destroy_dirty_segmap(struct f2fs_sb_info *sbi)

{
	struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
Quoted 11 lines

IMO, this patch is still a good catch.

Regards,
Gu

Quoted 6 lines
---
 fs/f2fs/segment.c |    2 ++
 1 file changed, 2 insertions(+)
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
fs/f2fs/segment.c +0 -0
index 3d4d5fc..ff363e6
@@ -1744,6 +1744,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
Quoted 8 lines

fs/f2fs/segment.c static void destroy_sit_info(struct f2fs_sb_info *sbi) · line 1751

Quoted 8 lines
fs/f2fs/segment.c +2 -0
 void destroy_segment_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_sm_info *sm_info = SM_I(sbi);
+	if (!sm_info)
+		return;
 	destroy_dirty_segmap(sbi);
 	destroy_curseg(sbi);
 	destroy_free_segmap(sbi);

=