Skip to contentSkip to conversation

arm: omap4: hsmmc: check for null pointer

PATCH Superseded Balaji T K 3 participants 5 messages Apr 23, 2012 – May 8, 2012

Subsystems (3)
lore
Share & tools
lore

Balaji T K

author
#0 lore raw

PATCH v2 1/1 arm: omap4: hsmmc: check for null pointer

platform_device pdev can be NULL if CONFIG_MMC_OMAP_HS is not set. Add check for NULL pointer

Fixes the following boot crash seen with omap4sdp and omap4panda when MMC is disabled.

Unable to handle kernel NULL pointer dereference at virtual address 0000008c
pgd = c0004000
[0000008c] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in:
CPU: 0    Not tainted  (3.4.0-rc1-05971-ga4dfa82 #4)
PC is at omap_4430sdp_init+0x184/0x410
LR is at device_add+0x1a0/0x664
---
 arch/arm/mach-omap2/board-4430sdp.c     |   44 --------------------------
 arch/arm/mach-omap2/board-omap4panda.c  |   49 -----------------------------
 arch/arm/mach-omap2/board-omap4pcm049.c |   45 ---------------------------
 arch/arm/mach-omap2/common.h            |    3 ++
 arch/arm/mach-omap2/omap4-common.c      |   51 +++++++++++++++++++++++++++++++
 5 files changed, 54 insertions(+), 138 deletions(-)
arch/arm/mach-omap2/board-4430sdp.c +0 -44
index a39fc4b..ec06103 100644
@@ -488,50 +488,6 @@ static struct platform_device omap_vwlan_device = {
 	},
 };
 
-static int omap4_twl6030_hsmmc_late_init(struct device *dev)
-{
-	int irq = 0;
-	struct platform_device *pdev = container_of(dev,
-				struct platform_device, dev);
-	struct omap_mmc_platform_data *pdata = dev->platform_data;
-
-	/* Setting MMC1 Card detect Irq */
-	if (pdev->id == 0) {
-		irq = twl6030_mmc_card_detect_config();
-		if (irq < 0) {
-			pr_err("Failed configuring MMC1 card detect\n");
-			return irq;
-		}
-		pdata->slots[0].card_detect_irq = irq;
-		pdata->slots[0].card_detect = twl6030_mmc_card_detect;
-	}
-	return 0;
-}
-
-static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
-{
-	struct omap_mmc_platform_data *pdata;
-
-	/* dev can be null if CONFIG_MMC_OMAP_HS is not set */
-	if (!dev) {
-		pr_err("Failed %s\n", __func__);
-		return;
-	}
-	pdata = dev->platform_data;
-	pdata->init =	omap4_twl6030_hsmmc_late_init;
-}
-
-static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
-{
-	struct omap2_hsmmc_info *c;
-
-	omap_hsmmc_init(controllers);
-	for (c = controllers; c->mmc; c++)
-		omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
-
-	return 0;
-}
-
 static struct regulator_init_data sdp4430_vaux1 = {
 	.constraints = {
 		.min_uV			= 1000000,
arch/arm/mach-omap2/board-omap4panda.c +0 -49

55 lines not on this page · raw message

arch/arm/mach-omap2/board-omap4pcm049.c +0 -45

51 lines not on this page · raw message

arch/arm/mach-omap2/common.h +3 -0
index 0e95efc..f14b3ae 100644
@@ -27,6 +27,7 @@
 #ifndef __ASSEMBLER__
 
 #include <linux/delay.h>
+#include <linux/i2c/twl.h>
 #include <plat/common.h>
 #include <asm/proc-fns.h>
 
@@ -252,6 +253,8 @@ static inline u32 omap4_mpuss_read_prev_context_state(void)
 struct omap_sdrc_params;
 extern void omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
 				      struct omap_sdrc_params *sdrc_cs1);
+struct omap2_hsmmc_info;
+extern int omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers);
 
 #endif /* __ASSEMBLER__ */
 #endif /* __ARCH_ARM_MACH_OMAP2PLUS_COMMON_H */
arch/arm/mach-omap2/omap4-common.c +51 -0

65 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 1/1 arm: omap4: hsmmc: check for null pointer

Hi,

Quoted 4 lines · Balaji T K
arch/arm/mach-omap2/omap4-common.c +4 -0
+int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
+{
+	struct omap2_hsmmc_info *c;
+

arch/arm/mach-omap2/omap4-common.c static int __init omap4_sar_ram_init(void) · line 260

Quoted 10 lines
arch/arm/mach-omap2/omap4-common.c +10 -0
+	omap_hsmmc_init(controllers);
+	for (c = controllers; c->mmc; c++) {
+		/* pdev can be null if CONFIG_MMC_OMAP_HS is not set */
+		if (!c->pdev)
+			continue;
+		omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
+	}
+
+	return 0;
+}

why are you even calling this if CONFIG_MMC_OMAP_HS isn't set ? Just stub it out if you don't have mmc support.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120423/78dc7f51/attachment.sig>
author
#2 lore raw

PATCH v3 1/1 arm: omap4: hsmmc: check for null pointer

platform_device pdev can be NULL if CONFIG_MMC_OMAP_HS is not set. Add check for NULL pointer. while at it move the duplicated functions to omap4-common.c

Fixes the following boot crash seen with omap4sdp and omap4panda when MMC is disabled.

