Skip to content

Commit 1ee47b0

Browse files
balajitktmlind
authored andcommitted
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 0000008 pgd = c0004000 [0000008] *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 Signed-off-by: Balaji T K <[email protected]> Reported-by: Santosh Shilimkar <[email protected]> Signed-off-by: Tony Lindgren <[email protected]>
1 parent e54bdc1 commit 1ee47b0

File tree

4 files changed

+61
-93
lines changed

4 files changed

+61
-93
lines changed

arch/arm/mach-omap2/board-4430sdp.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -489,50 +489,6 @@ static struct platform_device omap_vwlan_device = {
489489
},
490490
};
491491

492-
static int omap4_twl6030_hsmmc_late_init(struct device *dev)
493-
{
494-
int irq = 0;
495-
struct platform_device *pdev = container_of(dev,
496-
struct platform_device, dev);
497-
struct omap_mmc_platform_data *pdata = dev->platform_data;
498-
499-
/* Setting MMC1 Card detect Irq */
500-
if (pdev->id == 0) {
501-
irq = twl6030_mmc_card_detect_config();
502-
if (irq < 0) {
503-
pr_err("Failed configuring MMC1 card detect\n");
504-
return irq;
505-
}
506-
pdata->slots[0].card_detect_irq = irq;
507-
pdata->slots[0].card_detect = twl6030_mmc_card_detect;
508-
}
509-
return 0;
510-
}
511-
512-
static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
513-
{
514-
struct omap_mmc_platform_data *pdata;
515-
516-
/* dev can be null if CONFIG_MMC_OMAP_HS is not set */
517-
if (!dev) {
518-
pr_err("Failed %s\n", __func__);
519-
return;
520-
}
521-
pdata = dev->platform_data;
522-
pdata->init = omap4_twl6030_hsmmc_late_init;
523-
}
524-
525-
static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
526-
{
527-
struct omap2_hsmmc_info *c;
528-
529-
omap_hsmmc_init(controllers);
530-
for (c = controllers; c->mmc; c++)
531-
omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
532-
533-
return 0;
534-
}
535-
536492
static struct regulator_init_data sdp4430_vaux1 = {
537493
.constraints = {
538494
.min_uV = 1000000,

arch/arm/mach-omap2/board-omap4panda.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -236,55 +236,6 @@ struct wl12xx_platform_data omap_panda_wlan_data __initdata = {
236236
.board_ref_clock = 2,
237237
};
238238

239-
static int omap4_twl6030_hsmmc_late_init(struct device *dev)
240-
{
241-
int irq = 0;
242-
struct platform_device *pdev = container_of(dev,
243-
struct platform_device, dev);
244-
struct omap_mmc_platform_data *pdata = dev->platform_data;
245-
246-
if (!pdata) {
247-
dev_err(dev, "%s: NULL platform data\n", __func__);
248-
return -EINVAL;
249-
}
250-
/* Setting MMC1 Card detect Irq */
251-
if (pdev->id == 0) {
252-
irq = twl6030_mmc_card_detect_config();
253-
if (irq < 0) {
254-
dev_err(dev, "%s: Error card detect config(%d)\n",
255-
__func__, irq);
256-
return irq;
257-
}
258-
pdata->slots[0].card_detect = twl6030_mmc_card_detect;
259-
}
260-
return 0;
261-
}
262-
263-
static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
264-
{
265-
struct omap_mmc_platform_data *pdata;
266-
267-
/* dev can be null if CONFIG_MMC_OMAP_HS is not set */
268-
if (!dev) {
269-
pr_err("Failed omap4_twl6030_hsmmc_set_late_init\n");
270-
return;
271-
}
272-
pdata = dev->platform_data;
273-
274-
pdata->init = omap4_twl6030_hsmmc_late_init;
275-
}
276-
277-
static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
278-
{
279-
struct omap2_hsmmc_info *c;
280-
281-
omap_hsmmc_init(controllers);
282-
for (c = controllers; c->mmc; c++)
283-
omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
284-
285-
return 0;
286-
}
287-
288239
static struct twl6040_codec_data twl6040_codec = {
289240
/* single-step ramp for headset and handsfree */
290241
.hs_left_step = 0x0f,

arch/arm/mach-omap2/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef __ASSEMBLER__
2828

2929
#include <linux/delay.h>
30+
#include <linux/i2c/twl.h>
3031
#include <plat/common.h>
3132
#include <asm/proc-fns.h>
3233

@@ -254,6 +255,8 @@ static inline u32 omap4_mpuss_read_prev_context_state(void)
254255
struct omap_sdrc_params;
255256
extern void omap_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
256257
struct omap_sdrc_params *sdrc_cs1);
258+
struct omap2_hsmmc_info;
259+
extern int omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers);
257260

258261
#endif /* __ASSEMBLER__ */
259262
#endif /* __ARCH_ARM_MACH_OMAP2PLUS_COMMON_H */

arch/arm/mach-omap2/omap4-common.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <plat/irqs.h>
2626
#include <plat/sram.h>
2727
#include <plat/omap-secure.h>
28+
#include <plat/mmc.h>
2829

2930
#include <mach/hardware.h>
3031
#include <mach/omap-wakeupgen.h>
3132

3233
#include "common.h"
34+
#include "hsmmc.h"
3335
#include "omap4-sar-layout.h"
3436
#include <linux/export.h>
3537

@@ -207,3 +209,59 @@ static int __init omap4_sar_ram_init(void)
207209
return 0;
208210
}
209211
early_initcall(omap4_sar_ram_init);
212+
213+
#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
214+
static int omap4_twl6030_hsmmc_late_init(struct device *dev)
215+
{
216+
int irq = 0;
217+
struct platform_device *pdev = container_of(dev,
218+
struct platform_device, dev);
219+
struct omap_mmc_platform_data *pdata = dev->platform_data;
220+
221+
/* Setting MMC1 Card detect Irq */
222+
if (pdev->id == 0) {
223+
irq = twl6030_mmc_card_detect_config();
224+
if (irq < 0) {
225+
dev_err(dev, "%s: Error card detect config(%d)\n",
226+
__func__, irq);
227+
return irq;
228+
}
229+
pdata->slots[0].card_detect_irq = irq;
230+
pdata->slots[0].card_detect = twl6030_mmc_card_detect;
231+
}
232+
return 0;
233+
}
234+
235+
static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
236+
{
237+
struct omap_mmc_platform_data *pdata;
238+
239+
/* dev can be null if CONFIG_MMC_OMAP_HS is not set */
240+
if (!dev) {
241+
pr_err("Failed %s\n", __func__);
242+
return;
243+
}
244+
pdata = dev->platform_data;
245+
pdata->init = omap4_twl6030_hsmmc_late_init;
246+
}
247+
248+
int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
249+
{
250+
struct omap2_hsmmc_info *c;
251+
252+
omap_hsmmc_init(controllers);
253+
for (c = controllers; c->mmc; c++) {
254+
/* pdev can be null if CONFIG_MMC_OMAP_HS is not set */
255+
if (!c->pdev)
256+
continue;
257+
omap4_twl6030_hsmmc_set_late_init(&c->pdev->dev);
258+
}
259+
260+
return 0;
261+
}
262+
#else
263+
int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
264+
{
265+
return 0;
266+
}
267+
#endif

0 commit comments

Comments
 (0)