Message ID | 1346235093-28613-1-git-send-email-josh.wu@atmel.com (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers |
Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from <linux-media-owner@vger.kernel.org>) id 1T6fmz-0004QP-VZ for patchwork@linuxtv.org; Wed, 29 Aug 2012 12:46:25 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-4) with esmtp for <patchwork@linuxtv.org> id 1T6fmz-0003Ez-AN; Wed, 29 Aug 2012 12:46:25 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752766Ab2H2KqX (ORCPT <rfc822;patchwork@linuxtv.org>); Wed, 29 Aug 2012 06:46:23 -0400 Received: from newsmtp5.atmel.com ([204.2.163.5]:51348 "EHLO sjogate2.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752107Ab2H2KqW (ORCPT <rfc822;linux-media@vger.kernel.org>); Wed, 29 Aug 2012 06:46:22 -0400 X-Greylist: delayed 1777 seconds by postgrey-1.27 at vger.kernel.org; Wed, 29 Aug 2012 06:46:22 EDT Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id q7TABbuN014257; Wed, 29 Aug 2012 03:11:38 -0700 (PDT) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 29 Aug 2012 18:16:26 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 29 Aug 2012 18:16:25 +0800 From: Josh Wu <josh.wu@atmel.com> To: g.liakhovetski@gmx.de, linux-media@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, nicolas.ferre@atmel.com, mchehab@redhat.com, Josh Wu <josh.wu@atmel.com> Subject: [PATCH] [media] atmel_isi: allocate memory to store the isi platform data. Date: Wed, 29 Aug 2012 18:11:33 +0800 Message-Id: <1346235093-28613-1-git-send-email-josh.wu@atmel.com> X-Mailer: git-send-email 1.7.9.5 X-OriginalArrivalTime: 29 Aug 2012 10:16:26.0133 (UTC) FILETIME=[58FD4450:01CD85CF] Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.8.29.103617 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_1800_1899 0, BODY_SIZE_2000_LESS 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __DATE_TZ_HK 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_XOAT 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' |
Commit Message
Josh Wu
Aug. 29, 2012, 10:11 a.m. UTC
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(-)
Comments
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-- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi, On 08/29/2012 12:11 PM, 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); > 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)); > + Why not just embed struct isi_platform_data in struct atmel_isi and drop this another kzalloc() ? Then you could simply do isi->pdata = *pdata. Also, is this going to work when this driver is build and as a module and its loading is deferred past system booting ? At that time the driver's platform data may be well discarded. You may wan't to duplicate it on the running boards in board code with kmemdup() or something. -- Regards, Sylwester -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 29 Aug 2012, Sylwester Nawrocki wrote: > Hi, > > On 08/29/2012 12:11 PM, 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); > > 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)); > > + > > Why not just embed struct isi_platform_data in struct atmel_isi and drop this > another kzalloc() ? > Then you could simply do isi->pdata = *pdata. > > Also, is this going to work when this driver is build and as a module > and its loading is deferred past system booting ? At that time the driver's > platform data may be well discarded. Right, it will be gone, I think. > You may wan't to duplicate it on the > running boards in board code with kmemdup() or something. How about removing __initdata from board code? Thanks Guennadi --- Guennadi Liakhovetski, Ph.D. Freelance Open-Source Software Developer http://www.open-technology.de/ -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi, all Sorry, My mistake here. After checking the code, this ISI bug doesn't exist in current mainline code. So I will *cancel* this patch. Since current mainline will copy this __initdata isi platform data to one static structure in function at91_add_device_isi(...). Then pass this static structure to the driver. So the ISI driver has no bug that isi platform became invalid. I meet this is because I'm not call the at91_add_device_isi(...) since I try in the DT support board. At last, even no above bug in the code, This isi_platform_data is still need to stored in ISI driver. Since if we support DT then we need this isi platform data and the function at91_add_device_isi(...) will not to be called (it is in device file). So I think after soc-camera DT support is merged. Then I will send a DT support patch for ISI driver which will embed the isi_platform_data into atmel_isi. Thank you all for the replies. That helps a lot even in this small patch. :) On 8/30/2012 12:02 AM, Guennadi Liakhovetski wrote: > On Wed, 29 Aug 2012, Sylwester Nawrocki wrote: > >> Hi, >> >> On 08/29/2012 12:11 PM, 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); >>> 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)); >>> + >> Why not just embed struct isi_platform_data in struct atmel_isi and drop this >> another kzalloc() ? >> Then you could simply do isi->pdata = *pdata. >> >> Also, is this going to work when this driver is build and as a module >> and its loading is deferred past system booting ? At that time the driver's >> platform data may be well discarded. > Right, it will be gone, I think. > >> You may wan't to duplicate it on the >> running boards in board code with kmemdup() or something. > How about removing __initdata from board code? > > Thanks > Guennadi > --- > Guennadi Liakhovetski, Ph.D. > Freelance Open-Source Software Developer > http://www.open-technology.de/ > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Best Regards, Josh Wu -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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); 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)); + 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);