lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220519075117.1003520-2-tommaso.merciai@amarulasolutions.com>
Date:   Thu, 19 May 2022 09:51:14 +0200
From:   Tommaso Merciai <tommaso.merciai@...rulasolutions.com>
To:     unlisted-recipients:; (no To-header on input)
Cc:     tommaso.merciai@...rulasolutions.com, linuxfancy@...glegroups.com,
        linux-amarula@...rulasolutions.com, michael@...rulasolutions.com,
        Shunqian Zheng <zhengsq@...k-chips.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 1/4] media: i2c: ov5695: use regulator_bulk_enable/regulator_bulk disable instead of for loop

Enable regulator using regulator_bulk_enable/regulatore_bulk_disable
function in __ov5695_power_on/__ov5695_power_off function instead of for loop.
This reduce code size and make things more clear

Signed-off-by: Tommaso Merciai <tommaso.merciai@...rulasolutions.com>
Co-Developed-by: Michael Trimarchi <michael@...rulasolutions.com>
---
 drivers/media/i2c/ov5695.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/media/i2c/ov5695.c b/drivers/media/i2c/ov5695.c
index 439385938a51..880b586e55fe 100644
--- a/drivers/media/i2c/ov5695.c
+++ b/drivers/media/i2c/ov5695.c
@@ -972,7 +972,7 @@ static int ov5695_s_stream(struct v4l2_subdev *sd, int on)
 
 static int __ov5695_power_on(struct ov5695 *ov5695)
 {
-	int i, ret;
+	int ret;
 	struct device *dev = &ov5695->client->dev;
 
 	ret = clk_prepare_enable(ov5695->xvclk);
@@ -987,13 +987,10 @@ static int __ov5695_power_on(struct ov5695 *ov5695)
 	 * The hardware requires the regulators to be powered on in order,
 	 * so enable them one by one.
 	 */
-	for (i = 0; i < OV5695_NUM_SUPPLIES; i++) {
-		ret = regulator_enable(ov5695->supplies[i].consumer);
-		if (ret) {
-			dev_err(dev, "Failed to enable %s: %d\n",
-				ov5695->supplies[i].supply, ret);
-			goto disable_reg_clk;
-		}
+	ret = regulator_bulk_enable(ARRAY_SIZE(ov5695->supplies), ov5695->supplies);
+	if (ret) {
+		dev_err(dev, "Failed to enable regulators %d\n", ret);
+		goto disable_reg_clk;
 	}
 
 	gpiod_set_value_cansleep(ov5695->reset_gpio, 0);
@@ -1003,8 +1000,7 @@ static int __ov5695_power_on(struct ov5695 *ov5695)
 	return 0;
 
 disable_reg_clk:
-	for (--i; i >= 0; i--)
-		regulator_disable(ov5695->supplies[i].consumer);
+	regulator_bulk_disable(ARRAY_SIZE(ov5695->supplies), ov5695->supplies);
 	clk_disable_unprepare(ov5695->xvclk);
 
 	return ret;
@@ -1012,8 +1008,6 @@ static int __ov5695_power_on(struct ov5695 *ov5695)
 
 static void __ov5695_power_off(struct ov5695 *ov5695)
 {
-	struct device *dev = &ov5695->client->dev;
-	int i, ret;
 
 	clk_disable_unprepare(ov5695->xvclk);
 	gpiod_set_value_cansleep(ov5695->reset_gpio, 1);
@@ -1022,12 +1016,7 @@ static void __ov5695_power_off(struct ov5695 *ov5695)
 	 * The hardware requires the regulators to be powered off in order,
 	 * so disable them one by one.
 	 */
-	for (i = OV5695_NUM_SUPPLIES - 1; i >= 0; i--) {
-		ret = regulator_disable(ov5695->supplies[i].consumer);
-		if (ret)
-			dev_err(dev, "Failed to disable %s: %d\n",
-				ov5695->supplies[i].supply, ret);
-	}
+	regulator_bulk_disable(ARRAY_SIZE(ov5695->supplies), ov5695->supplies);
 }
 
 static int __maybe_unused ov5695_runtime_resume(struct device *dev)
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