Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2917783pxk; Mon, 28 Sep 2020 03:51:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL1B0WmS/tqNoJQhvuQhe35vI4AReWULmKPV6Wnr9zfRpQIlmblAjLIi456vXygICtE9dQ X-Received: by 2002:aa7:c419:: with SMTP id j25mr988941edq.109.1601290266283; Mon, 28 Sep 2020 03:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601290266; cv=none; d=google.com; s=arc-20160816; b=n65xdpdYJh6ECljVAh920K0U0zdQsSUTMnjF6e4fihRHVeT7RQOcNCI5e0WFTW0DwT qJP3AJd2JXv79Kkse1kTgBGwyntpecSMmT++TQRsuUoH/+zFdzH4SrOFSVKz/FjtPkCW 53e4c7VmL8MshqLqHrNyDzizhmqPyuPdaXgUCDdvSXowU+03Ygsv1yoTU/aL2n71uOLI OyGxg7ovruWu4hYYNezxkzxGMpMzWO+ko6QI99qYwpnwl5sfGg3WfU3duefw52SqS7T1 CFBai6JB68A63EtGstnogFgB3Z7rC+HWYKkuKzKiDweJ2jD8/TarDkkrdDK11O7cl3CI 828Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=hDFBYRpXo1olYXKlF3Qw3T+L7lMC0KWrRUihMRPqBeQ=; b=MWi0Tn6zV/yRmf+C+6bUnG/HSDt4Wa6PEszTqEoL+WQXCGwYTU88bnB2bCnoZn3d41 8l/RWOFC1bmxmhgo5iBsHIXhyPufIUgpr762xxbLONBGqNdnoyJCRKQVRKyRsBumzQKd VJm42F55N2vNg08YCNFxGu/qFuyrngvFA+MWyZxBQA0ASoUokj59lbb0565H3gAI9fK3 K1TZRZENOABDy/QriDEUhxqN234vBIaVcyFXajQh4nsSWwMpnpvv9cKpPDPHCN+Lhlfh yevFfXYw4zXSjh025o4UInXVIjZ1+xW/crvu2JwDYUmRdpolDpZbxtF6bB+ssaMRE7Zh hAyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lx24si334398ejb.89.2020.09.28.03.50.42; Mon, 28 Sep 2020 03:51:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726540AbgI1KtX (ORCPT + 99 others); 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