aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>2014-05-03 11:57:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-03-06 14:08:12 -0500
commit467a44b0372d8268ce5bd90e58bde7db51c1d476 (patch)
treebf0e61c2c39dc0912c2e36cfe7e7215bfc5d0b75
parent084b6e7765b9554699afa23a50e702a3d0ae4b24 (diff)
iio: adc: at91_adc: Repair broken platform_data support
Trying to use the at91_adc driver while not using device tree is ending up in a kernel crash: Unable to handle kernel NULL pointer dereference at virtual address 00000004 [...] [<c01f3510>] (at91_adc_probe) from [<c0183828>] (platform_drv_probe+0x18/0x48) [<c0183828>] (platform_drv_probe) from [<c01824a4>] (driver_probe_device+0x100/0x218) [<c01824a4>] (driver_probe_device) from [<c0182648>] (__driver_attach+0x8c/0x90) [<c0182648>] (__driver_attach) from [<c0180de4>] (bus_for_each_dev+0x58/0x88) [<c0180de4>] (bus_for_each_dev) from [<c0181c7c>] (bus_add_driver+0xd4/0x1d4) [<c0181c7c>] (bus_add_driver) from [<c0182c40>] (driver_register+0x78/0xf4) [<c0182c40>] (driver_register) from [<c0008998>] (do_one_initcall+0xe8/0x14c) [<c0008998>] (do_one_initcall) from [<c02f0b50>] (kernel_init_freeable+0xec/0x1b4) [<c02f0b50>] (kernel_init_freeable) from [<c022acdc>] (kernel_init+0x8/0xe4) [<c022acdc>] (kernel_init) from [<c0009670>] (ret_from_fork+0x14/0x24) This is because the at91_adc_caps structure is mandatory but is not filled when using platform_data. Correct that by using an id_table. It ensues that the driver will not match "at91_adc" anymore but it was crashing anyway. Fixes: c46016665fff (iio: at91: ADC start-up time calculation changed since at91sam9x5) Cc: stable@vger.kernel.org # v3.13+ Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> Tested-by: Josh Wu <josh.wu@atmel.com> Acked-by: Josh Wu <josh.wu@atmel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/adc/at91_adc.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 5b1aa027c034..bbba014c9939 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -765,14 +765,17 @@ static int at91_adc_probe_pdata(struct at91_adc_state *st,
765 if (!pdata) 765 if (!pdata)
766 return -EINVAL; 766 return -EINVAL;
767 767
768 st->caps = (struct at91_adc_caps *)
769 platform_get_device_id(pdev)->driver_data;
770
768 st->use_external = pdata->use_external_triggers; 771 st->use_external = pdata->use_external_triggers;
769 st->vref_mv = pdata->vref; 772 st->vref_mv = pdata->vref;
770 st->channels_mask = pdata->channels_used; 773 st->channels_mask = pdata->channels_used;
771 st->num_channels = pdata->num_channels; 774 st->num_channels = st->caps->num_channels;
772 st->startup_time = pdata->startup_time; 775 st->startup_time = pdata->startup_time;
773 st->trigger_number = pdata->trigger_number; 776 st->trigger_number = pdata->trigger_number;
774 st->trigger_list = pdata->trigger_list; 777 st->trigger_list = pdata->trigger_list;
775 st->registers = pdata->registers; 778 st->registers = &st->caps->registers;
776 779
777 return 0; 780 return 0;
778} 781}
@@ -1101,7 +1104,6 @@ static int at91_adc_remove(struct platform_device *pdev)
1101 return 0; 1104 return 0;
1102} 1105}
1103 1106
1104#ifdef CONFIG_OF
1105static struct at91_adc_caps at91sam9260_caps = { 1107static struct at91_adc_caps at91sam9260_caps = {
1106 .calc_startup_ticks = calc_startup_ticks_9260, 1108 .calc_startup_ticks = calc_startup_ticks_9260,
1107 .num_channels = 4, 1109 .num_channels = 4,
@@ -1154,11 +1156,27 @@ static const struct of_device_id at91_adc_dt_ids[] = {
1154 {}, 1156 {},
1155}; 1157};
1156MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); 1158MODULE_DEVICE_TABLE(of, at91_adc_dt_ids);
1157#endif 1159
1160static const struct platform_device_id at91_adc_ids[] = {
1161 {
1162 .name = "at91sam9260-adc",
1163 .driver_data = (unsigned long)&at91sam9260_caps,
1164 }, {
1165 .name = "at91sam9g45-adc",
1166 .driver_data = (unsigned long)&at91sam9g45_caps,
1167 }, {
1168 .name = "at91sam9x5-adc",
1169 .driver_data = (unsigned long)&at91sam9x5_caps,
1170 }, {
1171 /* terminator */
1172 }
1173};
1174MODULE_DEVICE_TABLE(platform, at91_adc_ids);
1158 1175
1159static struct platform_driver at91_adc_driver = { 1176static struct platform_driver at91_adc_driver = {
1160 .probe = at91_adc_probe, 1177 .probe = at91_adc_probe,
1161 .remove = at91_adc_remove, 1178 .remove = at91_adc_remove,
1179 .id_table = at91_adc_ids,
1162 .driver = { 1180 .driver = {
1163 .name = DRIVER_NAME, 1181 .name = DRIVER_NAME,
1164 .of_match_table = of_match_ptr(at91_adc_dt_ids), 1182 .of_match_table = of_match_ptr(at91_adc_dt_ids),