Skip to contentSkip to conversation

mm/block: logical error fix to avoid memory leak

PATCH Applied Liu, Changcheng 4 participants 6 messages Dec 14, 2017 – Dec 18, 2017 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/block: logical error fix to avoid memory leak

function: mmc_ext_csd_open
{
+-- 33 lines: struct mmc_card *card = inode->i_private;--

    if (n != EXT_CSD_STR_LEN) {
        err = -EINVAL;
        goto out_free;  //==>should free ext_csd firstly.
    }
+--  2 lines: filp->private_data = buf;------------------
    kfree(ext_csd);
    return 0;

out_free:

    kfree(buf);
    return err;
}
drivers/mmc/core/block.c +1 -0
index ccfa98a..b737a95 100644
@@ -2623,6 +2623,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
 
 	if (n != EXT_CSD_STR_LEN) {
 		err = -EINVAL;
+		kfree(ext_csd);
 		goto out_free;
 	}
 
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Changcheng

function: mmc_ext_csd_open
{
+-- 33 lines: struct mmc_card *card = inode->i_private;--

    if (n != EXT_CSD_STR_LEN) {
        err = -EINVAL;
        goto out_free;  //==>should free ext_csd firstly.
    }
+--  2 lines: filp->private_data = buf;------------------
    kfree(ext_csd);
    return 0;
Quoted 6 lines

out_free:

    kfree(buf);
    return err;
}

Well I don't really follow the commit message, but the patch is OK. How about this:

mmc: block: fix logical error to avoid memory leak

If the MMC_DRV_OP_GET_EXT_CSD request completes successfully, then ext_csd must be freed, but in one case it was not. Fix that.

Otherwise:

Quoted 14 lines
drivers/mmc/core/block.c +1 -0
index ccfa98a..b737a95 100644
@@ -2623,6 +2623,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
 
 	if (n != EXT_CSD_STR_LEN) {
 		err = -EINVAL;
+		kfree(ext_csd);
 		goto out_free;
 	}
 
#2 lore raw

Re: [PATCH v2] mmc: block: fix logical error to avoid memory leak

If the MMC_DRV_OP_GET_EXT_CSD request completes successfully, then ext_csd must be freed, but in one case it was not. Fix that.

drivers/mmc/core/block.c +1 -0
index ccfa98a..b737a95 100644
@@ -2623,6 +2623,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
 
 	if (n != EXT_CSD_STR_LEN) {
 		err = -EINVAL;
+		kfree(ext_csd);
 		goto out_free;
 	}
 
Signature · 1 line
2.7.4
Applied
#4 lore raw

Re: [PATCH v2] mmc: block: fix logical error to avoid memory leak

In reply to Liu, Changcheng
Quoted 4 lines · Changcheng

If the MMC_DRV_OP_GET_EXT_CSD request completes successfully, then ext_csd must be freed, but in one case it was not. Fix that.

Thanks, applied for next!

Next time, you may please preserve acks from previous versions, especially if the reviewer (Adrian in this case) says so.

Kind regards
Uffe

Quoted 15 lines
drivers/mmc/core/block.c +1 -1
index ccfa98a..b737a95 100644
@@ -2623,6 +2623,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
 
        if (n != EXT_CSD_STR_LEN) {
                err = -EINVAL;
+               kfree(ext_csd);
                goto out_free;
        }
 
--

2.7.4

#5 lore raw

Re: [PATCH v2] mmc: block: fix logical error to avoid memory leak

Hi Uffe,
Thx for your guide. I'm on the way to work with community. I'll
follow your suggestion next time.

B.R.
Changcheng

Quoted 29 lines · Ulf Hansson
Quoted 4 lines · Changcheng

If the MMC_DRV_OP_GET_EXT_CSD request completes successfully, then ext_csd must be freed, but in one case it was not. Fix that.

Thanks, applied for next!

Next time, you may please preserve acks from previous versions, especially if the reviewer (Adrian in this case) says so.

Kind regards
Uffe

Quoted 15 lines
drivers/mmc/core/block.c +1 -1
index ccfa98a..b737a95 100644
@@ -2623,6 +2623,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
 
        if (n != EXT_CSD_STR_LEN) {
                err = -EINVAL;
+               kfree(ext_csd);
                goto out_free;
        }
 
--

2.7.4