media: fix smatch warnings
Subsystems (14)
cover media: fix smatch warnings
This series fixes various smatch warnings. The build scripts didn't call smatch with the -p=kernel option, so some warnings were disabled. After fixing that new warnings appeared that are fixed in this series.
A few warnings remain for false positives that would be very painful to fix, and those are filtered by the build script so that they don't pollute the output.
Note that the adp1653 patch is a v2 of the first attempt:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
I incorporated Sakari's suggestions in the v2.
Regards,
Hans
Hans Verkuil (9):
staging: media: atomisp: drop check for reentrant .s_stream()
media: i2c: adp1653: don't reuse the same node pointer
staging: media: atomisp: improve unwinding
media: dvb-usb-v2: af9035: fix missing unlock
media: nxp: imx-jpeg: use goto instead of return
media: qcom: venus: fix incorrect return value
media: i2c: tc358746: check fmt validity
media: i2c: mt9m114: goto proper error path
media: pci: mgb4: fix potential spectre vulnerability
drivers/media/i2c/adp1653.c | 28 ++++++++++--------- drivers/media/i2c/mt9m114.c | 4 +-- drivers/media/i2c/tc358746.c | 6 +++- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 +++- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 2 +- .../media/platform/qcom/venus/pm_helpers.c | 2 +- drivers/media/usb/dvb-usb-v2/af9035.c | 13 ++++++--- .../media/atomisp/i2c/atomisp-gc0310.c | 6 ---- .../staging/media/atomisp/pci/atomisp_cmd.c | 18 ++++++++---- 9 files changed, 49 insertions(+), 35 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/9 staging: media: atomisp: drop check for reentrant .s_stream()
The subdev .s_stream() operation shall not be called to start streaming on an already started subdev, or stop streaming on a stopped subdev. Remove the check that guards against that condition.
Also fixes a smatch warning:
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c:446 gc0310_s_stream() warn: missing error code 'ret'
--- drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +0 -6
@@ -441,11 +441,6 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable)dev_dbg (&client->dev,"%s S enable=%d\n" , __func__, enable);mutex_lock (&dev->input_lock); -if (dev->is_streaming == enable) { -dev_warn (&client->dev,"stream already %s\n" , enable ?"started" :"stopped" ); - goto error_unlock; - } -if (enable) { ret =pm_runtime_get_sync (&client->dev);if (ret <0 )
@@ -497,7 +492,6 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) error_power_down:pm_runtime_put (&client->dev); dev->is_streaming = false; -error_unlock:mutex_unlock (&dev->input_lock);return ret; }
Signature · 1 line
2.40.1
Re: [PATCH 1/9] staging: media: atomisp: drop check for reentrant .s_stream()
Hi,
Quoted 10 lines · Hans Verkuil
The subdev .s_stream() operation shall not be called to start streaming on an already started subdev, or stop streaming on a stopped subdev. Remove the check that guards against that condition.
Also fixes a smatch warning:
drivers/staging/media/atomisp/i2c/atomisp-gc0310.c:446gc0310_s_stream()warn: missing error code 'ret'Signed-off-by Hans Verkuil <[email protected]>CC Hans de Goede <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 28 lines
--- drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 6 ------ 1 file changed, 6 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +0
-6@@ -441,11 +441,6 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable)dev_dbg (&client->dev,"%s S enable=%d\n" , __func__, enable);mutex_lock (&dev->input_lock); -if (dev->is_streaming == enable) { -dev_warn (&client->dev,"stream already %s\n" , enable ?"started" :"stopped" ); - goto error_unlock; - } -if (enable) { ret =pm_runtime_get_sync (&client->dev);if (ret <0 )@@ -497,7 +492,6 @@ static int gc0310_s_stream(struct v4l2_subdev *sd, int enable) error_power_down:pm_runtime_put (&client->dev); dev->is_streaming = false; -error_unlock:mutex_unlock (&dev->input_lock);return ret; }
PATCH 2/9 media: i2c: adp1653: don't reuse the same node pointer
In reply to Hans VerkuilThe child device_node pointer was used for two different childs. This confused smatch, causing this warning:
drivers/media/i2c/adp1653.c:444 adp1653_of_init() warn: missing unwind goto?
Use two different pointers, one for each child node, and add separate goto labels for each node as well. This also improves error logging since it will now state for which node the property was missing.
--- drivers/media/i2c/adp1653.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/media/i2c/adp1653.c +15 -13
@@ -411,43 +411,44 @@ static int adp1653_of_init(struct i2c_client *client, struct device_node *node) {struct adp1653_platform_data *pd; -struct device_node *child; +struct device_node *node_indicator =NULL ; +struct device_node *node_flash; pd =devm_kzalloc (&client->dev,sizeof (*pd),GFP_KERNEL );if (!pd)return -ENOMEM ; flash->platform_data = pd; - child =of_get_child_by_name (node,"flash" ); -if (!child) + node_flash =of_get_child_by_name (node,"flash" ); +if (!node_flash)return -EINVAL ; -if (of_property_read_u32 (child,"flash-timeout-us" , +if (of_property_read_u32 (node_flash,"flash-timeout-us" , &pd->max_flash_timeout)) goto err; -if (of_property_read_u32 (child,"flash-max-microamp" , +if (of_property_read_u32 (node_flash,"flash-max-microamp" , &pd->max_flash_intensity)) goto err; pd->max_flash_intensity /=1000 ; -if (of_property_read_u32 (child,"led-max-microamp" , +if (of_property_read_u32 (node_flash,"led-max-microamp" , &pd->max_torch_intensity)) goto err; pd->max_torch_intensity /=1000 ; -of_node_put (child); - child =of_get_child_by_name (node,"indicator" ); -if (!child) -return -EINVAL ; + node_indicator =of_get_child_by_name (node,"indicator" ); +if (!node_indicator) + goto err; -if (of_property_read_u32 (child,"led-max-microamp" , +if (of_property_read_u32 (node_indicator,"led-max-microamp" , &pd->max_indicator_intensity)) goto err; -of_node_put (child); +of_node_put (node_flash); +of_node_put (node_indicator); pd->enable_gpio =devm_gpiod_get (&client->dev,"enable" ,GPIOD_OUT_LOW );if (IS_ERR (pd->enable_gpio)) {
@@ -458,7 +459,8 @@ static int adp1653_of_init(struct i2c_client *client,return 0 ; err:dev_err (&client->dev,"Required property not found\n" ); -of_node_put (child); +of_node_put (node_flash); +of_node_put (node_indicator);return -EINVAL ; }
Signature · 1 line
2.40.1
Re: [PATCH 2/9] media: i2c: adp1653: don't reuse the same node pointer
Quoted 11 lines · Hans Verkuil
The child
device_nodepointer was used for two different childs. This confused smatch, causing this warning:
drivers/media/i2c/adp1653.c:444adp1653_of_init()warn: missing unwind goto?Use two different pointers, one for each child node, and add separate goto labels for each node as well. This also improves error logging since it will now state for which node the property was missing.
Signed-off-by Hans Verkuil <[email protected]>CC Sakari Ailus <[email protected]>
Thanks!
Signature · 1 line
Sakari Ailus
PATCH 3/9 staging: media: atomisp: improve unwinding
In reply to Hans VerkuilThis fixes two smatch warnings:
drivers/staging/media/atomisp/pci/atomisp_cmd.c:2779 atomisp_cp_dvs_6axis_config() warn: missing unwind goto? drivers/staging/media/atomisp/pci/atomisp_cmd.c:2878 atomisp_cp_morph_table() warn: missing unwind goto?
--- .../staging/media/atomisp/pci/atomisp_cmd.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_cmd.c +12 -6
@@ -2771,12 +2771,16 @@ int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd, css_param->dvs_6axis =NULL ; dvs_6axis_config =ia_css_dvs2_6axis_config_allocate (stream); -if (!dvs_6axis_config) -return -ENOMEM ; +if (!dvs_6axis_config) { + ret = -ENOMEM ; + goto error; + } }else if (!dvs_6axis_config) { dvs_6axis_config =ia_css_dvs2_6axis_config_allocate (stream); -if (!dvs_6axis_config) -return -ENOMEM ; +if (!dvs_6axis_config) { + ret = -ENOMEM ; + goto error; + } } dvs_6axis_config->exp_id = source_6axis_config->exp_id;
@@ -2874,8 +2878,10 @@ int atomisp_cp_morph_table(struct atomisp_sub_device *asd, morph_table =atomisp_css_morph_table_allocate ( source_morph_table->width, source_morph_table->height); -if (!morph_table) -return -ENOMEM ; +if (!morph_table) { + ret = -ENOMEM ; + goto error; + }for (i =0 ; i <IA_CSS_MORPH_TABLE_NUM_PLANES ; i++) { if (copy_from_compatible(morph_table->coordinates_x[i],
Signature · 1 line
2.40.1
Re: [PATCH 3/9] staging: media: atomisp: improve unwinding
Hi,
Quoted 39 lines · Hans Verkuil
This fixes two smatch warnings:
drivers/staging/media/atomisp/pci/atomisp_cmd.c:2779atomisp_cp_dvs_6axis_config()warn: missing unwind goto?drivers/staging/media/atomisp/pci/atomisp_cmd.c:2878atomisp_cp_morph_table()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Hans de Goede <[email protected]>--- .../staging/media/atomisp/pci/atomisp_cmd.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)drivers/staging/media/atomisp/pci/atomisp_cmd.c +8
-4@@ -2771,12 +2771,16 @@ int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd, css_param->dvs_6axis =NULL ; dvs_6axis_config =ia_css_dvs2_6axis_config_allocate (stream); -if (!dvs_6axis_config) -return -ENOMEM ; +if (!dvs_6axis_config) { + ret = -ENOMEM ; + goto error; + } }else if (!dvs_6axis_config) { dvs_6axis_config =ia_css_dvs2_6axis_config_allocate (stream); -if (!dvs_6axis_config) -return -ENOMEM ; +if (!dvs_6axis_config) { + ret = -ENOMEM ; + goto error; + } } dvs_6axis_config->exp_id = source_6axis_config->exp_id;@@ -2874,8 +2878,10 @@ int atomisp_cp_morph_table(struct atomisp_sub_device *asd, morph_table = atomisp_css_morph_table_allocate( source_morph_table->width,
drivers/staging/media/atomisp/pci/atomisp_cmd.c int atomisp_cp_morph_table(struct atomisp_sub_device *asd, · line 2887
Quoted 10 lines
drivers/staging/media/atomisp/pci/atomisp_cmd.c +4
-2source_morph_table->height); -if (!morph_table) -return -ENOMEM ; +if (!morph_table) { + ret = -ENOMEM ; + goto error; + }for (i =0 ; i <IA_CSS_MORPH_TABLE_NUM_PLANES ; i++) { if (copy_from_compatible(morph_table->coordinates_x[i],
There are 2 : "morph_table = atomisp_css_morph_table_allocate(...)" statements in this function in both branches of the
if (IS_ISP2401) { ... } else { ... } block, shouldn't both cases get the goto error treatment ?
Otherwise this looks good to me:
Regards,
Hans
PATCH 4/9 media: dvb-usb-v2: af9035: fix missing unlock
In reply to Hans VerkuilInstead of returning an error, goto the mutex unlock at the end of the function.
Fixes smatch warning:
drivers/media/usb/dvb-usb-v2/af9035.c:467 af9035_i2c_master_xfer() warn: inconsistent returns '&d->i2c_mutex'.
Locked on : 326,387
Unlocked on: 465,467
--- drivers/media/usb/dvb-usb-v2/af9035.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/media/usb/dvb-usb-v2/af9035.c +9 -4
@@ -322,8 +322,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { -if (msg[0 ].len <3 || msg[1 ].len <1 ) -return -EOPNOTSUPP ; +if (msg[0 ].len <3 || msg[1 ].len <1 ) { + ret = -EOPNOTSUPP ; + goto unlock; + }/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];
@@ -383,8 +385,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { -if (msg[0 ].len <3 ) -return -EOPNOTSUPP ; +if (msg[0 ].len <3 ) { + ret = -EOPNOTSUPP ; + goto unlock; + }/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];
@@ -459,6 +463,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; } +unlock:mutex_unlock (&d->i2c_mutex);if (ret <0 )
Signature · 1 line
2.40.1
Re: [PATCH 4/9] media: dvb-usb-v2: af9035: fix missing unlock
Quoted 10 lines · Hans Verkuil
Instead of returning an error, goto the mutex unlock at the end of the function.
Fixes smatch warning:
drivers/media/usb/dvb-usb-v2/af9035.c:467af9035_i2c_master_xfer()warn: inconsistent returns '&d->i2c_mutex'.
Locked on : 326,387
Unlocked on: 465,467Signed-off-by Hans Verkuil <[email protected]>
Regards,
Hans
Quoted 43 lines
CC Mauro Carvalho Chehab <[email protected]>--- drivers/media/usb/dvb-usb-v2/af9035.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/media/usb/dvb-usb-v2/af9035.c +9
-4@@ -322,8 +322,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { -if (msg[0 ].len <3 || msg[1 ].len <1 ) -return -EOPNOTSUPP ; +if (msg[0 ].len <3 || msg[1 ].len <1 ) { + ret = -EOPNOTSUPP ; + goto unlock; + }/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];@@ -383,8 +385,10 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { -if (msg[0 ].len <3 ) -return -EOPNOTSUPP ; +if (msg[0 ].len <3 ) { + ret = -EOPNOTSUPP ; + goto unlock; + }/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];@@ -459,6 +463,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; } +unlock:mutex_unlock (&d->i2c_mutex);if (ret <0 )
PATCH 5/9 media: nxp: imx-jpeg: use goto instead of return
In reply to Hans VerkuilFor consistency use goto instead of return.
This fixes a smatch warning:
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:2792 mxc_jpeg_probe() warn: missing unwind goto?
--- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +1 -1
@@ -2789,7 +2789,7 @@ static int mxc_jpeg_probe(struct platform_device *pdev) ret =mxc_jpeg_attach_pm_domains (jpeg);if (ret <0 ) {dev_err (dev,"failed to attach power domains %d\n" , ret); -return ret; + goto err_clk; }/* v4l2 */
Signature · 1 line
2.40.1
PATCH 6/9 media: qcom: venus: fix incorrect return value
In reply to Hans Verkuil'pd' can be NULL, and in that case it shouldn't be passed to PTR_ERR. Fixes a smatch warning:
drivers/media/platform/qcom/venus/pm_helpers.c:873 vcodec_domains_get() warn: passing zero to 'PTR_ERR'
--- drivers/media/platform/qcom/venus/pm_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/qcom/venus/pm_helpers.c +1 -1
@@ -870,7 +870,7 @@ static int vcodec_domains_get(struct venus_core *core) pd =dev_pm_domain_attach_by_name (dev, res->vcodec_pmdomains[i]);if (IS_ERR_OR_NULL (pd)) -return PTR_ERR (pd) ? : -ENODATA ; +return pd ?PTR_ERR (pd) : -ENODATA ; core->pmdomains[i] = pd; }
Signature · 1 line
2.40.1
Re: [PATCH 6/9] media: qcom: venus: fix incorrect return value
Quoted 18 lines · Hans Verkuil
'pd' can be NULL, and in that case it shouldn't be passed to
PTR_ERR. Fixes a smatch warning:
drivers/media/platform/qcom/venus/pm_helpers.c:873vcodec_domains_get()warn: passing zero to 'PTR_ERR'Signed-off-by Hans Verkuil <[email protected]>CC Stanimir Varbanov <[email protected]>CC Vikash Garodia <[email protected]>CC "Bryan O'Donoghue" <[email protected]>--- drivers/media/platform/qcom/venus/pm_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/qcom/venus/pm_helpers.c +0
-0
drivers/media/platform/qcom/venus/pm_helpers.c static int vcodec_domains_get(struct venus_core *core) · line 876
Quoted 8 lines
drivers/media/platform/qcom/venus/pm_helpers.c +1
-1@@ -870,7 +870,7 @@ static int vcodec_domains_get(struct venus_core *core) pd =dev_pm_domain_attach_by_name (dev, res->vcodec_pmdomains[i]);if (IS_ERR_OR_NULL (pd)) -return PTR_ERR (pd) ? : -ENODATA ; +return pd ?PTR_ERR (pd) : -ENODATA ; core->pmdomains[i] = pd; }
PATCH 7/9 media: i2c: tc358746: check fmt validity
In reply to Hans VerkuilCheck if the format was really found.
Fixes smatch warning:
drivers/media/i2c/tc358746.c:790 tc358746_set_fmt() error: 'fmt' dereferencing possible ERR_PTR()
--- drivers/media/i2c/tc358746.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/i2c/tc358746.c +5 -1
@@ -784,8 +784,12 @@ static int tc358746_set_fmt(struct v4l2_subdev *sd, sink_fmt =v4l2_subdev_get_pad_format (sd, sd_state,TC358746_SINK ); fmt =tc358746_get_format_by_code (format->pad, format->format.code); -if (IS_ERR (fmt)) +if (IS_ERR (fmt)) { fmt =tc358746_get_format_by_code (format->pad, tc358746_def_fmt.code); +// Can't happen, but just in case... +if (WARN_ON (IS_ERR (fmt))) +return -EINVAL ; + } format->format.code = fmt->code; format->format.field =V4L2_FIELD_NONE ;
Signature · 1 line
2.40.1
Re: [PATCH 7/9] media: i2c: tc358746: check fmt validity
Hi Hans,
Quoted 17 lines · Hans Verkuil
Check if the format was really found.
Fixes smatch warning:
drivers/media/i2c/tc358746.c:790tc358746_set_fmt()error: 'fmt' dereferencing possibleERR_PTR()Signed-off-by Hans Verkuil <[email protected]>CC Sakari Ailus <[email protected]>--- drivers/media/i2c/tc358746.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/media/i2c/tc358746.c +0
-0
drivers/media/i2c/tc358746.c static int tc358746_set_fmt(struct v4l2_subdev *sd, · line 789
Quoted 7 lines
drivers/media/i2c/tc358746.c +2
-1@@ -784,8 +784,12 @@ static int tc358746_set_fmt(struct v4l2_subdev *sd, sink_fmt =v4l2_subdev_get_pad_format (sd, sd_state,TC358746_SINK ); fmt =tc358746_get_format_by_code (format->pad, format->format.code); -if (IS_ERR (fmt)) +if (IS_ERR (fmt)) { fmt =tc358746_get_format_by_code (format->pad, tc358746_def_fmt.code); +// Can't happen, but just in case...
/* ... */
Quoted 9 lines
drivers/media/i2c/tc358746.c +3
-0+if (WARN_ON (IS_ERR (fmt))) +return -EINVAL ; + } format->format.code = fmt->code; format->format.field =V4L2_FIELD_NONE ;Signature · 1 line
2.40.1
Signature · 1 line
Sakari Ailus
PATCH 8/9 media: i2c: mt9m114: goto proper error path
In reply to Hans VerkuilIn two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381 mt9m114_probe() warn: missing unwind goto?
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m114.c +2 -2
@@ -2367,7 +2367,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_clk_init (sensor);if (ret) -return ret; + goto error_ep_free;/* * Identify the sensor. The driver supports runtime PM, but needs to
@@ -2378,7 +2378,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_power_on (sensor);if (ret <0 ) {dev_err_probe (dev, ret,"Could not power on the device\n" ); -return ret; + goto error_ep_free; } ret =mt9m114_identify (sensor);
Signature · 1 line
2.40.1
Laurent Pinchart
maintainerRe: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
Hi Hans,
Thank you for the patch.
Quoted 9 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>
I've already submitted
https://lore.kernel.org/linux-media/[email protected]
Quoted 26 lines
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/i2c/mt9m114.c +2
-2@@ -2367,7 +2367,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_clk_init (sensor);if (ret) -return ret; + goto error_ep_free;/* * Identify the sensor. The driver supports runtime PM, but needs to @@ -2378,7 +2378,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_power_on (sensor);if (ret <0 ) {dev_err_probe (dev, ret,"Could not power on the device\n" ); -return ret; + goto error_ep_free; } ret =mt9m114_identify (sensor);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
Hi Laurent,
Quoted 10 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 5 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
Quoted 7 lines
Quoted 4 lines
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>I've already submitted
https://lore.kernel.org/linux-media/[email protected]
Is it OK if I pick up your patch for this issue? I plan to pick up at least part of this series tomorrow in order to cut down on the number of reported smatch warnings.
Regards,
Hans
Quoted 28 lines
Quoted 27 lines
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/i2c/mt9m114.c +2
-2@@ -2367,7 +2367,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_clk_init (sensor);if (ret) -return ret; + goto error_ep_free;/* * Identify the sensor. The driver supports runtime PM, but needs to @@ -2378,7 +2378,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_power_on (sensor);if (ret <0 ) {dev_err_probe (dev, ret,"Could not power on the device\n" ); -return ret; + goto error_ep_free; } ret =mt9m114_identify (sensor);
Laurent Pinchart
maintainerRe: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
Hi Hans,
Quoted 12 lines · Hans Verkuil
Quoted 11 lines · Laurent Pinchart
Quoted 9 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>
Quoted 6 lines
Quoted 2 lines
I've already submitted
https://lore.kernel.org/linux-media/[email protected]Is it OK if I pick up your patch for this issue? I plan to pick up at least part of this series tomorrow in order to cut down on the number of reported smatch warnings.
Fine with me. Please update the Fixes: line, as the commit ID has changed due to the recent rebase. And this is a good occasion to test your scripts and make sure they catch this :-)
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
--- drivers/media/i2c/mt9m114.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/i2c/mt9m114.c +2
-2@@ -2367,7 +2367,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_clk_init (sensor);if (ret) -return ret; + goto error_ep_free;/* * Identify the sensor. The driver supports runtime PM, but needs to @@ -2378,7 +2378,7 @@ static int mt9m114_probe(struct i2c_client *client) ret =mt9m114_power_on (sensor);if (ret <0 ) {dev_err_probe (dev, ret,"Could not power on the device\n" ); -return ret; + goto error_ep_free; } ret =mt9m114_identify (sensor);
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
In reply to Hans VerkuilHi Hans,
Quoted 18 lines · Hans Verkuil
Hi Laurent,
Quoted 15 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 9 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>
Quoted 6 lines
Quoted 2 lines
I've already submitted
https://lore.kernel.org/linux-media/[email protected]Is it OK if I pick up your patch for this issue? I plan to pick up at least part of this series tomorrow in order to cut down on the number of reported smatch warnings.
I've got it in my tree and I intend to send a PR by tomorrow (there's an issue also in the CCS driver).
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
Quoted 24 lines · Sakari Ailus
Hi Hans,
Quoted 21 lines · Hans Verkuil
Hi Laurent,
Quoted 17 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 9 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>I've already submitted
https://lore.kernel.org/linux-media/[email protected]
Quoted 7 lines
Quoted 3 lines
Is it OK if I pick up your patch for this issue? I plan to pick up at least part of this series tomorrow in order to cut down on the number of reported smatch warnings.
I've got it in my tree and I intend to send a PR by tomorrow (there's an issue also in the CCS driver).
OK, then I leave this to you, Sakari.
The two patches you reviewed (2/9 and 7/9), can I commit those or do you plan to make those part of your PR? I don't care either way, as long as we don't duplicate work...
Regards,
Hans
Sakari Ailus
maintainerRe: [PATCH 8/9] media: i2c: mt9m114: goto proper error path
Hi Hans,
Quoted 33 lines · Hans Verkuil
Quoted 24 lines · Sakari Ailus
Hi Hans,
Quoted 21 lines · Hans Verkuil
Hi Laurent,
Quoted 17 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 9 lines · Hans Verkuil
In two places the probe function returns instead of going to the correct goto label.
This fixes this smatch warning:
drivers/media/i2c/mt9m114.c:2381mt9m114_probe()warn: missing unwind goto?Signed-off-by Hans Verkuil <[email protected]>CC Laurent Pinchart <[email protected]>I've already submitted
https://lore.kernel.org/linux-media/[email protected]Quoted 7 lines
Quoted 3 lines
Is it OK if I pick up your patch for this issue? I plan to pick up at least part of this series tomorrow in order to cut down on the number of reported smatch warnings.
I've got it in my tree and I intend to send a PR by tomorrow (there's an issue also in the CCS driver).
Quoted 5 lines
OK, then I leave this to you, Sakari.
The two patches you reviewed (2/9 and 7/9), can I commit those or do you plan to make those part of your PR? I don't care either way, as long as we don't duplicate work...
You already have them as part of your set so please take them.
I think I've already reviewed them, too.
Signature · 3 lines
Regards, Sakari Ailus
PATCH 9/9 media: pci: mgb4: fix potential spectre vulnerability
In reply to Hans VerkuilFix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118 video_source_store() warn: potential spectre issue 'mgbdev->vin' [r] (local cap) drivers/media/pci/mgb4/mgb4_sysfs_out.c:122 video_source_store() warn: possible spectre second half. 'loopin_new'
--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/pci/mgb4/mgb4_sysfs_out.c +4 -1
@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h"
@@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );
Signature · 1 line
2.40.1
Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability
Quoted 25 lines · Hans Verkuil
Fix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118video_source_store()warn: potential spectre issue 'mgbdev->vin' [r] (local cap)drivers/media/pci/mgb4/mgb4_sysfs_out.c:122video_source_store()warn: possible spectre second half. 'loopin_new'Signed-off-by Hans Verkuil <[email protected]>CC Martin Tuma <[email protected]>--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/pci/mgb4/mgb4_sysfs_out.c +1
-0@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h" @@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,
drivers/media/pci/mgb4/mgb4_sysfs_out.c static ssize_t video_source_store(struct device *dev, · line 124
Quoted 10 lines
drivers/media/pci/mgb4/mgb4_sysfs_out.c +3
-1if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );
Hi,
I had investigated the warning when it appeared here on the mailing list, but IMHO it is a false-positive, so I didn't react to it. MGB4_VIN_DEVICES in the condition is not a check for array bounds but a check whether the input source (val) is one of the inputs. Valid "val" values are <0,3> and only if the value is <0,1> it is used as an array index for the input devices (vin) array. So this is IMHO a different situation than desribed in the speculation document (https://www.kernel.org/doc/html/latest/staging/speculation.html). But I may be wrong and array_index_nospec() is still required here.
If the goal was just to silence smatch, than I'm ok with that, It shouldn't harm any performance here. Except that it will look like there is a possible spectre issue in the code where it in fact isn't, it should not change anything.
M.
Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability
Quoted 35 lines · Martin Tůma
Quoted 23 lines · Hans Verkuil
Fix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118video_source_store()warn: potential spectre issue 'mgbdev->vin' [r] (local cap)drivers/media/pci/mgb4/mgb4_sysfs_out.c:122video_source_store()warn: possible spectre second half. 'loopin_new'Signed-off-by Hans Verkuil <[email protected]>CC Martin Tuma <[email protected]>--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/pci/mgb4/mgb4_sysfs_out.c +1
-0@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h" drivers/media/pci/mgb4/mgb4_sysfs_out.c static ssize_t video_source_store(struct device *dev, · line 123
Quoted 10 lines
drivers/media/pci/mgb4/mgb4_sysfs_out.c +3
-1@@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );
Quoted 7 lines
Hi,
I had investigated the warning when it appeared here on the mailing list, but IMHO it is a false-positive, so I didn't react to it.MGB4_VIN_DEVICESin the condition is not a check for array bounds but a check whether the input source (val) is one of the inputs. Valid "val" values are <0,3> and only if the value is <0,1> it is used as an array index for the input devices (vin) array.
I think when there are 2 branch mispredicts this is a valid problem. Below both branches can be trained with a val < 2. Then for a val > 3, both branches can mispredict:
video_source_store(buf)
{
...
ret = kstrtoul(buf, 10, &val); if (ret) return ret; if (val > 3) <------------- predicted as not taken return -EINVAL; ... if (val < MGB4_VIN_DEVICES) <------------- predicted as taken
loopin_new = mgbdev->vin[val];
The fix LGTM, although it can also possibly be fixed by masking the index after the first mispredicted branch, like:
ret = kstrtoul(buf, 10, &val); if (ret) return ret;
+ val = array_index_nospec(val, 4);
provided, mgbdev->vin[2] and mgbdev->vin[3] can't load a secret.
Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability
Hi Martin,
Quoted 69 lines · Pawan Gupta
Quoted 34 lines · Martin Tůma
Quoted 22 lines · Hans Verkuil
Fix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118video_source_store()warn: potential spectre issue 'mgbdev->vin' [r] (local cap)drivers/media/pci/mgb4/mgb4_sysfs_out.c:122video_source_store()warn: possible spectre second half. 'loopin_new'>>>Signed-off-by Hans Verkuil <[email protected]>CC Martin Tuma <[email protected]>--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/pci/mgb4/mgb4_sysfs_out.c +1
-0@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h" drivers/media/pci/mgb4/mgb4_sysfs_out.c static ssize_t video_source_store(struct device *dev, · line 123
Quoted 10 lines
drivers/media/pci/mgb4/mgb4_sysfs_out.c +3
-1@@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );Quoted 7 lines
Hi,
I had investigated the warning when it appeared here on the mailing list, but IMHO it is a false-positive, so I didn't react to it.MGB4_VIN_DEVICESin the condition is not a check for array bounds but a check whether the input source (val) is one of the inputs. Valid "val" values are <0,3> and only if the value is <0,1> it is used as an array index for the input devices (vin) array.I think when there are 2 branch mispredicts this is a valid problem. Below both branches can be trained with a val < 2. Then for a val > 3, both branches can mispredict:
video_source_store(buf)
{
...ret = kstrtoul(buf, 10, &val); if (ret) return ret; if (val > 3) <------------- predicted as not taken return -EINVAL; ... if (val < MGB4_VIN_DEVICES) <------------- predicted as taken
loopin_new= mgbdev->vin[val];The fix LGTM, although it can also possibly be fixed by masking the index after the first mispredicted branch, like:
ret = kstrtoul(buf, 10, &val); if (ret) return ret;(quoted diff) +1
-0+ val = array_index_nospec(val, 4);
Quoted 1 line
provided, mgbdev->vin[2] and mgbdev->vin[3] can't load a secret.
Based on that input, and also because I want to shut up that warnings :-), is it OK to merge? Can you proved and Acked-by or Reviewed-by?
Thanks!
Hans
Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability
In reply to Pawan GuptaQuoted 69 lines · Pawan Gupta
Quoted 35 lines · Martin Tůma
Quoted 23 lines · Hans Verkuil
Fix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118video_source_store()warn: potential spectre issue 'mgbdev->vin' [r] (local cap)drivers/media/pci/mgb4/mgb4_sysfs_out.c:122video_source_store()warn: possible spectre second half. 'loopin_new'Signed-off-by Hans Verkuil <[email protected]>CC Martin Tuma <[email protected]>--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/pci/mgb4/mgb4_sysfs_out.c +1
-0@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h" drivers/media/pci/mgb4/mgb4_sysfs_out.c static ssize_t video_source_store(struct device *dev, · line 123
Quoted 10 lines
drivers/media/pci/mgb4/mgb4_sysfs_out.c +3
-1@@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );Quoted 7 lines
Hi,
I had investigated the warning when it appeared here on the mailing list, but IMHO it is a false-positive, so I didn't react to it.MGB4_VIN_DEVICESin the condition is not a check for array bounds but a check whether the input source (val) is one of the inputs. Valid "val" values are <0,3> and only if the value is <0,1> it is used as an array index for the input devices (vin) array.I think when there are 2 branch mispredicts this is a valid problem. Below both branches can be trained with a val < 2. Then for a val > 3, both branches can mispredict:
video_source_store(buf)
{
...ret = kstrtoul(buf, 10, &val); if (ret) return ret; if (val > 3) <------------- predicted as not taken return -EINVAL; ... if (val < MGB4_VIN_DEVICES) <------------- predicted as taken
loopin_new= mgbdev->vin[val];The fix LGTM, although it can also possibly be fixed by masking the index after the first mispredicted branch, like:
ret = kstrtoul(buf, 10, &val); if (ret) return ret;
Review
Quoted 1 line
(quoted diff) +1
-0+ val = array_index_nospec(val, 4);
Ok, thanks for the clarification.
Quoted 1 line
provided, mgbdev->vin[2] and mgbdev->vin[3] can't load a secret.
There is nothing secret there.
M.
Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability
In reply to Hans VerkuilQuoted 25 lines · Hans Verkuil
Fix smatch warnings:
drivers/media/pci/mgb4/mgb4_sysfs_out.c:118video_source_store()warn: potential spectre issue 'mgbdev->vin' [r] (local cap)drivers/media/pci/mgb4/mgb4_sysfs_out.c:122video_source_store()warn: possible spectre second half. 'loopin_new'Signed-off-by Hans Verkuil <[email protected]>CC Martin Tuma <[email protected]>--- drivers/media/pci/mgb4/mgb4_sysfs_out.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/pci/mgb4/mgb4_sysfs_out.c +1
-0@@ -8,6 +8,7 @@*/ #include <linux/device.h> +#include <linux/nospec.h> #include "mgb4_core.h" #include "mgb4_i2c.h" #include "mgb4_vout.h" @@ -114,8 +115,10 @@ static ssize_t video_source_store(struct device *dev,
drivers/media/pci/mgb4/mgb4_sysfs_out.c static ssize_t video_source_store(struct device *dev, · line 124
Quoted 10 lines
drivers/media/pci/mgb4/mgb4_sysfs_out.c +3
-1if (((config &0xc ) >>2 ) <MGB4_VIN_DEVICES ) loopin_old = mgbdev->vin[(config &0xc ) >>2 ]; -if (val <MGB4_VIN_DEVICES ) +if (val <MGB4_VIN_DEVICES ) { + val =array_index_nospec (val,MGB4_VIN_DEVICES ); loopin_new = mgbdev->vin[val]; + }if (loopin_old &&loopin_cnt (loopin_old) ==1 )mgb4_mask_reg (&mgbdev->video, loopin_old->config->regs.config,0x2 ,0x0 );