linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
@ 2022-12-08 11:36 Yuan Can
  2022-12-08 11:53 ` Dan Carpenter
  2023-01-02 11:17 ` Miquel Raynal
  0 siblings, 2 replies; 4+ messages in thread
From: Yuan Can @ 2022-12-08 11:36 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, rafal, error27, linux-mtd; +Cc: yuancan

The parts needs to be freed with all its elements, otherwise it will be
leaked.

Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
Changes in v2:
- Add a new label err_free_parts and jumps to it when
  mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.

 drivers/mtd/parsers/tplink_safeloader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/parsers/tplink_safeloader.c b/drivers/mtd/parsers/tplink_safeloader.c
index f601e7bd8627..1c689dafca2a 100644
--- a/drivers/mtd/parsers/tplink_safeloader.c
+++ b/drivers/mtd/parsers/tplink_safeloader.c
@@ -91,7 +91,7 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 	buf = mtd_parser_tplink_safeloader_read_table(mtd);
 	if (!buf) {
 		err = -ENOENT;
-		goto err_out;
+		goto err_free_parts;
 	}
 
 	for (idx = 0, offset = TPLINK_SAFELOADER_DATA_OFFSET;
@@ -118,6 +118,8 @@ static int mtd_parser_tplink_safeloader_parse(struct mtd_info *mtd,
 err_free:
 	for (idx -= 1; idx >= 0; idx--)
 		kfree(parts[idx].name);
+err_free_parts:
+	kfree(parts);
 err_out:
 	return err;
 };
-- 
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
  2022-12-08 11:36 [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse() Yuan Can
@ 2022-12-08 11:53 ` Dan Carpenter
  2022-12-08 12:03   ` Yuan Can
  2023-01-02 11:17 ` Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-12-08 11:53 UTC (permalink / raw)
  To: Yuan Can; +Cc: miquel.raynal, richard, vigneshr, rafal, linux-mtd

On Thu, Dec 08, 2022 at 11:36:20AM +0000, Yuan Can wrote:
> The parts needs to be freed with all its elements, otherwise it will be
> leaked.
> 
> Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
> Changes in v2:
> - Add a new label err_free_parts and jumps to it when
>   mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.
> 

Reviewed-by: Dan Carpenter <error27@gmail.com>

This is the same code as v2 but with an explanation added.

I spotted that the explanation was missing but knew what the explanation
was so I didn't mention it.  For me, a lot of patches have minor flaws
and if I complained about everything the whole kernel development
process would grind to a halt.  Greg is more picky about explanations
for new versions because he has to deal with a lot of patches and
because he is trying to teach newbies how to follow the process.

Although minutes ago I just criticized someone else for not putting the
note under the cut off but that's because I had no idea why they were
resending.

Next time please avoid putting RESEND in the subject because that means
there was no changes because your patch was perfect as-is.  Instead put
v3:

v2: blah blah
v3: add this explanatory message.

But don't do that in this case, for now the patch is fine.  :P  I'm
just telling you the process for next time.

regards,
dan carpenter

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
  2022-12-08 11:53 ` Dan Carpenter
@ 2022-12-08 12:03   ` Yuan Can
  0 siblings, 0 replies; 4+ messages in thread
From: Yuan Can @ 2022-12-08 12:03 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: miquel.raynal, richard, vigneshr, rafal, linux-mtd


在 2022/12/8 19:53, Dan Carpenter 写道:
> On Thu, Dec 08, 2022 at 11:36:20AM +0000, Yuan Can wrote:
>> The parts needs to be freed with all its elements, otherwise it will be
>> leaked.
>>
>> Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
>> Signed-off-by: Yuan Can <yuancan@huawei.com>
>> ---
>> Changes in v2:
>> - Add a new label err_free_parts and jumps to it when
>>    mtd_parser_tplink_safeloader_read_table() failed to avoid leaking parts.
>>
> Reviewed-by: Dan Carpenter <error27@gmail.com>
>
> This is the same code as v2 but with an explanation added.
>
> I spotted that the explanation was missing but knew what the explanation
> was so I didn't mention it.  For me, a lot of patches have minor flaws
> and if I complained about everything the whole kernel development
> process would grind to a halt.  Greg is more picky about explanations
> for new versions because he has to deal with a lot of patches and
> because he is trying to teach newbies how to follow the process.
>
> Although minutes ago I just criticized someone else for not putting the
> note under the cut off but that's because I had no idea why they were
> resending.
>
> Next time please avoid putting RESEND in the subject because that means
> there was no changes because your patch was perfect as-is.  Instead put
> v3:
>
> v2: blah blah
> v3: add this explanatory message.
>
> But don't do that in this case, for now the patch is fine.  :P  I'm
> just telling you the process for next time.
Ok, thanks for your explanation!

-- 
Best regards,
Yuan Can


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
  2022-12-08 11:36 [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse() Yuan Can
  2022-12-08 11:53 ` Dan Carpenter
@ 2023-01-02 11:17 ` Miquel Raynal
  1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2023-01-02 11:17 UTC (permalink / raw)
  To: Yuan Can, miquel.raynal, richard, vigneshr, rafal, error27, linux-mtd

On Thu, 2022-12-08 at 11:36:20 UTC, Yuan Can wrote:
> The parts needs to be freed with all its elements, otherwise it will be
> leaked.
> 
> Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> Reviewed-by: Dan Carpenter <error27@gmail.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-02 11:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 11:36 [PATCH v2 RESEND] mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse() Yuan Can
2022-12-08 11:53 ` Dan Carpenter
2022-12-08 12:03   ` Yuan Can
2023-01-02 11:17 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).