From 5e7749436d576a525d7b2a4bcffb17b3364b9e00 Mon Sep 17 00:00:00 2001 From: Scott Ellis Date: Wed, 10 Mar 2010 14:22:45 -0700 Subject: spi/omap2_mcspi: fix NULL pointer dereference Check spi->controller_state before dereferencing. Shows up NULL here when using spi_alloc_device()/spi_add_device() and spi_add_device() fails before spi_setup(). Calling spi_dev_put() on the leftover spi_device results in the error. Signed-off-by: Scott Ellis Signed-off-by: Grant Likely --- drivers/spi/omap2_mcspi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers/spi') diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c index 715c518b1b68..87d44eeaaa7b 100644 --- a/drivers/spi/omap2_mcspi.c +++ b/drivers/spi/omap2_mcspi.c @@ -751,11 +751,13 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) mcspi = spi_master_get_devdata(spi->master); mcspi_dma = &mcspi->dma_channels[spi->chip_select]; - /* Unlink controller state from context save list */ - cs = spi->controller_state; - list_del(&cs->node); + if (spi->controller_state) { + /* Unlink controller state from context save list */ + cs = spi->controller_state; + list_del(&cs->node); - kfree(spi->controller_state); + kfree(spi->controller_state); + } if (mcspi_dma->dma_rx_channel != -1) { omap_free_dma(mcspi_dma->dma_rx_channel); -- cgit From 9bd4517ddc51c803784778ab52e6f0bc03b77a52 Mon Sep 17 00:00:00 2001 From: Scott Ellis Date: Wed, 10 Mar 2010 14:23:13 -0700 Subject: spi/omap2_mcspi: Use transaction speed if provided omap2_mcspi_transfer() gets called in omap2_mcspi_work() when the transaction speed_hz or bits_per_word fields are non-zero. omap2_mcspi_transfer() does not look at the speed_hz field so the override speed value is ignored. The code should probably change to one of these options. 1. Skip the call to omap2_mcsp_transfer() if the only reason was a non-zero speed_hz and it's not going to be used. 2. Use the new speed_hz value provided The patch below uses the speed_hz value. Signed-off-by: Scott Ellis Signed-off-by: Grant Likely --- drivers/spi/omap2_mcspi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'drivers/spi') diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c index 87d44eeaaa7b..4dd786b99b8b 100644 --- a/drivers/spi/omap2_mcspi.c +++ b/drivers/spi/omap2_mcspi.c @@ -578,6 +578,7 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi, struct spi_master *spi_cntrl; u32 l = 0, div = 0; u8 word_len = spi->bits_per_word; + u32 speed_hz = spi->max_speed_hz; mcspi = spi_master_get_devdata(spi->master); spi_cntrl = mcspi->master; @@ -587,9 +588,12 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi, cs->word_len = word_len; - if (spi->max_speed_hz) { + if (t && t->speed_hz) + speed_hz = t->speed_hz; + + if (speed_hz) { while (div <= 15 && (OMAP2_MCSPI_MAX_FREQ / (1 << div)) - > spi->max_speed_hz) + > speed_hz) div++; } else div = 15; -- cgit From 5a0e3ad6af8660be21ca98a971cd00f331318c05 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Wed, 24 Mar 2010 17:04:11 +0900 Subject: include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo Guess-its-ok-by: Christoph Lameter Cc: Ingo Molnar Cc: Lee Schermerhorn --- drivers/spi/amba-pl022.c | 1 + drivers/spi/atmel_spi.c | 1 + drivers/spi/au1550_spi.c | 1 + drivers/spi/davinci_spi.c | 1 + drivers/spi/dw_spi.c | 1 + drivers/spi/dw_spi_mmio.c | 1 + drivers/spi/dw_spi_pci.c | 1 + drivers/spi/mpc52xx_psc_spi.c | 1 + drivers/spi/mpc52xx_spi.c | 1 + drivers/spi/omap2_mcspi.c | 1 + drivers/spi/omap_spi_100k.c | 1 + drivers/spi/omap_uwire.c | 1 + drivers/spi/pxa2xx_spi.c | 1 + drivers/spi/spi.c | 1 + drivers/spi/spi_bfin5xx.c | 1 + drivers/spi/spi_bitbang.c | 1 + drivers/spi/spi_imx.c | 1 + drivers/spi/spi_mpc8xxx.c | 1 + drivers/spi/spi_nuc900.c | 1 + drivers/spi/spi_ppc4xx.c | 1 + drivers/spi/spi_s3c24xx.c | 1 + drivers/spi/tle62x0.c | 1 + drivers/spi/xilinx_spi_of.c | 1 + 23 files changed, 23 insertions(+) (limited to 'drivers/spi') diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c index 9aeb68113100..e9aeee16d922 100644 --- a/drivers/spi/amba-pl022.c +++ b/drivers/spi/amba-pl022.c @@ -44,6 +44,7 @@ #include #include #include +#include /* * This macro is used to define some register default values. diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c index d21c24eaf0a9..c4e04428992d 100644 --- a/drivers/spi/atmel_spi.c +++ b/drivers/spi/atmel_spi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c index ba8ac4f599d3..3c9ade69643f 100644 --- a/drivers/spi/au1550_spi.c +++ b/drivers/spi/au1550_spi.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index 225ab60b02c4..95afb6b77395 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c index 8ed38f1d6c18..d256cb00604c 100644 --- a/drivers/spi/dw_spi.c +++ b/drivers/spi/dw_spi.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/dw_spi_mmio.c b/drivers/spi/dw_spi_mmio.c index e35b45ac5174..db35bd9c1b24 100644 --- a/drivers/spi/dw_spi_mmio.c +++ b/drivers/spi/dw_spi_mmio.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/dw_spi_pci.c b/drivers/spi/dw_spi_pci.c index 1f0735f9cc76..1f52755dc878 100644 --- a/drivers/spi/dw_spi_pci.c +++ b/drivers/spi/dw_spi_pci.c @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c index 04747868d6c4..77d4cc88edea 100644 --- a/drivers/spi/mpc52xx_psc_spi.c +++ b/drivers/spi/mpc52xx_psc_spi.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c index 6eab46537a0a..cd68f1ce5cc3 100644 --- a/drivers/spi/mpc52xx_spi.c +++ b/drivers/spi/mpc52xx_spi.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c index 4dd786b99b8b..d8356af118a8 100644 --- a/drivers/spi/omap2_mcspi.c +++ b/drivers/spi/omap2_mcspi.c @@ -32,6 +32,7 @@ #include #include #include +#include #include diff --git a/drivers/spi/omap_spi_100k.c b/drivers/spi/omap_spi_100k.c index 5355d90d1bee..24668b30a52d 100644 --- a/drivers/spi/omap_spi_100k.c +++ b/drivers/spi/omap_spi_100k.c @@ -33,6 +33,7 @@ #include #include #include +#include #include diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c index 6c3a8557db27..160d3266205f 100644 --- a/drivers/spi/omap_uwire.c +++ b/drivers/spi/omap_uwire.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c index c2f707e5ce74..36828358a4d8 100644 --- a/drivers/spi/pxa2xx_spi.c +++ b/drivers/spi/pxa2xx_spi.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index b76f2468a84a..9ffb0fdbd6fe 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c index 1d41058bbab2..10a6dc3d37ac 100644 --- a/drivers/spi/spi_bfin5xx.c +++ b/drivers/spi/spi_bfin5xx.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index f1db395dd889..5265330a528f 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c index 0ddbbe45e834..7972e9077473 100644 --- a/drivers/spi/spi_imx.c +++ b/drivers/spi/spi_imx.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c index 4f0cc9d457e0..14d052316502 100644 --- a/drivers/spi/spi_mpc8xxx.c +++ b/drivers/spi/spi_mpc8xxx.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/spi_nuc900.c b/drivers/spi/spi_nuc900.c index b319f9bf9b9b..dff63be0d0a8 100644 --- a/drivers/spi/spi_nuc900.c +++ b/drivers/spi/spi_nuc900.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c index 6d8d4026a07a..7cb5ff37f6e2 100644 --- a/drivers/spi/spi_ppc4xx.c +++ b/drivers/spi/spi_ppc4xx.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c index 1fabede9e061..151a95e40653 100644 --- a/drivers/spi/spi_s3c24xx.c +++ b/drivers/spi/spi_s3c24xx.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/drivers/spi/tle62x0.c b/drivers/spi/tle62x0.c index bf9540f5fb98..a3938958147c 100644 --- a/drivers/spi/tle62x0.c +++ b/drivers/spi/tle62x0.c @@ -11,6 +11,7 @@ #include #include +#include #include #include diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c index ed34a8d419c7..748d33a76d29 100644 --- a/drivers/spi/xilinx_spi_of.c +++ b/drivers/spi/xilinx_spi_of.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include -- cgit