Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1908540lqa; Tue, 30 Apr 2024 02:59:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWgsstQfbavqFV9Qa+RTHNpgPzWbEdzPqeRj43dR0gGssWmy621PXIgUQ+57w8TiRiC5np6o8UDI7Nzklb4mvtVsVttp95WylUDat8zXg== X-Google-Smtp-Source: AGHT+IHB9svOmwvBTYu08URFizGysLGZqEWH0XDilsvQ807JCK9V/ysdsXVdsOiKFN5oKi/4KNsr X-Received: by 2002:a50:f61b:0:b0:572:325a:8515 with SMTP id c27-20020a50f61b000000b00572325a8515mr11355524edn.36.1714471180106; Tue, 30 Apr 2024 02:59:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714471180; cv=pass; d=google.com; s=arc-20160816; b=cysI4Oa9S4uqbNqkqiJ6zn60aXmWioLOBDLuJiOgzzf01ECC5YEIE7hAK+USmbKvsE oEQnFp/YHjuuSyB2EX7JarxrJpJhRloZPWTJci9eT/3mkgsSxMKtDMJGnEL+AhblsO6u mEoart/HZuGmXg8GFNN0ZznxTsgBthlMRKhEUPvGg7WS3DY5eHz7emqKp4QLazR4pzRA rqPABF+WqGZzlQ7xnh7rVc/nYNKcCKbMjZQZ2BZSZEZSV2lXjxw9a2+lUn5sZgCKhplB 7LqI69cgu2nnEha2o9pxyEAcY9XDx5IVg6Advt+lzsdBQfIDj/yT9dbu15AdZuS9UOHw 4DHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from; bh=omww5mExBHevlTrytM8iS5RFpGRHUtoahO6HcZENUhM=; fh=tnqHSLcNjGPJ99BdeEeSs5RnuwjnVS1kZmtKFj0LaU0=; b=hb27/CGF3pK+0G2V6vEC9i+WN1MPrf+YUvbMIZn+eaMux+0t/aqSFqqoWtAEwRunNS h2Mnt0NXICDaA7lt0xstJBVithxrvg0b18iqwm5GVXUnHWLQkfyNOYxYN/wsJiX0mENs UTq3rkAtZYuSDPWKnD9yZnpxLevfAlysaDxy+TNK+4p25GoDUZSpkxNJrHLUSPf831Jn 9BYQjac5EGG2fgOZmc5aKyd5xAXOOpoWQky6mJw2opSOZgEblStQUWMoWnqE+LAX17ty dJXAg9pO12hvT8M+/j3AjexA63Jupq0gN5Z0Im/JlkXdBmbeg+z/SioUUVGv4isWxnwx RA1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=richtek.com); spf=pass (google.com: domain of linux-kernel+bounces-163732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163732-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s26-20020a508d1a000000b0057279f54876si2968603eds.626.2024.04.30.02.59.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 02:59:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=richtek.com); spf=pass (google.com: domain of linux-kernel+bounces-163732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163732-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D11E31F24318 for ; Tue, 30 Apr 2024 09:59:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5693E1420A6; Tue, 30 Apr 2024 09:58:54 +0000 (UTC) Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3FCC128833 for ; Tue, 30 Apr 2024 09:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.130.44.152 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; cv=none; b=ZATor0FXauMj0ScIj7nhq60G8dntL4A8WzMAMMr9TLqGxiOwUhuI8F0vzD39I5xUbNkgzfW0YOGJKmSYEZS7hi1eBPj8kNArDNlIM0A9eYFbarnC4y8wmaUTdbd1fihDOhZPY+/UBLnwx+hw7kUEnuRpOBP1GamRsCxOgwr4rLU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471133; c=relaxed/simple; bh=aLW+hLhtsKefh2Nh1SYqXbYSstdwqst9ixv2hu0e2fg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HzF6hVdVxTFwkYyZmUrTYaHXD29rFi/ky8rVjH4o3AQqxDBj3uCYijca/cUwBSrk6+Tl/X9yh15HXxGcWvCUP1XXc71oHYYHQqk9hwTXEMlnZP3rimhtxHFsy8t0v+023wDZ8eysfzB/7n40LpTSHYTFD4Vclet7U0eM9qOjWO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com; spf=pass smtp.mailfrom=richtek.com; arc=none smtp.client-ip=220.130.44.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(3367343:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Tue, 30 Apr 2024 17:58:31 +0800 (CST) Received: from ex4.rt.l (192.168.10.47) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 30 Apr 2024 17:58:30 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex4.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Tue, 30 Apr 2024 17:58:30 +0800 From: Alina Yu To: , CC: , , , Subject: [PATCH v2 3/4] regulator: rtq2208: Fix invalid memory access when devm_of_regulator_put_matches is called Date: Tue, 30 Apr 2024 17:58:26 +0800 Message-ID: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain In this patch, a software bug has been fixed. rtq2208_ldo_match is no longer a local variable. It prevents invalid memory access when devm_of_regulator_put_matches is called. Signed-off-by: Alina Yu --- drivers/regulator/rtq2208-regulator.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/rtq2208-regulator.c b/drivers/regulator/rtq2208-regulator.c index 80a4d2f..97a97a4 100644 --- a/drivers/regulator/rtq2208-regulator.c +++ b/drivers/regulator/rtq2208-regulator.c @@ -246,6 +246,11 @@ static const unsigned int rtq2208_ldo_volt_table[] = { 3300000, }; +static struct of_regulator_match rtq2208_ldo_match[] = { + {.name = "ldo2", }, + {.name = "ldo1", }, +}; + static unsigned int rtq2208_of_map_mode(unsigned int mode) { switch (mode) { @@ -340,8 +345,7 @@ static irqreturn_t rtq2208_irq_handler(int irqno, void *devid) return IRQ_HANDLED; } -static int rtq2208_of_get_ldo_dvs_ability(struct device *dev, - struct of_regulator_match *rtq2208_ldo_match, int n_fixed) +static int rtq2208_of_get_ldo_dvs_ability(struct device *dev) { struct device_node *np; struct of_regulator_match *match; @@ -356,14 +360,14 @@ static int rtq2208_of_get_ldo_dvs_ability(struct device *dev, if (!np) np = dev->of_node; - ret = of_regulator_match(dev, np, rtq2208_ldo_match, n_fixed); + ret = of_regulator_match(dev, np, rtq2208_ldo_match, ARRAY_SIZE(rtq2208_ldo_match)); of_node_put(np); if (ret < 0) return ret; - for (i = 0; i < n_fixed; i++) { + for (i = 0; i < ARRAY_SIZE(rtq2208_ldo_match); i++) { match = rtq2208_ldo_match + i; init_data = match->init_data; desc = (struct regulator_desc *)match->desc; @@ -413,8 +417,7 @@ static const struct linear_range rtq2208_vout_range[] = { REGULATOR_LINEAR_RANGE(1310000, 181, 255, 10000), }; -static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel, - int idx, struct of_regulator_match *rtq2208_ldo_match, int *ldo_idx) +static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, int mtp_sel, int idx) { struct regulator_desc *desc; static const struct { @@ -486,8 +489,7 @@ static void rtq2208_init_regulator_desc(struct rtq2208_regulator_desc *rdesc, in static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int *regulator_idx_table, struct rtq2208_regulator_desc *rdesc[RTQ2208_LDO_MAX], struct device *dev) { - struct of_regulator_match rtq2208_ldo_match[2]; - int mtp_sel, ret, i, idx, ldo_idx = 0; + int mtp_sel, i, idx, ret; /* get mtp_sel0 or mtp_sel1 */ mtp_sel = device_property_read_bool(dev, "richtek,mtp-sel-high"); @@ -499,14 +501,14 @@ static int rtq2208_parse_regulator_dt_data(int n_regulator, const unsigned int * if (!rdesc[i]) return -ENOMEM; - rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx, rtq2208_ldo_match, &ldo_idx); + rtq2208_init_regulator_desc(rdesc[i], mtp_sel, idx); /* init ldo dvs ability */ if (idx >= RTQ2208_LDO2) rtq2208_ldo_match[idx - RTQ2208_LDO2].desc = &rdesc[i]->desc; } - ret = rtq2208_of_get_ldo_dvs_ability(dev, rtq2208_ldo_match, ldo_idx); + ret = rtq2208_of_get_ldo_dvs_ability(dev); if (ret) return dev_err_probe(dev, ret, "Failed to get ldo fixed_uV\n"); -- 2.7.4