All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] Resubmit mtd: mtdoops: fix for a potential memory leak in mtdoops_notify_remove
Date: Tue, 13 Aug 2013 11:50:43 -0300	[thread overview]
Message-ID: <20130813145041.GB2359@localhost> (raw)
In-Reply-To: <1376369315-5170-1-git-send-email-nilanjan.roychowdhury@gmail.com>

Hi Nilanjan,

On Mon, Aug 12, 2013 at 09:48:35PM -0700, Nilanjan Roychowdhury wrote:
> we are allocating cxt->oops_page_used using vmalloc in mtdoops_notify_add for
> every mtd_info addition but not freeing it in mtdoops_notify_remove. Also care is
> taken so that we do not free the same pointer again in module remove.
> 

Could you re-send this with a better commit message?

In particular we'd like to see why you're doing this, explaining
how the current implementation implies a possible leak, explaining under
what circumstance this leak.

I think it would be great if you could test the patch and also add
some information about the testing scenario.

Please note the subject should be "[PATCH v2] mtd: ...", with a
proper patch version number. The next patch will be v3 (and so on) which
should be stated in the subject.

Also...

> Signed-off-by: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
> ---

In this place (between the "---" and the diffstat) you can put some
changelog information, like this:

Changes from v2:
 * Did this and that.

Changes from v1:
 * Added check to vfree() in remove function as suggested by Ezequiel.

>  drivers/mtd/mtdoops.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> index 97bb8f6..4b8b621 100644
> --- a/drivers/mtd/mtdoops.c
> +++ b/drivers/mtd/mtdoops.c
> @@ -386,6 +386,8 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)
>  	cxt->mtd = NULL;
>  	flush_work(&cxt->work_erase);
>  	flush_work(&cxt->work_write);
> +	vfree(cxt->oops_page_used);
> +	cxt->oops_page_used = NULL;
>  }
>  
>  
> @@ -439,7 +441,8 @@ static void __exit mtdoops_exit(void)
>  
>  	unregister_mtd_user(&mtdoops_notifier);
>  	vfree(cxt->oops_buf);
> -	vfree(cxt->oops_page_used);
> +	if (cxt->oops_page_used)
> +		vfree(cxt->oops_page_used);
>  }
>  
>  
> -- 
> 1.7.9.5
> 

Thanks!
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

WARNING: multiple messages have this Message-ID (diff)
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
Cc: linux-mtd@lists.infradead.org,
	David Woodhouse <dwmw2@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] Resubmit mtd: mtdoops: fix for a potential memory leak in mtdoops_notify_remove
Date: Tue, 13 Aug 2013 11:50:43 -0300	[thread overview]
Message-ID: <20130813145041.GB2359@localhost> (raw)
In-Reply-To: <1376369315-5170-1-git-send-email-nilanjan.roychowdhury@gmail.com>

Hi Nilanjan,

On Mon, Aug 12, 2013 at 09:48:35PM -0700, Nilanjan Roychowdhury wrote:
> we are allocating cxt->oops_page_used using vmalloc in mtdoops_notify_add for
> every mtd_info addition but not freeing it in mtdoops_notify_remove. Also care is
> taken so that we do not free the same pointer again in module remove.
> 

Could you re-send this with a better commit message?

In particular we'd like to see why you're doing this, explaining
how the current implementation implies a possible leak, explaining under
what circumstance this leak.

I think it would be great if you could test the patch and also add
some information about the testing scenario.

Please note the subject should be "[PATCH v2] mtd: ...", with a
proper patch version number. The next patch will be v3 (and so on) which
should be stated in the subject.

Also...

> Signed-off-by: Nilanjan Roychowdhury <nilanjan.roychowdhury@gmail.com>
> ---

In this place (between the "---" and the diffstat) you can put some
changelog information, like this:

Changes from v2:
 * Did this and that.

Changes from v1:
 * Added check to vfree() in remove function as suggested by Ezequiel.

>  drivers/mtd/mtdoops.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> index 97bb8f6..4b8b621 100644
> --- a/drivers/mtd/mtdoops.c
> +++ b/drivers/mtd/mtdoops.c
> @@ -386,6 +386,8 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)
>  	cxt->mtd = NULL;
>  	flush_work(&cxt->work_erase);
>  	flush_work(&cxt->work_write);
> +	vfree(cxt->oops_page_used);
> +	cxt->oops_page_used = NULL;
>  }
>  
>  
> @@ -439,7 +441,8 @@ static void __exit mtdoops_exit(void)
>  
>  	unregister_mtd_user(&mtdoops_notifier);
>  	vfree(cxt->oops_buf);
> -	vfree(cxt->oops_page_used);
> +	if (cxt->oops_page_used)
> +		vfree(cxt->oops_page_used);
>  }
>  
>  
> -- 
> 1.7.9.5
> 

Thanks!
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-08-13 14:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-13  4:48 [PATCH 1/1] Resubmit mtd: mtdoops: fix for a potential memory leak in mtdoops_notify_remove Nilanjan Roychowdhury
2013-08-13 14:50 ` Ezequiel Garcia [this message]
2013-08-13 14:50   ` Ezequiel Garcia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130813145041.GB2359@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nilanjan.roychowdhury@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.