Skip to contentSkip to conversation

media: i2c: mt9m114: use fsleep() in place of udelay()

PATCH In review Arnd Bergmann 3 participants 6 messages Dec 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: i2c: mt9m114: use fsleep() in place of udelay()

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

              drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")
---
 drivers/media/i2c/mt9m114.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +1 -1
index 0a22f328981d..68adaecaf481 100644
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
 		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
 		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
 		gpiod_set_value(sensor->reset, 0);
 	} else {
 		/*
Signature · 1 line
2.39.2
maintainer Reviewed-by on v2 1/1
#1 lore raw

Hi Arnd,

Thank you for the patch.

Quoted 9 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

              drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a
Quoted 8 lines

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

The longest delay would be 16.66µs, which may not be worth a sleep, but I think that's fine. Using fsleep() by default is a good idea.

Quoted 4 lines
Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")

---

Quoted 16 lines
 drivers/media/i2c/mt9m114.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +1 -1
index 0a22f328981d..68adaecaf481 100644
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
 		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
 		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
 		gpiod_set_value(sensor->reset, 0);
 	} else {
 		/*
Signature · 3 lines
Regards,

Laurent Pinchart
Reviewed-by on v2 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 30 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

               drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")
---
  drivers/media/i2c/mt9m114.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +0 -0
index 0a22f328981d..68adaecaf481 100644

drivers/media/i2c/mt9m114.c static int mt9m114_power_on(struct mt9m114 *sensor) · line 2122

Quoted 8 lines
drivers/media/i2c/mt9m114.c +1 -1
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
  		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
  		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
  		gpiod_set_value(sensor->reset, 0);
  	} else {
  		/*

I think this is fine, so:

But: If we don't have COMMON_CLK (or rather, I think, HAVE_CLK), the freq will be zero at compile time. So won't the compiler give a warning for the DIV_ROUND_UP() call?

Interestingly, for me, this doesn't give a div-by-zero warning:

	int x;
	int y = 0;
	x = DIV_ROUND_UP(10, y);

but this does:

	int x;
	const int y = 0;
	x = DIV_ROUND_UP(10, y);

And looks like this gives the warning too:

	int x;
	const int y = 0;
	if (y)
		x = DIV_ROUND_UP(10, y);

So, I think, the code in the driver could fail to compile at some later point, if the compiler warnings are improved (?), or if someone adds a 'const' in front of 'long freq = clk_get_rate(sensor->clk);' line.

Maybe worry about that if it actually happens =).

Tomi

maintainer
#3 lore raw
Quoted 67 lines · Tomi Valkeinen
Quoted 30 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

               drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")
---
  drivers/media/i2c/mt9m114.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +0 -0
index 0a22f328981d..68adaecaf481 100644

drivers/media/i2c/mt9m114.c static int mt9m114_power_on(struct mt9m114 *sensor) · line 2122

Quoted 8 lines
drivers/media/i2c/mt9m114.c +1 -1
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
  		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
  		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
  		gpiod_set_value(sensor->reset, 0);
  	} else {
  		/*

I think this is fine, so:

But: If we don't have COMMON_CLK (or rather, I think, HAVE_CLK), the freq will be zero at compile time. So won't the compiler give a warning for the DIV_ROUND_UP() call?

Interestingly, for me, this doesn't give a div-by-zero warning:

	int x;
	int y = 0;
	x = DIV_ROUND_UP(10, y);

but this does:

	int x;
	const int y = 0;
	x = DIV_ROUND_UP(10, y);

And looks like this gives the warning too:

	int x;
	const int y = 0;
	if (y)
		x = DIV_ROUND_UP(10, y);
Quoted 5 lines

So, I think, the code in the driver could fail to compile at some later point, if the compiler warnings are improved (?), or if someone adds a 'const' in front of 'long freq = clk_get_rate(sensor->clk);' line.

Maybe worry about that if it actually happens =).

Maybe :-) I would be tempted to make VIDEO_CAMERA_SENSOR depend on COMMON_CLK.

Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw
Quoted 68 lines · Laurent Pinchart
Quoted 67 lines · Tomi Valkeinen
Quoted 30 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

                drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")
---
   drivers/media/i2c/mt9m114.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +0 -0
index 0a22f328981d..68adaecaf481 100644

drivers/media/i2c/mt9m114.c static int mt9m114_power_on(struct mt9m114 *sensor) · line 2122

Quoted 8 lines
drivers/media/i2c/mt9m114.c +1 -1
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
   		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
   		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
   		gpiod_set_value(sensor->reset, 0);
   	} else {
   		/*

I think this is fine, so:

But: If we don't have COMMON_CLK (or rather, I think, HAVE_CLK), the freq will be zero at compile time. So won't the compiler give a warning for the DIV_ROUND_UP() call?

Interestingly, for me, this doesn't give a div-by-zero warning:

	int x;
	int y = 0;
	x = DIV_ROUND_UP(10, y);

but this does:

	int x;
	const int y = 0;
	x = DIV_ROUND_UP(10, y);

And looks like this gives the warning too:

	int x;
	const int y = 0;
	if (y)
		x = DIV_ROUND_UP(10, y);
Quoted 8 lines
Quoted 5 lines

So, I think, the code in the driver could fail to compile at some later point, if the compiler warnings are improved (?), or if someone adds a 'const' in front of 'long freq = clk_get_rate(sensor->clk);' line.

Maybe worry about that if it actually happens =).

Maybe :-) I would be tempted to make VIDEO_CAMERA_SENSOR depend on COMMON_CLK.

I think HAVE_CLK would be more correct.

Tomi

maintainer
#5 lore raw
Quoted 73 lines · Tomi Valkeinen
Quoted 72 lines · Laurent Pinchart
Quoted 71 lines · Tomi Valkeinen
Quoted 30 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

With clang-16, building without COMMON_CLK triggers a range check on udelay() because of a constant division-by-zero calculation:

ld.lld: error: undefined symbol: __bad_udelay

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

referenced by mt9m114.c

                drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a

In this configuration, the driver already fails to probe, before this function gets called, so it's enough to suppress the assertion.

Do this by using fsleep(), which turns long delays into sleep() calls in place of the link failure.

This is probably a good idea regardless to avoid overly long dynamic udelay() calls on a slow clock.

Cc Sakari Ailus <[email protected]>
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")
---
   drivers/media/i2c/mt9m114.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/mt9m114.c +0 -0
index 0a22f328981d..68adaecaf481 100644

drivers/media/i2c/mt9m114.c static int mt9m114_power_on(struct mt9m114 *sensor) · line 2122

Quoted 8 lines
drivers/media/i2c/mt9m114.c +1 -1
@@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor)
   		duration = DIV_ROUND_UP(2 * 50 * 1000000, freq);
 
   		gpiod_set_value(sensor->reset, 1);
-		udelay(duration);
+		fsleep(duration);
   		gpiod_set_value(sensor->reset, 0);
   	} else {
   		/*

I think this is fine, so:

But: If we don't have COMMON_CLK (or rather, I think, HAVE_CLK), the freq will be zero at compile time. So won't the compiler give a warning for the DIV_ROUND_UP() call?

Interestingly, for me, this doesn't give a div-by-zero warning:

	int x;
	int y = 0;
	x = DIV_ROUND_UP(10, y);

but this does:

	int x;
	const int y = 0;
	x = DIV_ROUND_UP(10, y);

And looks like this gives the warning too:

	int x;
	const int y = 0;
	if (y)
		x = DIV_ROUND_UP(10, y);

So, I think, the code in the driver could fail to compile at some later point, if the compiler warnings are improved (?), or if someone adds a 'const' in front of 'long freq = clk_get_rate(sensor->clk);' line.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Maybe worry about that if it actually happens =).

Maybe :-) I would be tempted to make VIDEO_CAMERA_SENSOR depend on COMMON_CLK.

I think HAVE_CLK would be more correct.

Indeed. Only arch/m68k (for Coldfire), arch/mips (for BCM63xx and Lantiq) and arch/sh (for pre-DT platforms) still make use of HAVE_LEGACY_CLK. It takes a long time to address the last users of a legacy API, but it seems we could get there one day.

Signature · 3 lines
Regards,

Laurent Pinchart