media: hi556: Fix memory leak (on error) in hi556_check_hwcfg()
PATCH 1/4 media: hi556: Fix memory leak (on error) in hi556_check_hwcfg()
Commit 7d968b5badfc ("media: hi556: Return -EPROBE_DEFER if no endpoint is found") moved the v4l2_fwnode_endpoint_alloc_parse() call in hi556_check_hwcfg() up, but it did not make the error-exit paths between the old and new call-site use "goto check_hwcfg_error;" to free the bus_cfg on errors.
Add the missing "goto check_hwcfg_error;" statements to fix a memleak on early error-exits from hi556_check_hwcfg().
--- drivers/media/i2c/hi556.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/hi556.c +3 -2
@@ -1230,12 +1230,13 @@ static int hi556_check_hwcfg(struct device *dev) ret =fwnode_property_read_u32 (fwnode,"clock-frequency" , &mclk);if (ret) {dev_err (dev,"can't get clock frequency" ); -return ret; + goto check_hwcfg_error; }if (mclk !=HI556_MCLK ) {dev_err (dev,"external clock %d is not supported" , mclk); -return -EINVAL ; + ret = -EINVAL ; + goto check_hwcfg_error; }if (bus_cfg.bus.mipi_csi2.num_data_lanes !=2 ) {
Signature · 1 line
2.47.1
PATCH 2/4 media: hi556: Add missing '\n' to hi556 error messages
Many hi556 dev_err() error messages miss a terminating '\n', add the missing '\n' to these.
--- drivers/media/i2c/hi556.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/media/i2c/hi556.c +16 -16
@@ -719,7 +719,7 @@ static int hi556_write_reg_list(struct hi556 *hi556, r_list->regs[i].val);if (ret) {dev_err_ratelimited (&client->dev, -"failed to write reg 0x%4.4x. error = %d" , +"failed to write reg 0x%4.4x. error = %d\n" , r_list->regs[i].address, ret);return ret; }
@@ -926,7 +926,7 @@ static int hi556_identify_module(struct hi556 *hi556)return ret;if (val !=HI556_CHIP_ID ) { -dev_err (&client->dev,"chip id mismatch: %x!=%x" , +dev_err (&client->dev,"chip id mismatch: %x!=%x\n" ,HI556_CHIP_ID , val);return -ENXIO ; }
@@ -1002,14 +1002,14 @@ static int hi556_start_streaming(struct hi556 *hi556) reg_list = &link_freq_configs[link_freq_index].reg_list; ret =hi556_write_reg_list (hi556, reg_list);if (ret) { -dev_err (&client->dev,"failed to set plls" ); +dev_err (&client->dev,"failed to set plls\n" );return ret; } reg_list = &hi556->cur_mode->reg_list; ret =hi556_write_reg_list (hi556, reg_list);if (ret) { -dev_err (&client->dev,"failed to set mode" ); +dev_err (&client->dev,"failed to set mode\n" );return ret; }
@@ -1021,7 +1021,7 @@ static int hi556_start_streaming(struct hi556 *hi556) HI556_REG_VALUE_16BIT, HI556_MODE_STREAMING);if (ret) { -dev_err (&client->dev,"failed to set stream" ); +dev_err (&client->dev,"failed to set stream\n" );return ret; }
@@ -1034,7 +1034,7 @@ static void hi556_stop_streaming(struct hi556 *hi556)if (hi556_write_reg (hi556,HI556_REG_MODE_SELECT ,HI556_REG_VALUE_16BIT ,HI556_MODE_STANDBY )) -dev_err (&client->dev,"failed to set stream" ); +dev_err (&client->dev,"failed to set stream\n" ); }static int hi556_set_stream (struct v4l2_subdev *sd,int enable)
@@ -1229,25 +1229,25 @@ static int hi556_check_hwcfg(struct device *dev) ret =fwnode_property_read_u32 (fwnode,"clock-frequency" , &mclk);if (ret) { -dev_err (dev,"can't get clock frequency" ); +dev_err (dev,"can't get clock frequency\n" ); goto check_hwcfg_error; }if (mclk !=HI556_MCLK ) { -dev_err (dev,"external clock %d is not supported" , mclk); +dev_err (dev,"external clock %d is not supported\n" , mclk); ret = -EINVAL ; goto check_hwcfg_error; }if (bus_cfg.bus.mipi_csi2.num_data_lanes !=2 ) { -dev_err (dev,"number of CSI2 data lanes %d is not supported" , +dev_err (dev,"number of CSI2 data lanes %d is not supported\n" , bus_cfg.bus.mipi_csi2.num_data_lanes); ret = -EINVAL ; goto check_hwcfg_error; }if (!bus_cfg.nr_of_link_frequencies) { -dev_err (dev,"no link frequencies defined" ); +dev_err (dev,"no link frequencies defined\n" ); ret = -EINVAL ; goto check_hwcfg_error; }
@@ -1260,7 +1260,7 @@ static int hi556_check_hwcfg(struct device *dev) }if (j == bus_cfg.nr_of_link_frequencies) { -dev_err (dev,"no link frequency %lld supported" , +dev_err (dev,"no link frequency %lld supported\n" , link_freq_menu_items[i]); ret = -EINVAL ; goto check_hwcfg_error;
@@ -1334,7 +1334,7 @@ static int hi556_probe(struct i2c_client *client) ret =hi556_check_hwcfg (&client->dev);if (ret) { -dev_err (&client->dev,"failed to check HW configuration: %d" , +dev_err (&client->dev,"failed to check HW configuration: %d\n" , ret);return ret; }
@@ -1372,7 +1372,7 @@ static int hi556_probe(struct i2c_client *client) ret =hi556_identify_module (hi556);if (ret) { -dev_err (&client->dev,"failed to find sensor: %d" , ret); +dev_err (&client->dev,"failed to find sensor: %d\n" , ret); goto probe_error_power_off; } }
@@ -1381,7 +1381,7 @@ static int hi556_probe(struct i2c_client *client) hi556->cur_mode = &supported_modes[0 ]; ret =hi556_init_controls (hi556);if (ret) { -dev_err (&client->dev,"failed to init controls: %d" , ret); +dev_err (&client->dev,"failed to init controls: %d\n" , ret); goto probe_error_v4l2_ctrl_handler_free; }
@@ -1392,13 +1392,13 @@ static int hi556_probe(struct i2c_client *client) hi556->pad.flags =MEDIA_PAD_FL_SOURCE ; ret =media_entity_pads_init (&hi556->sd.entity,1 , &hi556->pad);if (ret) { -dev_err (&client->dev,"failed to init entity pads: %d" , ret); +dev_err (&client->dev,"failed to init entity pads: %d\n" , ret); goto probe_error_v4l2_ctrl_handler_free; } ret =v4l2_async_register_subdev_sensor (&hi556->sd);if (ret <0 ) { -dev_err (&client->dev,"failed to register V4L2 subdev: %d" , +dev_err (&client->dev,"failed to register V4L2 subdev: %d\n" , ret); goto probe_error_media_entity_cleanup; }
Signature · 1 line
2.47.1
PATCH 3/4 media: hi556: Improve error logging when fwnode is not found
In reply to Hans de GoedeThe hi556 driver waits for the endpoint fwnode to show up in case this fwnode is created by a bridge-driver.
It does this by returning -EPROBE_DEFER, but it does not use dev_err_probe() so no reason for deferring gets registered.
After 30 seconds the kernel logs a warning that the probe is still deferred, which looks like this:
[ 33.952052] i2c i2c-INT3537:00: deferred probe pending: (reason unknown)
Use dev_err_probe() when returning -EPROBE_DEFER to register the probe deferral reason changing the error to:
deferred probe pending: waiting for fwnode graph endpoint
--- drivers/media/i2c/hi556.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/hi556.c +2 -1
@@ -1220,7 +1220,8 @@ static int hi556_check_hwcfg(struct device *dev)*/ ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep) -return -EPROBE_DEFER ; +return dev_err_probe (dev, -EPROBE_DEFER , +"waiting for fwnode graph endpoint\n" ); ret =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);fwnode_handle_put (ep);
Signature · 1 line
2.47.1
PATCH 4/4 media: hi556: Don't log hi556_check_hwcfg() errors twice
In reply to Hans de GoedeAll hi556_check_hwcfg() error-exit paths already log a detailed reason, logging a second generic "failed to check HW configuration" error is not useful, and in case of the fwnode check failing with -EPROBE_DEFER this is outright problematic flooding the log with:
[ 6.336318] hi556 i2c-INT3537:00: failed to check HW configuration: -517 [ 6.339006] hi556 i2c-INT3537:00: failed to check HW configuration: -517 [ 6.346293] hi556 i2c-INT3537:00: failed to check HW configuration: -517 [ 6.356129] hi556 i2c-INT3537:00: failed to check HW configuration: -517 [ 6.380316] hi556 i2c-INT3537:00: failed to check HW configuration: -517
etc.
The one exception to all hi556_check_hwcfg() error-exit paths already logging an error is on v4l2_fwnode_endpoint_alloc_parse() errors.
Make hi556_check_hwcfg() log an error in that case too and drop the duplicate "failed to check HW configuration" error logging.
--- drivers/media/i2c/hi556.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/i2c/hi556.c +2 -5
@@ -1226,7 +1226,7 @@ static int hi556_check_hwcfg(struct device *dev) ret =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);fwnode_handle_put (ep);if (ret) -return ret; +return dev_err_probe (dev, ret,"parsing endpoint failed\n" ); ret =fwnode_property_read_u32 (fwnode,"clock-frequency" , &mclk);if (ret) {
@@ -1334,11 +1334,8 @@ static int hi556_probe(struct i2c_client *client)int ret; ret =hi556_check_hwcfg (&client->dev); -if (ret) { -dev_err (&client->dev,"failed to check HW configuration: %d\n" , - ret); +if (ret)return ret; - } hi556 =devm_kzalloc (&client->dev,sizeof (*hi556),GFP_KERNEL );if (!hi556)
Signature · 1 line
2.47.1