Skip to contentSkip to conversation

media: fix smatch warnings

PATCH In review Hans Verkuil 8 participants 27 messages Oct 6, 2023 – Oct 13, 2023

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

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
#1 lore raw

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
index c438accb0472..58cddf11c9ab 100644
@@ -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
Reviewed-by on v1 1/9
#2 lore raw

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:446 gc0310_s_stream() warn: missing error code 'ret'

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
index c438accb0472..58cddf11c9ab 100644
@@ -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;
 }
#3 lore raw

PATCH 2/9 media: i2c: adp1653: don't reuse the same node pointer

In reply to Hans Verkuil

The 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
index 98ca417b8004..5ace7b5804d4 100644
@@ -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
maintainer Acked-by on v1 2/9
#4 lore raw

Re: [PATCH 2/9] media: i2c: adp1653: don't reuse the same node pointer

Quoted 11 lines · Hans Verkuil

The 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.

Thanks!

Signature · 1 line
Sakari Ailus
#5 lore raw

PATCH 3/9 staging: media: atomisp: improve unwinding

In reply to Hans Verkuil

This 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
index a54be2d20c58..759233a7ba50 100644
@@ -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
Reviewed-by on v1 3/9
#6 lore raw

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: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 +8 -4
index a54be2d20c58..759233a7ba50 100644
@@ -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 -2
 				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],

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

#7 lore raw

PATCH 4/9 media: dvb-usb-v2: af9035: fix missing unlock

In reply to 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:467 af9035_i2c_master_xfer() warn: inconsistent returns '&d->i2c_mutex'.
Locked on : 326,387
Unlocked on: 465,467

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
index 33a2aa8907e6..4eb7dd4599b7 100644
@@ -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
#8 lore raw

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:467 af9035_i2c_master_xfer() warn: inconsistent returns '&d->i2c_mutex'.
Locked on : 326,387
Unlocked on: 465,467

Fixes 7bf744f2de0a ("media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer")

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
index 33a2aa8907e6..4eb7dd4599b7 100644
@@ -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)
#9 lore raw

PATCH 5/9 media: nxp: imx-jpeg: use goto instead of return

In reply to Hans Verkuil

For 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?

CC Mirela Rabulea <[email protected]>
CC NXP Linux Team <[email protected]>
---
 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
index e74b0ed8ec5b..1fc6b3660bdd 100644
@@ -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
#10 lore raw

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'

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 +1 -1
index 48c9084bb4db..a1b127caa90a 100644
@@ -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
Reviewed-by on v1 6/9
#11 lore raw

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:873 vcodec_domains_get() warn: passing zero to 'PTR_ERR'

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
index 48c9084bb4db..a1b127caa90a 100644

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;
  	}
 
#12 lore raw

PATCH 7/9 media: i2c: tc358746: check fmt validity

In reply to Hans Verkuil

Check 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
index 566f5eaddd57..ce612a47ba84 100644
@@ -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
maintainer Reviewed-by on v1 7/9
#13 lore raw

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: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 +0 -0
index 566f5eaddd57..ce612a47ba84 100644

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
#14 lore raw

PATCH 8/9 media: i2c: mt9m114: goto proper error path

In reply to 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:2381 mt9m114_probe() warn: missing unwind goto?

CC Laurent Pinchart <[email protected]>
---
 drivers/media/i2c/mt9m114.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m114.c +2 -2
index dae675e52390..ac19078ceda3 100644
@@ -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
maintainer
#15 lore raw

Re: [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:2381 mt9m114_probe() warn: missing unwind goto?

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
index dae675e52390..ac19078ceda3 100644
@@ -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
#16 lore raw

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:2381 mt9m114_probe() warn: missing unwind goto?

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
index dae675e52390..ac19078ceda3 100644
@@ -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);
maintainer
#17 lore raw

Re: [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:2381 mt9m114_probe() warn: missing unwind goto?

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
index dae675e52390..ac19078ceda3 100644
@@ -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
maintainer
#18 lore raw

Re: [PATCH 8/9] media: i2c: mt9m114: goto proper error path

In reply to Hans Verkuil

Hi 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:2381 mt9m114_probe() warn: missing unwind goto?

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
#19 lore raw

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:2381 mt9m114_probe() warn: missing unwind goto?

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

maintainer
#20 lore raw

Re: [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:2381 mt9m114_probe() warn: missing unwind goto?

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
#21 lore raw

PATCH 9/9 media: pci: mgb4: fix potential spectre vulnerability

In reply to Hans Verkuil

Fix 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
index 23a9aabf3915..9f6e81c57726 100644
@@ -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
#22 lore raw

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: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 +1 -0
index 23a9aabf3915..9f6e81c57726 100644
@@ -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 -1
  	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);

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.

#23 lore raw

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: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 +1 -0
index 23a9aabf3915..9f6e81c57726 100644
@@ -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_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.

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.

#24 lore raw

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: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 +1 -0
index 23a9aabf3915..9f6e81c57726 100644
@@ -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_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.

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

#25 lore raw

Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability

In reply to Pawan Gupta
Quoted 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: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 +1 -0
index 23a9aabf3915..9f6e81c57726 100644
@@ -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_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.

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.

Reviewed-by on v1 9/9
#26 lore raw

Re: [PATCH 9/9] media: pci: mgb4: fix potential spectre vulnerability

In reply to Hans Verkuil
Quoted 25 lines · Hans Verkuil

Fix 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 +1 -0
index 23a9aabf3915..9f6e81c57726 100644
@@ -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 -1
  	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);