From patchwork Mon Nov 14 00:43:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Tang X-Patchwork-Id: 19489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1897827wru; Sun, 13 Nov 2022 17:00:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NpUmYDXtV+GsMFGS41ukIk9tGY9zCBK3vbMPp+ZZwgK+hGYKzk8gCTuwV9jkEweM+Tq5r X-Received: by 2002:a17:90a:38c1:b0:205:f921:90ff with SMTP id x59-20020a17090a38c100b00205f92190ffmr11663947pjb.156.1668387639021; Sun, 13 Nov 2022 17:00:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668387639; cv=none; d=google.com; s=arc-20160816; b=nChbtM7LdIH7IjCSxzrRh0Kj6FsjssL6xezuPN/kSOOTYnSjuV5qtVkN21kYkWjMey iIMVJ41261GdjilfG6RkDvt4YAi+EcFuE86lL7Mv1LN/DDBqHmuNashNITlx3XwzCZ3I XkNPT7p36TB/wcZ66Ecr42uuiQ6VfByuUJKHvA5jfTDyzbYM2dUrJto8d3zbln353jVb t/VMJGD69qulF7YqCNhJRaz+BD42b2dxdsNAOCXAU/H1UA7uP9X3KXgLcCwnKd9W+fMk o0n+5VSiVpovfcbm8iQ0NSO1j4UfM87R0My6iVZ+KSmyqg7NoajSXpeZ+IaMAMzxb4c8 js6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=ST0ibcFeCWxcXgVr6Ij6/+PAwYoi5fghUuFfC3hbJew=; b=j8fMGtPTwDVrUl3NKJfAjC7oV0AJA2i3/i8ecKl2hIbseR1Uv8wzNBKtX6q83gHYab RsPWayZly6Y02Ue09WOC/WehF7Xx9zO73H1Wn9X40KOaDIMx00SdwsZ2d1w1v8cUJHIH Q/0ooSMiYhqqBkb1u3wsU3LnG3T4CHtDvWjiaV8XPMfo8ZSo39mlI4IBvKfzBmu+b8Sl IHyqmY8fN1Bx/5XGlE0mj19ksJcfTXBEXA1imukYPjAnhpk0sAYirVIw1u31RqMiYEE9 ANtEfLJ+hK3K5XVzVU876JCwJw5yrQojdqStObLYNM7g81T3syoJD8r73bVkS56p6Aki NtRA== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020a62520f000000b00567719e34aesi7466148pfb.49.2022.11.13.17.00.24; Sun, 13 Nov 2022 17:00:39 -0800 (PST) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbiKNAqu (ORCPT + 99 others); Sun, 13 Nov 2022 19:46:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbiKNAqs (ORCPT ); Sun, 13 Nov 2022 19:46:48 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 352BBE0FD; Sun, 13 Nov 2022 16:46:47 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N9VxG3mcnz15Mbw; Mon, 14 Nov 2022 08:46:26 +0800 (CST) Received: from kwepemm600005.china.huawei.com (7.193.23.191) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 14 Nov 2022 08:46:44 +0800 Received: from ubuntu1804.huawei.com (10.67.175.30) by kwepemm600005.china.huawei.com (7.193.23.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 14 Nov 2022 08:46:44 +0800 From: Hui Tang To: CC: , Subject: [PATCH] i2c: mux: reg: Fix possible null-ptr-deref Date: Mon, 14 Nov 2022 08:43:22 +0800 Message-ID: <20221114004322.257455-1-tanghui20@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.30] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600005.china.huawei.com (7.193.23.191) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749431237064446367?= X-GMAIL-MSGID: =?utf-8?q?1749431237064446367?= It will cause null-ptr-deref when resource_size(res) invoked, if platform_get_resource() returns NULL. Fixes: b3fdd32799d8 ("i2c: mux: Add register-based mux i2c-mux-reg") Signed-off-by: Hui Tang --- drivers/i2c/muxes/i2c-mux-reg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index 0e0679f65cf7..d26de1017385 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -184,12 +184,12 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Register not set, using platform resource\n"); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - mux->data.reg_size = resource_size(res); mux->data.reg = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(mux->data.reg)) { ret = PTR_ERR(mux->data.reg); goto err_put_parent; } + mux->data.reg_size = resource_size(res); } if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&