media: i2c: mt9m114: add CONFIG_COMMON_CLK dependency
PATCH 1/1 media: i2c: mt9m114: add CONFIG_COMMON_CLK dependency
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.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a
Avoid this by adding a Kconfig dependency that avoids the broken build.
--- drivers/media/i2c/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/media/i2c/Kconfig +1 -0
@@ -228,6 +228,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" + depends on COMMON_CLK select V4L2_CCI_I2C help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114
Signature · 1 line
2.39.2
Sakari Ailus
maintainerHi Arnd,
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With clang-16, building without
COMMON_CLKtriggers a range check onudelay()because of a constant division-by-zero calculation:ld.lld: error: undefined symbol:
__bad_udelayQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
mt9m114.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.aAvoid this by adding a
Kconfigdependency that avoids the broken build.
This sounds like an odd way to fix an issue with udelay(). On which arch does it happen? Wouldn't it be better to fix the udelay() problem in the source?
A quick check reveals there are about 2400 files using udelay.
Quoted 19 lines
Fixes 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/media/i2c/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/Kconfig +1
-0@@ -228,6 +228,7 @@ config VIDEO_MT9M111 config VIDEO_MT9M114 tristate "onsemi MT9M114 sensor support" + depends on COMMON_CLK select V4L2_CCI_I2C help This is a Video4Linux2 sensor-level driver for the onsemi MT9M114
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerQuoted 12 lines · Sakari Ailus
Hi Arnd,
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With clang-16, building without
COMMON_CLKtriggers a range check onudelay()because of a constant division-by-zero calculation:ld.lld: error: undefined symbol:
__bad_udelayQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
mt9m114.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a
Quoted 7 lines
Quoted 1 line
Avoid this by adding a
Kconfigdependency that avoids the broken build.This sounds like an odd way to fix an issue with
udelay(). On which arch does it happen? Wouldn't it be better to fix theudelay()problem in the source?A quick check reveals there are about 2400 files using udelay.
After discussing with Tomi, I think the driver could be improved, too, by adding checks for clock frequency and avoiding an obvious potential division by zero if clk_get_rate() happens to return 0. Switching to fsleep() would probably address the Clang 16 issue, but that doesn't seem to be the primary cause here anyway.
Signature · 1 line
Sakari Ailus
Quoted 10 lines · Sakari Ailus
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With clang-16, building without
COMMON_CLKtriggers a range check onudelay()because of a constant division-by-zero calculation:ld.lld: error: undefined symbol:
__bad_udelayQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
mt9m114.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a
Quoted 7 lines
Quoted 1 line
Avoid this by adding a
Kconfigdependency that avoids the broken build.This sounds like an odd way to fix an issue with
udelay(). On which arch does it happen? Wouldn't it be better to fix theudelay()problem in the source?A quick check reveals there are about 2400 files using udelay.
I observed this on arm, but same sanity check exists on arc, m68k, microblaze, nios2 and xtensa, all of which try to discourage overly large constant delays busy loops. On Arm that limit is any delay of over 2 miliseconds, at which time a driver should generally use either msleep() to avoid a busy-loop, or (in extreme cases) mdelay().
I first tried to rewrite the mt9m114_power_on() function to have an upper bound on the udelay, but that didn't avoid the link error because it still got into undefined C. Disabling the driver without COMMON_CLK seemed easier since it already fails to probe if mt9m114_clk_init() runs into a zero clk.
Maybe we could just fall back to the soft reset when the clock rate is unknown?
drivers/media/i2c/mt9m114.c +4 -2
@@ -2092,6 +2092,7 @@ static void mt9m114_ifp_cleanup(struct mt9m114 *sensor)static int mt9m114_power_on (struct mt9m114 *sensor) { +long freq;int ret;/* Enable power and clocks. */
@@ -2104,9 +2105,10 @@ static int mt9m114_power_on(struct mt9m114 *sensor)if (ret <0 ) goto error_regulator; + freq =clk_get_rate (sensor->clk); +/* Perform a hard reset if available, or a soft reset otherwise. */ -if (sensor->reset) { -long freq =clk_get_rate (sensor->clk); +if (sensor->reset && freq) {unsigned int duration;/*
Arnd
Sakari Ailus
maintainerHi Arnd,
Quoted 26 lines · Arnd Bergmann
Quoted 10 lines · Sakari Ailus
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With clang-16, building without
COMMON_CLKtriggers a range check onudelay()because of a constant division-by-zero calculation:ld.lld: error: undefined symbol:
__bad_udelayQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
mt9m114.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.aQuoted 7 lines
Quoted 1 line
Avoid this by adding a
Kconfigdependency that avoids the broken build.This sounds like an odd way to fix an issue with
udelay(). On which arch does it happen? Wouldn't it be better to fix theudelay()problem in the source?A quick check reveals there are about 2400 files using udelay.
I observed this on arm, but same sanity check exists on arc, m68k, microblaze, nios2 and xtensa, all of which try to discourage overly large constant delays busy loops. On Arm that limit is any delay of over 2 miliseconds, at which time a driver should generally use either
msleep()to avoid a busy-loop, or (in extreme cases)mdelay().
Quoted 8 lines
I first tried to rewrite the
mt9m114_power_on()function to have an upper bound on the udelay, but that didn't avoid the link error because it still got into undefined C. Disabling the driver withoutCOMMON_CLKseemed easier since it already fails to probe ifmt9m114_clk_init()runs into a zero clk.Maybe we could just fall back to the soft reset when the clock rate is unknown?
The datasheet says the input clock range is between 6 MHz and 54 MHz. We could check that, and return an error if it's not in the range. The rate is needed for other reasons, too, and the sensor is unlikely to work if it's (more than little) off.
I wonder if this could address the Clang 16 issue, too? I'd replace udelay() with fsleep() in any case, and at the very least Clang should be happy with this.
Quoted 28 lines
drivers/media/i2c/mt9m114.c +4
-2@@ -2092,6 +2092,7 @@ static void mt9m114_ifp_cleanup(struct mt9m114 *sensor)static int mt9m114_power_on (struct mt9m114 *sensor) { +long freq;int ret;/* Enable power and clocks. */ @@ -2104,9 +2105,10 @@ static int mt9m114_power_on(struct mt9m114 *sensor)if (ret <0 ) goto error_regulator; + freq =clk_get_rate (sensor->clk); +/* Perform a hard reset if available, or a soft reset otherwise. */ -if (sensor->reset) { -long freq =clk_get_rate (sensor->clk); +if (sensor->reset && freq) {unsigned int duration;/* Arnd
Signature · 3 lines
Regards, Sakari Ailus
Laurent Pinchart
maintainerQuoted 38 lines · Sakari Ailus
Hi Arnd,
Quoted 26 lines · Arnd Bergmann
Quoted 10 lines · Sakari Ailus
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
With clang-16, building without
COMMON_CLKtriggers a range check onudelay()because of a constant division-by-zero calculation:ld.lld: error: undefined symbol:
__bad_udelayQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by
mt9m114.cdrivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.aQuoted 7 lines
Quoted 1 line
Avoid this by adding a
Kconfigdependency that avoids the broken build.This sounds like an odd way to fix an issue with
udelay(). On which arch does it happen? Wouldn't it be better to fix theudelay()problem in the source?A quick check reveals there are about 2400 files using udelay.
I observed this on arm, but same sanity check exists on arc, m68k, microblaze, nios2 and xtensa, all of which try to discourage overly large constant delays busy loops. On Arm that limit is any delay of over 2 miliseconds, at which time a driver should generally use either
msleep()to avoid a busy-loop, or (in extreme cases)mdelay().Quoted 8 lines
I first tried to rewrite the
mt9m114_power_on()function to have an upper bound on the udelay, but that didn't avoid the link error because it still got into undefined C. Disabling the driver withoutCOMMON_CLKseemed easier since it already fails to probe ifmt9m114_clk_init()runs into a zero clk.Maybe we could just fall back to the soft reset when the clock rate is unknown?
Quoted 8 lines
The datasheet says the input clock range is between 6 MHz and 54 MHz. We could check that, and return an error if it's not in the range. The rate is needed for other reasons, too, and the sensor is unlikely to work if it's (more than little) off.
I wonder if this could address the Clang 16 issue, too? I'd replace
udelay()withfsleep()in any case, and at the very least Clang should be happy with this.
I'm fine with both of those changes.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/mt9m114.c +4
-2@@ -2092,6 +2092,7 @@ static void mt9m114_ifp_cleanup(struct mt9m114 *sensor)static int mt9m114_power_on (struct mt9m114 *sensor) { +long freq;int ret;/* Enable power and clocks. */ @@ -2104,9 +2105,10 @@ static int mt9m114_power_on(struct mt9m114 *sensor)if (ret <0 ) goto error_regulator; + freq =clk_get_rate (sensor->clk); +/* Perform a hard reset if available, or a soft reset otherwise. */ -if (sensor->reset) { -long freq =clk_get_rate (sensor->clk); +if (sensor->reset && freq) {unsigned int duration;/*
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 9 lines · Laurent Pinchart
Quoted 8 lines · Sakari Ailus
Quoted 1 line · Arnd Bergmann
On Wed, Dec 13, 2023, at 09:09, Sakari Ailus wrote:
The datasheet says the input clock range is between 6 MHz and 54 MHz. We could check that, and return an error if it's not in the range. The rate is needed for other reasons, too, and the sensor is unlikely to work if it's (more than little) off.
Quoted 5 lines
Quoted 3 lines
I wonder if this could address the Clang 16 issue, too? I'd replace
udelay()withfsleep()in any case, and at the very least Clang should be happy with this.I'm fine with both of those changes.
I verified that the build failure is solved by either one. I would just do the fsleep() change in that case since that is a sensible change regardless of the undefined behavior.
I'll send a v2.
Arnd