linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: nicolas.thery@st.com (Nicolas THERY)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] [media] atmel_isi: allocate memory to store the isi platform data.
Date: Wed, 29 Aug 2012 16:55:32 +0200	[thread overview]
Message-ID: <503E2D64.1020303@st.com> (raw)
In-Reply-To: <1346235093-28613-1-git-send-email-josh.wu@atmel.com>

Hello,

On 2012-08-29 12:11, Josh Wu wrote:
> This patch fix the bug: ISI driver's platform data became invalid when isi platform data's attribution is __initdata.
> 
> If the isi platform data is passed as __initdata. Then we need store it in driver allocated memory. otherwise when we use it out of the probe() function, then the isi platform data is invalid.
> 
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> ---
>  drivers/media/platform/soc_camera/atmel-isi.c |   12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
> index ec3f6a0..dc0fdec 100644
> --- a/drivers/media/platform/soc_camera/atmel-isi.c
> +++ b/drivers/media/platform/soc_camera/atmel-isi.c
> @@ -926,6 +926,7 @@ static int __devexit atmel_isi_remove(struct platform_device *pdev)
>  	clk_put(isi->mck);
>  	clk_unprepare(isi->pclk);
>  	clk_put(isi->pclk);
> +	kfree(isi->pdata);

Not needed if you use devm_kzalloc().  See below.

>  	kfree(isi);
>  
>  	return 0;
> @@ -968,8 +969,15 @@ static int __devinit atmel_isi_probe(struct platform_device *pdev)
>  		goto err_alloc_isi;
>  	}
>  
> +	isi->pdata = kzalloc(sizeof(struct isi_platform_data), GFP_KERNEL);
> +	if (!isi->pdata) {
> +		ret = -ENOMEM;
> +		dev_err(&pdev->dev, "Can't allocate isi platform data!\n");
> +		goto err_alloc_isi_pdata;
> +	}
> +	memcpy(isi->pdata, pdata, sizeof(struct isi_platform_data));
> +

It is more idiomatic to use sizeof(*isi->pdata) in kzalloc() and memcpy() calls
to be resilient to future type changes.

You may also want to use dev_kzalloc() which frees memory automagically on
driver detach.

>  	isi->pclk = pclk;
> -	isi->pdata = pdata;
>  	isi->active = NULL;
>  	spin_lock_init(&isi->lock);
>  	init_waitqueue_head(&isi->vsync_wq);
> @@ -1073,6 +1081,8 @@ err_set_mck_rate:
>  err_clk_prepare_mck:
>  	clk_put(isi->mck);
>  err_clk_get:
> +	kfree(isi->pdata);
> +err_alloc_isi_pdata:
>  	kfree(isi);
>  err_alloc_isi:
>  	clk_unprepare(pclk);
> 

Best regards,
Nicolas

  reply	other threads:[~2012-08-29 14:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-29 10:11 [PATCH] [media] atmel_isi: allocate memory to store the isi platform data Josh Wu
2012-08-29 14:55 ` Nicolas THERY [this message]
2012-08-29 15:16 ` Sylwester Nawrocki
2012-08-29 16:02   ` Guennadi Liakhovetski
2012-08-30  6:27     ` Josh Wu

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=503E2D64.1020303@st.com \
    --to=nicolas.thery@st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).