From patchwork Thu Jun 24 10:50:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: lijian_8010a29@163.com X-Patchwork-Id: 466669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDC77C48BDF for ; Thu, 24 Jun 2021 10:52:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0C1161405 for ; Thu, 24 Jun 2021 10:52:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbhFXKyW (ORCPT ); Thu, 24 Jun 2021 06:54:22 -0400 Received: from m12-17.163.com ([220.181.12.17]:53635 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231294AbhFXKyW (ORCPT ); Thu, 24 Jun 2021 06:54:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=pTZr7 M934qJGS/p1VktboAnozAKaukgQzPAAMTI6ZEU=; b=UOUztijBMBM3Zq1mnCao5 dW7/IisIuq7M2swceN4Rnbf5nery55FgRvjlpHerkwB+rQwFAG3jIcBIVYaOWKy/ 3piYjSZLqVX6BvycqPIoa+wqSTJGpg/H2uZRxJgfY7W+goGLoSMzAKUfsS14qgf0 6BCMA8JuXxwo9UIB71T55c= Received: from localhost.localdomain (unknown [218.17.89.92]) by smtp13 (Coremail) with SMTP id EcCowAC31ZXNY9RgiGNQ9Q--.32474S2; Thu, 24 Jun 2021 18:51:58 +0800 (CST) From: lijian_8010a29@163.com To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, lijian Subject: [PATCH] spi: spi-topcliff-pch: Fixed the possible null pointer exception issue Date: Thu, 24 Jun 2021 18:50:56 +0800 Message-Id: <20210624105056.167233-1-lijian_8010a29@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: EcCowAC31ZXNY9RgiGNQ9Q--.32474S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF1xtw4UWry8Ar1fCryrtFb_yoW8GF1xpF WDGa1qyrWrAF4kJFnrXFWUuFn8W3s7WryUu342kwnIvr18tryDtF4Utr97trWayF4IqF4a yr4IvryYq3ZYyF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bYL05UUUUU= X-Originating-IP: [218.17.89.92] X-CM-SenderInfo: 5olmxttqbyiikqdsmqqrwthudrp/1tbi3w67UGB0GoFjRAAAsS Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: lijian 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 Reported-by: kernel test robot Reported-by: Dan Carpenter --- 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;