linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spi-topcliff-pch: Fixed the possible null pointer exception issue
@ 2021-06-24 10:50 lijian_8010a29
  2021-06-24 11:44 ` Mark Brown
  2021-06-25 12:46 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: lijian_8010a29 @ 2021-06-24 10:50 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel, lijian

From: lijian <lijian@yulong.com>

The 'data->pkt_tx_buff' is used after called
‘kfree(data->pkt_tx_buff)’,it may be null when it is called,
and null pointer exception may occur,
so judgment is added when using 'data->pkt_tx_buff'.

Signed-off-by: lijian <lijian@yulong.com>
---
 drivers/spi/spi-topcliff-pch.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index b8870784fc6e..a5ac59f2eb80 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -599,7 +599,7 @@ static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw)
 	}
 
 	/* copy Tx Data */
-	if (data->cur_trans->tx_buf != NULL) {
+	if ((data->cur_trans->tx_buf != NULL) && (data->pkt_tx_buff != NULL)) {
 		if (*bpw == 8) {
 			tx_buf = data->cur_trans->tx_buf;
 			for (j = 0; j < data->bpw_len; j++)
@@ -621,8 +621,10 @@ static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw)
 		__func__);
 	pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW);
 
-	for (j = 0; j < n_writes; j++)
-		pch_spi_writereg(data->master, PCH_SPDWR, data->pkt_tx_buff[j]);
+	if (data->pkt_tx_buff != NULL) {
+		for (j = 0; j < n_writes; j++)
+			pch_spi_writereg(data->master, PCH_SPDWR, data->pkt_tx_buff[j]);
+	}
 
 	/* update tx_index */
 	data->tx_index = j;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-25 12:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 10:50 [PATCH] spi: spi-topcliff-pch: Fixed the possible null pointer exception issue lijian_8010a29
2021-06-24 11:44 ` Mark Brown
2021-06-25 12:46 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).