Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3310829rwd; Mon, 29 May 2023 08:33:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7PGepbGwIUFVJfYVSDiSUV3QHJv5eieFYnWFr2d9d43NhMKufY0kOIIoQys38SmURIiZbg X-Received: by 2002:a05:6a20:3d04:b0:102:18a9:cad7 with SMTP id y4-20020a056a203d0400b0010218a9cad7mr10217866pzi.58.1685374405178; Mon, 29 May 2023 08:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685374405; cv=none; d=google.com; s=arc-20160816; b=eDoup2Z4p/z8QP+cz3ajido51Nylb5rYkX6vWQsPlCfxm0njKMrJUX2tRNFp2nfRGg ixbA7Ny+qBIzXC2GFshdBlCthGHLtNA0i89xQho4RdFtHQmdPU+uyOXO4sOCI28pGyN0 WWbTdb1yzT0x1yxkoa6uglr/gokbN91OLSQkOFQ97uMpjWOXjDykjD+Z9w3c9daM8x9I u9DKw4VfuAvMORgO89K4S5z+AdvWKEpSLxOgEMElrpuFMdgZaOtP/p4rmfm3U8M4ajGS RPxnuGppPKbcVxWAPk6PjOCmL3KKRet6o60j1fixI/QSTqgmXP65W0sLjbBvczj2/cVn Nfag== 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=yiPDcXuVA7yTNtxjdyxRW/uNk/TiPgRwxr60DNcGs1M=; b=U5TipurFmEpAJA3OMcaa4Tr6alqA9TjdX3RledHwi23UgCvRIAVkGNp9S82C4PW+MA mwMTBvmvHThkaf4y7Os52rFWoeCHa4caViPjzpWVeFejszk8SSo86VY4jTrpyYzx1GZu cIsny2X/6PKsvj64AlFl4Z0ug4z7wDDotme99ZPor78g0CEvYqcCElKN/UnAYGTEOfAt M09kBrdcVwyDAY2N46Wg+c+OMCNqek4pfibWT4GjoriepOC5OC0rL2b03WqWLd1NCJjC 9dMBYenyQbeKqP8ZJxIe1av5ymVpwHx8DOcnccTsAnY8tYa7VwUk1JSZjt12sds79zcy Y52A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l131-20020a633e89000000b0053eef685a0csi8697097pga.852.2023.05.29.08.33.10; Mon, 29 May 2023 08:33:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbjE2PXM (ORCPT + 99 others); Mon, 29 May 2023 11:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjE2PXK (ORCPT ); Mon, 29 May 2023 11:23:10 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD155D2; Mon, 29 May 2023 08:23:06 -0700 (PDT) Received: from pride-poweredge-r740.. ([172.16.0.254]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 34TFLoKa032373-34TFLoKd032373 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 29 May 2023 23:21:55 +0800 From: Dongliang Mu To: Hans de Goede , Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Dongliang Mu , Andy Shevchenko Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] media: atomisp: move the sanity checks before variable dereferences Date: Mon, 29 May 2023 23:21:30 +0800 Message-Id: <20230529152136.11719-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: dzm91@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Smatch reports: sh_css_load_firmware() warn: variable dereferenced before check 'fw_data' The variable fw_data can be NULL in sh_css_load_firmware, resulting in NULL pointer dereference. Fix this by moving the sanity checks before variable dereferences. Signed-off-by: Dongliang Mu --- drivers/staging/media/atomisp/pci/sh_css_firmware.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/sh_css_firmware.c b/drivers/staging/media/atomisp/pci/sh_css_firmware.c index e7ef578db8ab..38b757c3df0a 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_firmware.c +++ b/drivers/staging/media/atomisp/pci/sh_css_firmware.c @@ -229,6 +229,10 @@ sh_css_load_firmware(struct device *dev, const char *fw_data, struct sh_css_fw_bi_file_h *file_header; int ret; + /* some sanity checks */ + if (!fw_data || fw_size < sizeof(struct sh_css_fw_bi_file_h)) + return -EINVAL; + firmware_header = (struct firmware_header *)fw_data; file_header = &firmware_header->file_header; binaries = &firmware_header->binary_header; @@ -243,10 +247,6 @@ sh_css_load_firmware(struct device *dev, const char *fw_data, IA_CSS_LOG("successfully load firmware version %s", release_version); } - /* some sanity checks */ - if (!fw_data || fw_size < sizeof(struct sh_css_fw_bi_file_h)) - return -EINVAL; - if (file_header->h_size != sizeof(struct sh_css_fw_bi_file_h)) return -EINVAL; -- 2.34.1