Skip to contentSkip to conversation

media: i2c: ov5670: Fix conditions for clock access

PATCH In review Sakari Ailus 2 participants 3 messages May 2, 2023 – May 5, 2023

Subsystems (3)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 media: i2c: ov5670: Fix conditions for clock access

Leftovers from the earlier fix. Fix also the conditions for reading the clock-frequency property as well as accessing the clock.

Fixes 8df08ba4a331 ("media: ov5670: Fix probe on ACPI")
---
 drivers/media/i2c/ov5670.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ov5670.c +2 -2
index c5e783a06f06c..5437cf32a7b3a 100644
@@ -2661,9 +2661,9 @@ static int ov5670_probe(struct i2c_client *client)
 	}
 
 	ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL);
-	if (!IS_ERR_OR_NULL(ov5670->xvclk))
+	if (!IS_ERR(ov5670->xvclk))
 		input_clk = clk_get_rate(ov5670->xvclk);
-	else if (PTR_ERR(ov5670->xvclk) == -ENOENT)
+	else if (!ov5670->xvclk)
 		device_property_read_u32(&client->dev, "clock-frequency",
 					 &input_clk);
 	else
Signature · 1 line
2.30.2
#1 lore raw

Hi Sakari

Quoted 14 lines · Sakari Ailus

Leftovers from the earlier fix. Fix also the conditions for reading the clock-frequency property as well as accessing the clock.

Fixes 8df08ba4a331 ("media: ov5670: Fix probe on ACPI")
---
 drivers/media/i2c/ov5670.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ov5670.c +0 -0
index c5e783a06f06c..5437cf32a7b3a 100644

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2664

Quoted 5 lines
drivers/media/i2c/ov5670.c +1 -1
@@ -2661,9 +2661,9 @@ static int ov5670_probe(struct i2c_client *client)
 	}
 
 	ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL);
-	if (!IS_ERR_OR_NULL(ov5670->xvclk))
+	if (!IS_ERR(ov5670->xvclk))

Can't clk_get_optional() return NULL in the case the clock source is not available ?

Also, if !CONFIG_HAVE_CLK devm_clk_get_optional() returns 0.

I would then keep the _OR_NULL() part

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2666

Quoted 3 lines
drivers/media/i2c/ov5670.c +1 -1
 		input_clk = clk_get_rate(ov5670->xvclk);
-	else if (PTR_ERR(ov5670->xvclk) == -ENOENT)
+	else if (!ov5670->xvclk)

While here it's probably correct, we only want to read "clock-frequency" if xvclk == NULL (when either the clock providere is not there, or !CONFIG_HAVE_CLK)

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2669

Quoted 3 lines
drivers/media/i2c/ov5670.c +0 -0
 		device_property_read_u32(&client->dev, "clock-frequency",
 					 &input_clk);
 	else

Everything else is an error (in example, -EPROBE_DEFER)

Quoted 3 lines

--
2.30.2

author maintainer
#2 lore raw

Hi Jacopo,

Quoted 19 lines · Jacopo Mondi

Hi Sakari

Quoted 16 lines · Sakari Ailus

Leftovers from the earlier fix. Fix also the conditions for reading the clock-frequency property as well as accessing the clock.

Fixes 8df08ba4a331 ("media: ov5670: Fix probe on ACPI")
---
 drivers/media/i2c/ov5670.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ov5670.c +0 -0
index c5e783a06f06c..5437cf32a7b3a 100644
@@ -2661,9 +2661,9 @@ static int ov5670_probe(struct i2c_client *client)
 	}
 
Quoted 8 lines

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2664

Quoted 3 lines
drivers/media/i2c/ov5670.c +1 -1
 	ov5670->xvclk = devm_clk_get_optional(&client->dev, NULL);
-	if (!IS_ERR_OR_NULL(ov5670->xvclk))
+	if (!IS_ERR(ov5670->xvclk))

Can't clk_get_optional() return NULL in the case the clock source is not available ?

Also, if !CONFIG_HAVE_CLK devm_clk_get_optional() returns 0.

Correct. And in that case the clock-frequency property should be read instead.

Quoted 17 lines

I would then keep the _OR_NULL() part

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2666

Quoted 3 lines
drivers/media/i2c/ov5670.c +1 -1
 		input_clk = clk_get_rate(ov5670->xvclk);
-	else if (PTR_ERR(ov5670->xvclk) == -ENOENT)
+	else if (!ov5670->xvclk)

While here it's probably correct, we only want to read "clock-frequency" if xvclk == NULL (when either the clock providere is not there, or !CONFIG_HAVE_CLK)

drivers/media/i2c/ov5670.c static int ov5670_probe(struct i2c_client *client) · line 2669

Quoted 3 lines
drivers/media/i2c/ov5670.c +0 -0
 		device_property_read_u32(&client->dev, "clock-frequency",
 					 &input_clk);
 	else

Everything else is an error (in example, -EPROBE_DEFER)

Signature · 3 lines
Regards,

Sakari Ailus