diff options
author | Brian Niebuhr <bniebuhr@efjohnson.com> | 2010-08-19 07:34:25 -0400 |
---|---|---|
committer | Sekhar Nori <nsekhar@ti.com> | 2010-11-18 08:08:28 -0500 |
commit | 53d454a170e86594af1d27be820e678a582af751 (patch) | |
tree | 437b09d173aa8ee0479ba7c8e7e04875fbdafb13 | |
parent | b7ab24a0da96c8fc6d551ea87e82692299df6ac6 (diff) |
spi: davinci: check for NULL buffer pointer before using it
In the davinci_spi_{tx|rx}_u{8|16}() functions, check for
buffer pointer being valid before using it. While providing
for better error checking, this change will help simplify
code in the caller.
Signed-off-by: Brian Niebuhr <bniebuhr@efjohnson.com>
Tested-By: Michael Williamson <michael.williamson@criticallink.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
-rw-r--r-- | drivers/spi/davinci_spi.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index b0b338fc4466..10b0a08d2625 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c | |||
@@ -158,37 +158,41 @@ static unsigned use_dma; | |||
158 | 158 | ||
159 | static void davinci_spi_rx_buf_u8(u32 data, struct davinci_spi *davinci_spi) | 159 | static void davinci_spi_rx_buf_u8(u32 data, struct davinci_spi *davinci_spi) |
160 | { | 160 | { |
161 | u8 *rx = davinci_spi->rx; | 161 | if (davinci_spi->rx) { |
162 | 162 | u8 *rx = davinci_spi->rx; | |
163 | *rx++ = (u8)data; | 163 | *rx++ = (u8)data; |
164 | davinci_spi->rx = rx; | 164 | davinci_spi->rx = rx; |
165 | } | ||
165 | } | 166 | } |
166 | 167 | ||
167 | static void davinci_spi_rx_buf_u16(u32 data, struct davinci_spi *davinci_spi) | 168 | static void davinci_spi_rx_buf_u16(u32 data, struct davinci_spi *davinci_spi) |
168 | { | 169 | { |
169 | u16 *rx = davinci_spi->rx; | 170 | if (davinci_spi->rx) { |
170 | 171 | u16 *rx = davinci_spi->rx; | |
171 | *rx++ = (u16)data; | 172 | *rx++ = (u16)data; |
172 | davinci_spi->rx = rx; | 173 | davinci_spi->rx = rx; |
174 | } | ||
173 | } | 175 | } |
174 | 176 | ||
175 | static u32 davinci_spi_tx_buf_u8(struct davinci_spi *davinci_spi) | 177 | static u32 davinci_spi_tx_buf_u8(struct davinci_spi *davinci_spi) |
176 | { | 178 | { |
177 | u32 data; | 179 | u32 data = 0; |
178 | const u8 *tx = davinci_spi->tx; | 180 | if (davinci_spi->tx) { |
179 | 181 | const u8 *tx = davinci_spi->tx; | |
180 | data = *tx++; | 182 | data = *tx++; |
181 | davinci_spi->tx = tx; | 183 | davinci_spi->tx = tx; |
184 | } | ||
182 | return data; | 185 | return data; |
183 | } | 186 | } |
184 | 187 | ||
185 | static u32 davinci_spi_tx_buf_u16(struct davinci_spi *davinci_spi) | 188 | static u32 davinci_spi_tx_buf_u16(struct davinci_spi *davinci_spi) |
186 | { | 189 | { |
187 | u32 data; | 190 | u32 data = 0; |
188 | const u16 *tx = davinci_spi->tx; | 191 | if (davinci_spi->tx) { |
189 | 192 | const u16 *tx = davinci_spi->tx; | |
190 | data = *tx++; | 193 | data = *tx++; |
191 | davinci_spi->tx = tx; | 194 | davinci_spi->tx = tx; |
195 | } | ||
192 | return data; | 196 | return data; |
193 | } | 197 | } |
194 | 198 | ||