mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Alexander Shiyan <shc_work@mail.ru>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/3] mc13xxx: Fixed memory leak
Date: Thu, 9 Aug 2012 08:38:01 +0200	[thread overview]
Message-ID: <20120809063801.GO1451@pengutronix.de> (raw)
In-Reply-To: <1344071755-6733-3-git-send-email-shc_work@mail.ru>

On Sat, Aug 04, 2012 at 01:15:55PM +0400, Alexander Shiyan wrote:
> A string allocated by asprintf is not freed, so change it to a sprintf
> with the preallocated buffer.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  drivers/mfd/mc13xxx.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
> index 8e3c0b0..2373254 100644
> --- a/drivers/mfd/mc13xxx.c
> +++ b/drivers/mfd/mc13xxx.c
> @@ -252,7 +252,7 @@ static struct mc13892_rev mc13892_revisions[] = {
>  static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  {
>  	unsigned int rev_id;
> -	char *chipname, *revstr;
> +	char *chipname, revstr[5];
>  	int rev, i;
>  
>  	mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
> @@ -265,9 +265,9 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  		/* Ver 0.2 is actually 3.2a. Report as 3.2 */
>  		if (rev == 0x02) {
>  			rev = 0x32;
> -			revstr = "3.2a";
> +			strcpy(&revstr[0], "3.2a");
>  		} else
> -			revstr = asprintf("%d.%d", rev / 0x10, rev % 10);
> +			sprintf(&revstr[0], "%d.%d", rev / 0x10, rev % 10);
>  		break;
>  	case 7:
>  		chipname = "MC13892";
> @@ -279,12 +279,12 @@ static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
>  			return -EINVAL;
>  
>  		rev = mc13892_revisions[i].rev;
> -		revstr = mc13892_revisions[i].revstr;
> +		strcpy(&revstr[0], mc13892_revisions[i].revstr);
>  
>  		if (rev == MC13892_REVISION_2_0) {
>  			if ((rev_id >> 9) & 0x3) {
>  				rev = MC13892_REVISION_2_0a;
> -				revstr = "2.0a";
> +				strcpy(&revstr[0], "2.0a");

strcpy(revstr, "2.0a") should do the same, right? (also for the other
places)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-08-09  6:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-04  9:15 [PATCH 1/3] mc13xxx: Added mc13xxx_revision() function Alexander Shiyan
2012-08-04  9:15 ` [PATCH 2/3] mc13xxx: Hide private struct mc13xxx from other units Alexander Shiyan
2012-08-04  9:15 ` [PATCH 3/3] mc13xxx: Fixed memory leak Alexander Shiyan
2012-08-09  6:38   ` Sascha Hauer [this message]
2012-08-09 15:33     ` Alexander Shiyan
2012-08-10  8:44       ` Sascha Hauer

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=20120809063801.GO1451@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=shc_work@mail.ru \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox