From mboxrd@z Thu Jan 1 00:00:00 1970 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=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 33583C2D0A8 for ; Mon, 28 Sep 2020 10:49:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB2F620789 for ; Mon, 28 Sep 2020 10:49:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbgI1KtX (ORCPT ); Mon, 28 Sep 2020 06:49:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14307 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726465AbgI1KtX (ORCPT ); Mon, 28 Sep 2020 06:49:23 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7BF8F6792C3B33BAAEFF; Mon, 28 Sep 2020 18:49:21 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 28 Sep 2020 18:49:12 +0800 From: Jing Xiangfeng To: , , , , CC: , , Subject: [PATCH] staging: most: don't access hdm_ch before checking it valid Date: Mon, 28 Sep 2020 18:48:38 +0800 Message-ID: <20200928104838.189639-1-jingxiangfeng@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In try_start_dim_transfer(), pointer hdm_ch is accessed before checking. This may lead to a potential null pointer dereference. Fix this by dereferencing hdm_ch after calling BUG_ON(). Signed-off-by: Jing Xiangfeng --- drivers/staging/most/dim2/dim2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c index 509c8012d20b..ccd7cc7545e4 100644 --- a/drivers/staging/most/dim2/dim2.c +++ b/drivers/staging/most/dim2/dim2.c @@ -148,7 +148,7 @@ void dimcb_on_error(u8 error_id, const char *error_message) static int try_start_dim_transfer(struct hdm_channel *hdm_ch) { u16 buf_size; - struct list_head *head = &hdm_ch->pending_list; + struct list_head *head; struct mbo *mbo; unsigned long flags; struct dim_ch_state_t st; @@ -156,6 +156,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch) BUG_ON(!hdm_ch); BUG_ON(!hdm_ch->is_initialized); + head = &hdm_ch->pending_list; spin_lock_irqsave(&dim_lock, flags); if (list_empty(head)) { spin_unlock_irqrestore(&dim_lock, flags); -- 2.17.1