From patchwork Thu Sep 10 16:18:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1361685 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=wPr6KrEg; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnPFd3HHqz9sSP for ; Fri, 11 Sep 2020 02:18:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8A58182351; Thu, 10 Sep 2020 18:18:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="wPr6KrEg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ADDA782364; Thu, 10 Sep 2020 18:18:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7940082351 for ; Thu, 10 Sep 2020 18:18:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08AGGoDT023146; Thu, 10 Sep 2020 18:18:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=STMicroelectronics; bh=lccH6lOyYpcmpo0Ov/wWvpCd1DhxkVdx7xkNUe5tCcY=; b=wPr6KrEg65BhnEL+AYHUumMZxSbysSLT7pytJAVNswY5DnXxUejDe4oLCPA0sCUi16fr zqGzYfvQzFVGyUYZlccGb7YggOvsAuScccuawImCwpufANrOizhId0Go3JcIELKXFjB4 LzHqeCSTRN67T1LfKQ/rBWNENweLbMXWxlpjhen18J9IznxTYuwLmfeMLIjpNjYA2lUn f1CsfQJvxF+GshZ/Zi7U7/E53+BW7Y95oSX8ClkVn8Jq/H6rLz16VKeYDpRDGV/sX+xV nMLdFPfhwd2OuBRUt5pEUiRNdZV4nTO3u5xxpTVNs06zoU19XL3h1WYm87+8CC8JeYsM jQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 33c0ev45ah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Sep 2020 18:18:20 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E6527100034; Thu, 10 Sep 2020 18:18:19 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id D92742BA2D8; Thu, 10 Sep 2020 18:18:19 +0200 (CEST) Received: from localhost (10.75.127.50) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 10 Sep 2020 18:18:19 +0200 From: Patrick Delaunay To: CC: Patrick Delaunay , Jaehoon Chung , Simon Glass , U-Boot STM32 Subject: [PATCH 1/2] power: regulator: gpio-regulator: protect count value Date: Thu, 10 Sep 2020 18:18:16 +0200 Message-ID: <20200910161817.27535-1-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG4NODE3.st.com (10.75.127.12) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-10_04:2020-09-10, 2020-09-10 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Update the size of states_array to avoid overflow for dev_pdata->voltages[j] and dev_pdata->states[j]. As the size of array is GPIO_REGULATOR_MAX_STATES, the size of states_array is limited by GPIO_REGULATOR_MAX_STATES * 2 = 4 instead of 8 previously. The value of the "count" variable is limited by the third parameter of fdtdec_get_int_array_count. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- drivers/power/regulator/gpio-regulator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/power/regulator/gpio-regulator.c b/drivers/power/regulator/gpio-regulator.c index 947f812d09..017a3644fe 100644 --- a/drivers/power/regulator/gpio-regulator.c +++ b/drivers/power/regulator/gpio-regulator.c @@ -35,7 +35,7 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev) const void *blob = gd->fdt_blob; int node = dev_of_offset(dev); int ret, count, i, j; - u32 states_array[8]; + u32 states_array[GPIO_REGULATOR_MAX_STATES * 2]; dev_pdata = dev_get_platdata(dev); uc_pdata = dev_get_uclass_platdata(dev); @@ -58,7 +58,8 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev) debug("regulator gpio - not found! Error: %d", ret); count = fdtdec_get_int_array_count(blob, node, "states", - states_array, 8); + states_array, + ARRAY_SIZE(states_array)); if (!count) return -EINVAL; From patchwork Thu Sep 10 16:18:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1361686 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=KH8k73/W; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BnPFq2zymz9sSP for ; Fri, 11 Sep 2020 02:18:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 579AA8237B; Thu, 10 Sep 2020 18:18:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="KH8k73/W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DAC6882361; Thu, 10 Sep 2020 18:18:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 24E1D82337 for ; Thu, 10 Sep 2020 18:18:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08AGDADx013125; Thu, 10 Sep 2020 18:18:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=622U/G2f2UhwGSgNbRGhHbrirybN982HhMIj3wPf9P0=; b=KH8k73/Wh9LvfM171ZAM154fVtZIkKOpEC7atA+Wy4vH2tPDLZoS9COp3W2231Q+nWsU mbUEdccMQJ9oePjVEy1zglVnDomEUbO9TC592M4TyUPTRCliWKBFatsqUNvZ6Efg7Ve5 rAUfb7ZUMVTEK5tVjb2Yuu6kTMpy5clGehDtaHwJFlL5HKz7cyWn+oDSCO4d/sEOjVuV 0QE5f/YTMeZdmct6DX36d19rkHCBmRb/Z6k4MlC9Y4sftvB37J9Pd/RW832NXu3nRB4a zH/ZgweNM7yNqLlgWmbbUiI6JGgjRRJuOs71FYUWQgrk+MbU3Hy8Onii7H20S1TM7Jgf lQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 33c051m71n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Sep 2020 18:18:21 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BE8E5100038; Thu, 10 Sep 2020 18:18:20 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag6node3.st.com [10.75.127.18]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AF9EE2BA2D8; Thu, 10 Sep 2020 18:18:20 +0200 (CEST) Received: from localhost (10.75.127.48) by SFHDAG6NODE3.st.com (10.75.127.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 10 Sep 2020 18:18:20 +0200 From: Patrick Delaunay To: CC: Patrick Delaunay , Jaehoon Chung , Simon Glass , U-Boot STM32 Subject: [PATCH 2/2] power: regulator: gpio-regulator: Convert to use APIs which support live DT Date: Thu, 10 Sep 2020 18:18:17 +0200 Message-ID: <20200910161817.27535-2-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910161817.27535-1-patrick.delaunay@st.com> References: <20200910161817.27535-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG6NODE3.st.com (10.75.127.18) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-10_05:2020-09-10, 2020-09-10 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Use ofnode_ or dev_ APIs instead of fdt_ and fdtdec_ APIs so that the driver can support live DT. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- drivers/power/regulator/gpio-regulator.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/power/regulator/gpio-regulator.c b/drivers/power/regulator/gpio-regulator.c index 017a3644fe..28c9e222e2 100644 --- a/drivers/power/regulator/gpio-regulator.c +++ b/drivers/power/regulator/gpio-regulator.c @@ -18,8 +18,6 @@ #define GPIO_REGULATOR_MAX_STATES 2 -DECLARE_GLOBAL_DATA_PTR; - struct gpio_regulator_platdata { struct regulator_common_platdata common; struct gpio_desc gpio; /* GPIO for regulator voltage control */ @@ -32,8 +30,6 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev) struct dm_regulator_uclass_platdata *uc_pdata; struct gpio_regulator_platdata *dev_pdata; struct gpio_desc *gpio; - const void *blob = gd->fdt_blob; - int node = dev_of_offset(dev); int ret, count, i, j; u32 states_array[GPIO_REGULATOR_MAX_STATES * 2]; @@ -57,12 +53,20 @@ static int gpio_regulator_ofdata_to_platdata(struct udevice *dev) if (ret) debug("regulator gpio - not found! Error: %d", ret); - count = fdtdec_get_int_array_count(blob, node, "states", - states_array, - ARRAY_SIZE(states_array)); + ret = dev_read_size(dev, "states"); + if (ret < 0) + return ret; - if (!count) - return -EINVAL; + count = ret / sizeof(states_array[0]); + if (count > ARRAY_SIZE(states_array)) { + debug("regulator gpio - to many states (%d > %d)", + count / 2, GPIO_REGULATOR_MAX_STATES); + count = ARRAY_SIZE(states_array); + } + + ret = dev_read_u32_array(dev, "states", states_array, count); + if (ret < 0) + return ret; for (i = 0, j = 0; i < count; i += 2) { dev_pdata->voltages[j] = states_array[i];