Skip to contentSkip to conversation

thermal/drivers/tsens: fix usage of unititialized value

PATCH In review Yang Li 2 participants 2 messages Jun 8, 2021 – Jun 11, 2021

Subsystems (3)
lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 thermal/drivers/tsens: fix usage of unititialized value

When "tsens_version(priv) > VER_0_1" is false, "regmap_field_read(priv->rf[VER_MINOR], &ver_minor)" can't execute. So, ver_minor has no initialization and assignment before it is used, and we initialize it to 0.

Clean up smatch warning:
drivers/thermal/qcom/tsens.c:896 init_common() error: uninitialized symbol 'ver_minor'.

---
 drivers/thermal/qcom/tsens.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/qcom/tsens.c +1 -1
index 4c7ebd1..a36c43d 100644
@@ -743,8 +743,8 @@ int __init init_common(struct tsens_priv *priv)
 {
 	void __iomem *tm_base, *srot_base;
 	struct device *dev = priv->dev;
-	u32 ver_minor;
 	struct resource *res;
+	u32 ver_minor = 0;
 	u32 enabled;
 	int ret, i, j;
 	struct platform_device *op = of_find_device_by_node(priv->dev->of_node);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 4 lines · Yang Li

When "tsens_version(priv) > VER_0_1" is false, "regmap_field_read(priv->rf[VER_MINOR], &ver_minor)" can't execute. So, ver_minor has no initialization and assignment before it is used, and we initialize it to 0.

Hi Yang,

Thanks for the patch. I have a few questions though.

1. Where do you see ver_minor being used uninitialized? AFAICT , ver_minor is used like below and will never be referenced if version <= VER_0_1

	if (tsens_version(priv) > VER_1_X &&  ver_minor > 2) {

2. Do you know whether minor versions can be read or not on tsens ips with verions < 0_1?

Signature · 2 lines
Warm Regards
Thara (She/Her/Hers)
Quoted 26 lines

Clean up smatch warning:
drivers/thermal/qcom/tsens.c:896 init_common() error: uninitialized symbol 'ver_minor'.

---
  drivers/thermal/qcom/tsens.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/qcom/tsens.c +1 -1
index 4c7ebd1..a36c43d 100644
@@ -743,8 +743,8 @@ int __init init_common(struct tsens_priv *priv)
  {
  	void __iomem *tm_base, *srot_base;
  	struct device *dev = priv->dev;
-	u32 ver_minor;
  	struct resource *res;
+	u32 ver_minor = 0;
  	u32 enabled;
  	int ret, i, j;
  	struct platform_device *op = of_find_device_by_node(priv->dev->of_node);