Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp165316pxh; Tue, 9 Nov 2021 23:23:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyst2/YNSxX4SC3cVEmIt1F9xsZqZAkbZdDdpdEYH5Yyi/WGyOceeFJNTbqaMQG/7w6aDU X-Received: by 2002:a05:6602:29c2:: with SMTP id z2mr9256781ioq.73.1636528987385; Tue, 09 Nov 2021 23:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636528987; cv=none; d=google.com; s=arc-20160816; b=ZtXYgp6XeOE7sFnK7iBYjXfGbyETsukx9rA/iSlc5ZIjhbeKm115BAJcmU8iGvp9di +8Fpim8FCAFSBbEI7B7cE9e74qCOaK7TkL2DIeqpeY8p+tFeSBH86FNptpwnHnoNRKYR BQ/0Zpw25y7Qu7G4NolnG1L6Os+pg+AzgcbJmUduAJ6PL6ArWoWNmO0d4Z8/HdvQ9iTw 1SyeacGjnnWWqKXu2zyVFE4zWqNOZBU8u/9DLmFNrA9ktabw/fU25V0XMZbw8KCap+xJ 0zoj3MGPhkpDGSROjI6LrwSuhQk7wjHxHbiGlvRyh9qV3QoFB6SyeOLvj2T9rNSpJGh3 ycgg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=OLDcds/NT7bYm2NqhA8lkjSB8Q7Lk3r49WD0wBRl/+E=; b=QQPHpEfUDYtpaZCMSKcPsXw8fd1SbxKnUk8M2X3BH1YD7eHtPixdenTArG/P9qaXZF RQk5WN+4IkqoFX7A9vHSDUbxNP0a+u1TB+MFrZ0UOkOaEa1TeczOlWDjZ3kgA5yVR41P YITKGRpjJXC5n5+08lUgWVxny+aaTeuVJJNJn29q5gy3MHMlIyQprfMVtM4woH7YYn4c LAyGJiEKySmkW/rGEG2ATjEJ7mEGLLXqbKFiwWF0ervHFaZ1rFnkH+F7JxX0/yb+VHfv xltqyaNrmKK10TBYTr6vHK6q6rYxcSPVjtNxhKBNQsWvHwdhEbKyBsI2JPtyHpuI6oHM 1dFA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n10si11196041ioz.37.2021.11.09.23.22.54; Tue, 09 Nov 2021 23:23:07 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbhKJHWE (ORCPT + 99 others); Wed, 10 Nov 2021 02:22:04 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:40140 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229567AbhKJHWC (ORCPT ); Wed, 10 Nov 2021 02:22:02 -0500 X-UUID: 7324b64ed486497696925dd4ddafaafc-20211110 X-UUID: 7324b64ed486497696925dd4ddafaafc-20211110 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1047556568; Wed, 10 Nov 2021 15:19:05 +0800 Received: from mtkmbs10n1.mediatek.inc (172.21.101.34) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Wed, 10 Nov 2021 15:19:03 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs10n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Wed, 10 Nov 2021 15:19:02 +0800 From: Zhiyong Tao To: , , , , CC: , , , , , , , , , , , , , "Guodong Liu" , Chen-Yu Tsai Subject: [PATCH v4] pinctrl: mediatek: fix global-out-of-bounds issue Date: Wed, 10 Nov 2021 15:19:00 +0800 Message-ID: <20211110071900.4490-2-zhiyong.tao@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110071900.4490-1-zhiyong.tao@mediatek.com> References: <20211110071900.4490-1-zhiyong.tao@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guodong Liu When eint virtual eint number is greater than gpio number, it maybe produce 'desc[eint_n]' size globle-out-of-bounds issue. Signed-off-by: Guodong Liu Signed-off-by: Zhiyong Tao Reviewed-by: Chen-Yu Tsai --- Changes in patch v4: 1. fix sort signed-off-by name. 2. add Reviewed-by. Changes in patch v3: 1. keep original patch author 2. fix version issue. Changes in patch v2: 1. change check eint number boundary condition. --- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c index 45ebdeba985a..12163d3c4bcb 100644 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c @@ -285,8 +285,12 @@ static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n, desc = (const struct mtk_pin_desc *)hw->soc->pins; *gpio_chip = &hw->chip; - /* Be greedy to guess first gpio_n is equal to eint_n */ - if (desc[eint_n].eint.eint_n == eint_n) + /* + * Be greedy to guess first gpio_n is equal to eint_n. + * Only eint virtual eint number is greater than gpio number. + */ + if (hw->soc->npins > eint_n && + desc[eint_n].eint.eint_n == eint_n) *gpio_n = eint_n; else *gpio_n = mtk_xt_find_eint_num(hw, eint_n); -- 2.25.1