Patchwork [1/2] MTD: check for valid pdata inside plat_nand

login
register
mail settings
Submitter John Crispin
Date July 22, 2012, 6:59 a.m.
Message ID <1342940398-2162-1-git-send-email-blogic@openwrt.org>
Download mbox | patch
Permalink /patch/172478/
State Accepted
Commit da3888cb84065a03d30b5f729b405e573bd0d66e
Headers show

Comments

John Crispin - July 22, 2012, 6:59 a.m.
If plat_nand loads and the platform_data is not properly set it will segfault.

Signed-off-by: John Crispin <blogic@openwrt.org>
Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: linux-mtd@lists.infradead.org
---
I am seeing this when plat_nand is referenced inside my DT file but
CONFIG_MTD_NAND_XWAY is not selected, resulting in platform_data not being
populated with valid data.
---
 drivers/mtd/nand/plat_nand.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Artem Bityutskiy - Aug. 17, 2012, 2:03 p.m.
On Sun, 2012-07-22 at 08:59 +0200, John Crispin wrote:
> If plat_nand loads and the platform_data is not properly set it will segfault.
> 
> Signed-off-by: John Crispin <blogic@openwrt.org>
> Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
> Cc: linux-mtd@lists.infradead.org
> ---
> I am seeing this when plat_nand is referenced inside my DT file but
> CONFIG_MTD_NAND_XWAY is not selected, resulting in platform_data not being
> populated with valid data.

Aiaiai complains like this for this patch-set:

--------------------------------------------------------------------------------

Successfully built configuration "mips-lantiq_defconfig,mips,mips-linux-", results:

--- before_patching.log
+++ after_patching.log
@@ @@
+drivers/mtd/nand/xway_nand.c:145:9: warning: cast removes address space of expression [sparse]
+drivers/mtd/nand/xway_nand.c:163:25: warning: duplicate const  [sparse]
+drivers/mtd/nand/xway_nand.c:184:12: warning: symbol 'xway_register_nand' was not declared. Should it be static? [sparse]
+drivers/mtd/nand/xway_nand.c:184:12: warning: no previous prototype for 'xway_register_nand' [-Wmissing-prototypes]

--------------------------------------------------------------------------------
John Crispin - Aug. 17, 2012, 8:52 p.m.
On 17/08/12 16:03, Artem Bityutskiy wrote:
> On Sun, 2012-07-22 at 08:59 +0200, John Crispin wrote:
>> If plat_nand loads and the platform_data is not properly set it will segfault.
>>
>> Signed-off-by: John Crispin <blogic@openwrt.org>
>> Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
>> Cc: linux-mtd@lists.infradead.org
>> ---
>> I am seeing this when plat_nand is referenced inside my DT file but
>> CONFIG_MTD_NAND_XWAY is not selected, resulting in platform_data not being
>> populated with valid data.
> Aiaiai complains like this for this patch-set:
>
> --------------------------------------------------------------------------------
>
> Successfully built configuration "mips-lantiq_defconfig,mips,mips-linux-", results:
>
> --- before_patching.log
> +++ after_patching.log
> @@ @@
> +drivers/mtd/nand/xway_nand.c:145:9: warning: cast removes address space of expression [sparse]
> +drivers/mtd/nand/xway_nand.c:163:25: warning: duplicate const  [sparse]
> +drivers/mtd/nand/xway_nand.c:184:12: warning: symbol 'xway_register_nand' was not declared. Should it be static? [sparse]
> +drivers/mtd/nand/xway_nand.c:184:12: warning: no previous prototype for 'xway_register_nand' [-Wmissing-prototypes]
>
> -------------------------------------------------------------------------------
Hi,

shame on me ... we are currently setting up a build bot to run *all*
mips patches through aiaiai so this wont happen in future  ...

i will fix the patch and resend it ...

John
Artem Bityutskiy - Aug. 24, 2012, 2:31 p.m.
On Sun, 2012-07-22 at 08:59 +0200, John Crispin wrote:
> If plat_nand loads and the platform_data is not properly set it will segfault.
> 
> Signed-off-by: John Crispin <blogic@openwrt.org>
> Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
> Cc: linux-mtd@lists.infradead.org
> ---

Pushed to l2-mtd.git, thanks!

Patch

diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 1bcb520..a47ee68 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -37,6 +37,11 @@  static int __devinit plat_nand_probe(struct platform_device *pdev)
 	const char **part_types;
 	int err = 0;
 
+	if (!pdata) {
+		dev_err(&pdev->dev, "platform_nand_data is missing\n");
+		return -EINVAL;
+	}
+
 	if (pdata->chip.nr_chips < 1) {
 		dev_err(&pdev->dev, "invalid number of chips specified\n");
 		return -EINVAL;