media: Fix last smatch warnings
Subsystems (7)
v2 cover media: Fix last smatch warnings
This series completes the smatch warning cleanout.
---
Changes in v2:
- Fix double free in ar0251 patch. Thanks Dan!
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ricardo Ribalda (6):
media: ar0521: Refactor ar0521_power_off()
media: i2c: ov5645: Refactor ov5645_set_power_off()
media: i2c: s5c73m3: Move clk_prepare to its own function
media: tc358746: Move clk_prepare to its own function
media: meson: vdec_1: Refactor vdec_1_stop()
media: meson: vdec: hevc: Refactor vdec_hevc_start and vdec_hevc_stop
drivers/media/i2c/ar0521.c | 17 ++++++++--- drivers/media/i2c/ov5645.c | 15 ++++++++-- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 13 ++++++++- drivers/media/i2c/tc358746.c | 12 +++++++- drivers/staging/media/meson/vdec/vdec_1.c | 16 ++++++++--- drivers/staging/media/meson/vdec/vdec_hevc.c | 43 +++++++++++++++++++++------- 6 files changed, 92 insertions(+), 24 deletions(-)
---
base-commit: c80bfa4f9e0ebfce6ac909488d412347acbcb4f9
change-id: 20240813-smatch-clock-2fa3b1174857
Best regards,
Signature · 1 line
Ricardo Ribalda <[email protected]>
PATCH v2 1/6 media: ar0521: Refactor ar0521_power_off()
Factor out all the power off logic, except the clk_disable_unprepare(), to a new function __ar0521_power_off().
This allows ar0521_power_on() to explicitly clean-out the clock during the error-path.
The following smatch warning is fixed:drivers/media/i2c/ar0521.c:912 ar0521_power_on() warn: 'sensor->extclk' from clk_prepare_enable() not released on lines: 912.
--- drivers/media/i2c/ar0521.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/media/i2c/ar0521.c +13 -4
@@ -835,14 +835,12 @@ static const struct initial_reg { be(0x0707)), /* 3F44: couple k factor 2 */ }; -static int ar0521_power_off (struct device *dev) +static void __ar0521_power_off (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev);struct ar0521_dev *sensor =to_ar0521_dev (sd);int i; -clk_disable_unprepare (sensor->extclk); -if (sensor->reset_gpio)gpiod_set_value (sensor->reset_gpio,1 );/* assert RESET signal */
@@ -850,6 +848,16 @@ static int ar0521_power_off(struct device *dev)if (sensor->supplies[i])regulator_disable (sensor->supplies[i]); } +} + +static int ar0521_power_off (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ar0521_dev *sensor =to_ar0521_dev (sd); + +clk_disable_unprepare (sensor->extclk); +__ar0521_power_off (dev); +return 0 ; }
@@ -908,7 +916,8 @@ static int ar0521_power_on(struct device *dev)return 0 ; off: -ar0521_power_off (dev); +clk_disable_unprepare (sensor->extclk); +__ar0521_power_off (dev);return ret; }
Signature · 1 line
2.46.0.184.g6999bdac58-goog
Re: [PATCH v2 1/6] media: ar0521: Refactor ar0521_power_off()
Hi Ricardo,
Quoted 8 lines · Ricardo Ribalda
Factor out all the power off logic, except the
clk_disable_unprepare(), to a new function__ar0521_power_off().This allows
ar0521_power_on()to explicitly clean-out the clock during the error-path.The following smatch warning is fixed:
drivers/media/i2c/ar0521.c:912ar0521_power_on()warn: 'sensor->extclk' fromclk_prepare_enable()not released on lines: 912.
TBH I don't know if the code with the patch applied is better or not. It if silences the tool, well, sometimes things are not as clear as we want them.
Quoted 52 lines
Signed-off-by Ricardo Ribalda <[email protected]>--- drivers/media/i2c/ar0521.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)drivers/media/i2c/ar0521.c +13
-4@@ -835,14 +835,12 @@ static const struct initial_reg { be(0x0707)), /* 3F44: couple k factor 2 */ }; -static int ar0521_power_off (struct device *dev) +static void __ar0521_power_off (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev);struct ar0521_dev *sensor =to_ar0521_dev (sd);int i; -clk_disable_unprepare (sensor->extclk); -if (sensor->reset_gpio)gpiod_set_value (sensor->reset_gpio,1 );/* assert RESET signal */ @@ -850,6 +848,16 @@ static int ar0521_power_off(struct device *dev)if (sensor->supplies[i])regulator_disable (sensor->supplies[i]); } +} + +static int ar0521_power_off (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ar0521_dev *sensor =to_ar0521_dev (sd); + +clk_disable_unprepare (sensor->extclk); +__ar0521_power_off (dev); +return 0 ; }@@ -908,7 +916,8 @@ static int ar0521_power_on(struct device *dev)return 0 ; off: -ar0521_power_off (dev); +clk_disable_unprepare (sensor->extclk); +__ar0521_power_off (dev);return ret; }
Signature · 5 lines
Krzysztof "Chris" Hałasa Sieć Badawcza Łukasiewicz Przemysłowy Instytut Automatyki i Pomiarów PIAP Al. Jerozolimskie 202, 02-486 Warszawa
PATCH v2 2/6 media: i2c: ov5645: Refactor ov5645_set_power_off()
In reply to Ricardo RibaldaFactor out all the power off logic, except clk_disable_unprepare(), to a new function __ov5645_set_power_off().
This allows ov5645_set_power_on() to excplicitly clean-out the clock during the error-path.
The following smatch warning is fixed:drivers/media/i2c/ov5645.c:690 ov5645_set_power_on() warn: 'ov5645->xclk' from clk_prepare_enable() not released on lines: 690.
--- drivers/media/i2c/ov5645.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5645.c +12 -3
@@ -635,7 +635,7 @@ static int ov5645_set_register_array(struct ov5645 *ov5645,return 0 ; } -static int ov5645_set_power_off (struct device *dev) +static void __ov5645_set_power_off (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev);struct ov5645 *ov5645 =to_ov5645 (sd);
@@ -643,8 +643,16 @@ static int ov5645_set_power_off(struct device *dev)ov5645_write_reg (ov5645,OV5645_IO_MIPI_CTRL00 ,0x58 );gpiod_set_value_cansleep (ov5645->rst_gpio,1 );gpiod_set_value_cansleep (ov5645->enable_gpio,0 ); -clk_disable_unprepare (ov5645->xclk);regulator_bulk_disable (OV5645_NUM_SUPPLIES , ov5645->supplies); +} + +static int ov5645_set_power_off (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ov5645 *ov5645 =to_ov5645 (sd); + +__ov5645_set_power_off (dev); +clk_disable_unprepare (ov5645->xclk);return 0 ; }
@@ -686,7 +694,8 @@ static int ov5645_set_power_on(struct device *dev)return 0 ; exit: -ov5645_set_power_off (dev); +__ov5645_set_power_off (dev); +clk_disable_unprepare (ov5645->xclk);return ret; }
Signature · 1 line
2.46.0.184.g6999bdac58-goog
PATCH v2 3/6 media: i2c: s5c73m3: Move clk_prepare to its own function
In reply to Ricardo RibaldaSmatch is very confused by a clk_prepare_enable() being called in an error-path. Fix this warning by moving the clk_prepare_enable() to its own function.
drivers/media/i2c/s5c73m3/s5c73m3-core.c:1425 __s5c73m3_power_off() warn: 'state->clock' from clk_prepare_enable() not released on lines: 1425.
--- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/media/i2c/s5c73m3/s5c73m3-core.c +12 -1
@@ -1392,6 +1392,16 @@ static int __s5c73m3_power_on(struct s5c73m3 *state)return ret; } +/* +* This function has been created just to avoid a smatch warning, +* please do not merge into __s5c73m3_power_off() until you have +* confirmed that it does not introduce a new warning. +*/ +static void s5c73m3_enable_clk (struct s5c73m3 *state) +{ +clk_prepare_enable (state->clock); +} +static int __s5c73m3_power_off (struct s5c73m3 *state) {int i, ret;
@@ -1421,7 +1431,8 @@ static int __s5c73m3_power_off(struct s5c73m3 *state) state->supplies[i].supply, r); } -clk_prepare_enable (state->clock); +s5c73m3_enable_clk (state); +return ret; }
Signature · 1 line
2.46.0.184.g6999bdac58-goog
PATCH v2 4/6 media: tc358746: Move clk_prepare to its own function
In reply to Ricardo RibaldaSmatch is very confused by a clk_prepare_enable() being called in an error-path. Fix this warning by moving the clk_prepare_enable() to its own function.
drivers/media/i2c/tc358746.c:1631 tc358746_suspend() warn: 'tc358746->refclk' from clk_prepare_enable() not released on lines: 1631.
--- drivers/media/i2c/tc358746.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/media/i2c/tc358746.c +11 -1
@@ -1616,6 +1616,16 @@ static void tc358746_remove(struct i2c_client *client)pm_runtime_dont_use_autosuspend (sd->dev); } +/* +* This function has been created just to avoid a smatch warning, +* please do not merge it into tc358746_suspend until you have +* confirmed that it does not introduce a new warning. +*/ +static void tc358746_clk_enable (struct tc358746 *tc358746) +{ +clk_prepare_enable (tc358746->refclk); +} +static int tc358746_suspend (struct device *dev) {struct tc358746 *tc358746 =dev_get_drvdata (dev);
@@ -1626,7 +1636,7 @@ static int tc358746_suspend(struct device *dev) err =regulator_bulk_disable (ARRAY_SIZE (tc358746_supplies), tc358746->supplies);if (err) -clk_prepare_enable (tc358746->refclk); +tc358746_clk_enable (tc358746);return err; }
Signature · 1 line
2.46.0.184.g6999bdac58-goog
PATCH v2 5/6 media: meson: vdec_1: Refactor vdec_1_stop()
In reply to Ricardo RibaldaFactor out all the power off logic, except the clk_disable_unprepare(), to a new function __vdec_1_stop().
This allows vdec_1_start() to explicitly clean-out the clock during the error-path.
The following smatch warning is fixed:drivers/staging/media/meson/vdec/vdec_1.c:239 vdec_1_start() warn: 'core->vdec_1_clk' from clk_prepare_enable() not released on lines: 239.
--- drivers/staging/media/meson/vdec/vdec_1.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/staging/media/meson/vdec/vdec_1.c +12 -4
@@ -129,7 +129,7 @@ static u32 vdec_1_vififo_level(struct amvdec_session *sess)return amvdec_read_dos (core,VLD_MEM_VIFIFO_LEVEL ); } -static int vdec_1_stop (struct amvdec_session *sess) +static void __vdec_1_stop (struct amvdec_session *sess) {struct amvdec_core *core = sess->core;struct amvdec_codec_ops *codec_ops = sess->fmt_out->codec_ops;
@@ -158,10 +158,17 @@ static int vdec_1_stop(struct amvdec_session *sess)regmap_update_bits (core->regmap_ao,AO_RTI_GEN_PWR_SLEEP0 ,GEN_PWR_VDEC_1 ,GEN_PWR_VDEC_1 ); -clk_disable_unprepare (core->vdec_1_clk); -if (sess->priv) codec_ops->stop (sess); +} + +static int vdec_1_stop (struct amvdec_session *sess) +{ +struct amvdec_core *core = sess->core; + +__vdec_1_stop (sess); + +clk_disable_unprepare (core->vdec_1_clk);return 0 ; }
@@ -235,7 +242,8 @@ static int vdec_1_start(struct amvdec_session *sess)return 0 ; stop: -vdec_1_stop (sess); +__vdec_1_stop (sess); +clk_disable_unprepare (core->vdec_1_clk);return ret; }
Signature · 1 line
2.46.0.184.g6999bdac58-goog
PATCH v2 6/6 media: meson: vdec: hevc: Refactor vdec_hevc_start and vdec_hevc_stop
In reply to Ricardo RibaldaMake a new function __vdec_hevc_start(), that does all the initialization, except the clock initialization for G12A and SM1.
Factor out all the stop logic, except the clk_disable_unprepare(), to a new function __vdec_hevc_stop. This allows vdec_hevc_start() to explicitly celan-out the clock during the error-path.
The following smatch warnings are fixed:
drivers/staging/media/meson/vdec/vdec_hevc.c:227 vdec_hevc_start() warn: 'core->vdec_hevc_clk' from clk_prepare_enable() not released on lines: 227. drivers/staging/media/meson/vdec/vdec_hevc.c:227 vdec_hevc_start() warn: 'core->vdec_hevcf_clk' from clk_prepare_enable() not released on lines: 227.
--- drivers/staging/media/meson/vdec/vdec_hevc.c | 43 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-)
drivers/staging/media/meson/vdec/vdec_hevc.c +32 -11
@@ -110,7 +110,7 @@ static u32 vdec_hevc_vififo_level(struct amvdec_session *sess)return readl_relaxed (sess->core->dos_base +HEVC_STREAM_LEVEL ); } -static int vdec_hevc_stop (struct amvdec_session *sess) +static void __vdec_hevc_stop (struct amvdec_session *sess) {struct amvdec_core *core = sess->core;struct amvdec_codec_ops *codec_ops = sess->fmt_out->codec_ops;
@@ -142,6 +142,13 @@ static int vdec_hevc_stop(struct amvdec_session *sess)else regmap_update_bits (core->regmap_ao,AO_RTI_GEN_PWR_SLEEP0 ,GEN_PWR_VDEC_HEVC ,GEN_PWR_VDEC_HEVC ); +} + +static int vdec_hevc_stop (struct amvdec_session *sess) +{ +struct amvdec_core *core = sess->core; + +__vdec_hevc_stop (sess);clk_disable_unprepare (core->vdec_hevc_clk); if (core->platform->revision == VDEC_REVISION_G12A ||
@@ -151,20 +158,12 @@ static int vdec_hevc_stop(struct amvdec_session *sess)return 0 ; } -static int vdec_hevc_start (struct amvdec_session *sess) +static int __vdec_hevc_start (struct amvdec_session *sess) {int ret;struct amvdec_core *core = sess->core;struct amvdec_codec_ops *codec_ops = sess->fmt_out->codec_ops; -if (core->platform->revision ==VDEC_REVISION_G12A || - core->platform->revision ==VDEC_REVISION_SM1 ) { -clk_set_rate (core->vdec_hevcf_clk,666666666 ); - ret =clk_prepare_enable (core->vdec_hevcf_clk); -if (ret) -return ret; - } -clk_set_rate (core->vdec_hevc_clk,666666666 ); ret =clk_prepare_enable (core->vdec_hevc_clk);if (ret) {
@@ -223,10 +222,32 @@ static int vdec_hevc_start(struct amvdec_session *sess)return 0 ; stop: -vdec_hevc_stop (sess); +__vdec_hevc_stop (sess); +clk_disable_unprepare (core->vdec_hevc_clk);return ret; } +static int vdec_hevc_start (struct amvdec_session *sess) +{ +struct amvdec_core *core = sess->core; +int ret; + +if (core->platform->revision ==VDEC_REVISION_G12A || + core->platform->revision ==VDEC_REVISION_SM1 ) { +clk_set_rate (core->vdec_hevcf_clk,666666666 ); + ret =clk_prepare_enable (core->vdec_hevcf_clk); +if (ret) +return ret; + + ret =__vdec_hevc_start (sess); +if (ret) +clk_disable_unprepare (core->vdec_hevcf_clk); +return ret; + } + +return __vdec_hevc_start (sess); +} +struct amvdec_ops vdec_hevc_ops = { .start = vdec_hevc_start, .stop = vdec_hevc_stop,
Signature · 1 line
2.46.0.184.g6999bdac58-goog