aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-dw.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-08-31 00:47:06 -0400
committerMark Brown <broonie@kernel.org>2014-09-01 12:51:25 -0400
commita97c883a16da7e0691a3be5465926c92a8da4da6 (patch)
tree616ed5ff42847168d32ec3e32b4e91d1ff3c332d /drivers/spi/spi-dw.c
parent7d1311b93e58ed55f3a31cc8f94c4b8fe988a2b9 (diff)
spi: dw: Don't use devm_kzalloc in master->setup callback
device_add() expects that any memory allocated via devm_* API is only done in the device's probe function. Fix below boot warning: WARNING: CPU: 1 PID: 1 at drivers/base/dd.c:286 driver_probe_device+0x2b4/0x2f4() Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 3.16.0-10474-g835c90b-dirty #160 [<c0016364>] (unwind_backtrace) from [<c001251c>] (show_stack+0x20/0x24) [<c001251c>] (show_stack) from [<c04eaefc>] (dump_stack+0x7c/0x98) [<c04eaefc>] (dump_stack) from [<c0023d4c>] (warn_slowpath_common+0x78/0x9c) [<c0023d4c>] (warn_slowpath_common) from [<c0023d9c>] (warn_slowpath_null+0x2c/0x34) [<c0023d9c>] (warn_slowpath_null) from [<c0302c60>] (driver_probe_device+0x2b4/0x2f4) [<c0302c60>] (driver_probe_device) from [<c0302d90>] (__device_attach+0x50/0x54) [<c0302d90>] (__device_attach) from [<c0300e60>] (bus_for_each_drv+0x54/0x9c) [<c0300e60>] (bus_for_each_drv) from [<c0302958>] (device_attach+0x84/0x90) [<c0302958>] (device_attach) from [<c0301f10>] (bus_probe_device+0x94/0xb8) [<c0301f10>] (bus_probe_device) from [<c03000c0>] (device_add+0x434/0x4fc) [<c03000c0>] (device_add) from [<c0342dd4>] (spi_add_device+0x98/0x164) [<c0342dd4>] (spi_add_device) from [<c03444a4>] (spi_register_master+0x598/0x768) [<c03444a4>] (spi_register_master) from [<c03446b4>] (devm_spi_register_master+0x40/0x80) [<c03446b4>] (devm_spi_register_master) from [<c0346214>] (dw_spi_add_host+0x1a8/0x258) [<c0346214>] (dw_spi_add_host) from [<c0346920>] (dw_spi_mmio_probe+0x1d4/0x294) [<c0346920>] (dw_spi_mmio_probe) from [<c0304560>] (platform_drv_probe+0x3c/0x6c) [<c0304560>] (platform_drv_probe) from [<c0302a98>] (driver_probe_device+0xec/0x2f4) [<c0302a98>] (driver_probe_device) from [<c0302d3c>] (__driver_attach+0x9c/0xa0) [<c0302d3c>] (__driver_attach) from [<c0300f0c>] (bus_for_each_dev+0x64/0x98) [<c0300f0c>] (bus_for_each_dev) from [<c0302518>] (driver_attach+0x2c/0x30) [<c0302518>] (driver_attach) from [<c0302134>] (bus_add_driver+0xdc/0x1f4) [<c0302134>] (bus_add_driver) from [<c03035c8>] (driver_register+0x88/0x104) [<c03035c8>] (driver_register) from [<c030445c>] (__platform_driver_register+0x58/0x6c) [<c030445c>] (__platform_driver_register) from [<c0700f00>] (dw_spi_mmio_driver_init+0x18/0x20) [<c0700f00>] (dw_spi_mmio_driver_init) from [<c0008914>] (do_one_initcall+0x90/0x1d4) [<c0008914>] (do_one_initcall) from [<c06d7d90>] (kernel_init_freeable+0x178/0x248) [<c06d7d90>] (kernel_init_freeable) from [<c04e687c>] (kernel_init+0x18/0xfc) [<c04e687c>] (kernel_init) from [<c000ecd8>] (ret_from_fork+0x14/0x20) Reported-by: Thor Thayer <tthayer@opensource.altera.com> Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/spi/spi-dw.c')
-rw-r--r--drivers/spi/spi-dw.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 29f33143b795..b4508db2edcd 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -547,8 +547,7 @@ static int dw_spi_setup(struct spi_device *spi)
547 /* Only alloc on first setup */ 547 /* Only alloc on first setup */
548 chip = spi_get_ctldata(spi); 548 chip = spi_get_ctldata(spi);
549 if (!chip) { 549 if (!chip) {
550 chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data), 550 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
551 GFP_KERNEL);
552 if (!chip) 551 if (!chip)
553 return -ENOMEM; 552 return -ENOMEM;
554 spi_set_ctldata(spi, chip); 553 spi_set_ctldata(spi, chip);
@@ -606,6 +605,14 @@ static int dw_spi_setup(struct spi_device *spi)
606 return 0; 605 return 0;
607} 606}
608 607
608static void dw_spi_cleanup(struct spi_device *spi)
609{
610 struct chip_data *chip = spi_get_ctldata(spi);
611
612 kfree(chip);
613 spi_set_ctldata(spi, NULL);
614}
615
609/* Restart the controller, disable all interrupts, clean rx fifo */ 616/* Restart the controller, disable all interrupts, clean rx fifo */
610static void spi_hw_init(struct dw_spi *dws) 617static void spi_hw_init(struct dw_spi *dws)
611{ 618{
@@ -661,6 +668,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
661 master->bus_num = dws->bus_num; 668 master->bus_num = dws->bus_num;
662 master->num_chipselect = dws->num_cs; 669 master->num_chipselect = dws->num_cs;
663 master->setup = dw_spi_setup; 670 master->setup = dw_spi_setup;
671 master->cleanup = dw_spi_cleanup;
664 master->transfer_one_message = dw_spi_transfer_one_message; 672 master->transfer_one_message = dw_spi_transfer_one_message;
665 master->max_speed_hz = dws->max_freq; 673 master->max_speed_hz = dws->max_freq;
666 674