Unable to handle kernel NULL pointer dereference at virtual address 0000008c
pgd = c0004000
[0000008c] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in:
CPU: 0    Not tainted  (3.4.0-rc1-05971-ga4dfa82 #4)
PC is at omap_4430sdp_init+0x184/0x410
LR is at device_add+0x1a0/0x664

---
v3:
do nothing in omap4_twl6030_hsmmc_init when CONFIG_MMC_OMAP_HS is disabled

v2:
move omap4 mmc board init functions to omap4-common.c

 arch/arm/mach-omap2/board-4430sdp.c     |   44 -----------------------
 arch/arm/mach-omap2/board-omap4panda.c  |   49 --------------------------
 arch/arm/mach-omap2/board-omap4pcm049.c |   45 ------------------------
 arch/arm/mach-omap2/common.h            |    3 ++
 arch/arm/mach-omap2/omap4-common.c      |   58 +++++++++++++++++++++++++++++++
 5 files changed, 61 insertions(+), 138 deletions(-)
arch/arm/mach-omap2/board-4430sdp.c +0 -44
index a39fc4b..ec06103 100644
@@ -488,50 +488,6 @@ static struct platform_device omap_vwlan_device = {
 	},
 };
 
-static int omap4_twl6030_hsmmc_late_init(struct device *dev)
-{
-	int irq = 0;
-	struct platform_device *pdev = container_of(dev,
-				struct platform_device, dev);
-	struct omap_mmc_platform_data *pdata = dev->platform_data;
-
-	/* Setting MMC1 Card detect Irq */
-	if (pdev->id == 0) {
-		irq = twl6030_mmc_card_detect_config();
-		if (irq < 0) {
-			pr_err("Failed configuring MMC1 card detect\n");
-			return irq;
-		}
-		pdata->slots[0].card_detect_irq = irq;
-		pdata->slots[0].card_detect = twl6030_mmc_card_detect;
-	}
-	return 0;
-}
-
-static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
-{
-	struct omap_mmc_platform_data *pdata;
-
-	/* dev can be null if CONFIG_MMC_OMAP_HS is not set */
-	if (!dev) {
-		pr_err("Failed %s\n", __func__);
-		return;
-	}
-	pdata = dev->platform_data;
-	pdata->init =	omap4_twl6030_hsmmc_late_init;
-}
-
-static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
-{
-	struct omap2_hsmmc_info *c;
-
-	omap_hsmmc_init(controllers);
-	for (c = controllers; c->mmc; c++)
-		omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
-
-	return 0;
-}
-
 static struct regulator_init_data sdp4430_vaux1 = {
 	.constraints = {
 		.min_uV			= 1000000,
arch/arm/mach-omap2/board-omap4panda.c +0 -49

55 lines not on this page · raw message

arch/arm/mach-omap2/board-omap4pcm049.c +0 -45

51 lines not on this page · raw message

arch/arm/mach-omap2/common.h +3 -0
index 0e95efc..f14b3ae 100644
@@ -27,6 +27,7 @@
 #ifndef __ASSEMBLER__
 
 #include <linux/delay.h>
+#include <linux/i2c/twl.h>
 #include <plat/common.h>
 #include <asm/proc-fns.h>
 
@@ -252,6 +253,8 @@ static inline u32 omap4_mpuss_read_prev_context_state(void)
 struct omap_sdrc_params;
 extern void omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
 				      struct omap_sdrc_params *sdrc_cs1);
+struct omap2_hsmmc_info;
+extern int omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers);
 
 #endif /* __ASSEMBLER__ */
 #endif /* __ARCH_ARM_MACH_OMAP2PLUS_COMMON_H */
arch/arm/mach-omap2/omap4-common.c +58 -0

72 lines not on this page · raw message

Signature · 1 line
1.7.0.4
maintainer
#3 lore raw

PATCH v3 1/1 arm: omap4: hsmmc: check for null pointer

Quoted 6 lines · Balaji T K

platform_device pdev can be NULL if CONFIG_MMC_OMAP_HS is not set. Add check for NULL pointer. while at it move the duplicated functions to omap4-common.c

Fixes the following boot crash seen with omap4sdp and omap4panda when MMC is disabled.

Thanks applying into fixes-non-critical, this is a bit too intrusive for the -rc series.

Regards,

Tony

#4 lore raw

PATCH v2 1/1 arm: omap4: hsmmc: check for null pointer

In reply to Felipe Balbi
Quoted 12 lines · Felipe Balbi

Hi,

Quoted 9 lines · Balaji T K
(quoted diff) +9 -0
+int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
+{
+ ? ? struct omap2_hsmmc_info *c;
+
+ ? ? omap_hsmmc_init(controllers);
+ ? ? for (c = controllers; c->mmc; c++) {
+ ? ? ? ? ? ? /* pdev can be null if CONFIG_MMC_OMAP_HS is not set */
+ ? ? ? ? ? ? if (!c->pdev)
+ ? ? ? ? ? ? ? ? ? ? continue;
Quoted 8 lines

arch/arm/mach-omap2/omap4-common.c static int __init omap4_sar_ram_init(void) · line 227

Quoted 5 lines

+ ? ? ? ? ? ? omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
+ ? ? }

arch/arm/mach-omap2/omap4-common.c +3 -0
+
+ ? ? return 0;
+}

why are you even calling this if CONFIG_MMC_OMAP_HS isn't set ? Just stub it out if you don't have mmc support.

Ok, added in v3