* [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
@ 2023-03-07 13:51 bchihi
2023-03-08 15:55 ` Balsam CHIHI
0 siblings, 1 reply; 5+ messages in thread
From: bchihi @ 2023-03-07 13:51 UTC (permalink / raw)
To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
ye.xingchen, p.zabel
Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen, error27
From: Balsam CHIHI <bchihi@baylibre.com>
Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data.
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
---
Rebased on top of thermal/linux-next
base-commit: 6828e402d06f7c574430b61c05db784cd847b19f
Original email :
Hello Balsam CHIHI,
The patch f5f633b18234: "thermal/drivers/mediatek: Add the Low
Voltage Thermal Sensor driver" from Feb 9, 2023, leads to the
following Smatch static checker warning:
drivers/thermal/mediatek/lvts_thermal.c:562 lvts_calibration_init()
warn: not copying enough bytes for '&lvts_ctrl->calibration[i]' (4 vs 2 bytes)
drivers/thermal/mediatek/lvts_thermal.c
555 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
556 const struct lvts_ctrl_data *lvts_ctrl_data,
557 u8 *efuse_calibration)
558 {
559 int i;
560
561 for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
--> 562 memcpy(&lvts_ctrl->calibration[i],
563 efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
^
This is copying an array of known ints to a u32 array. It should copy
sizeof(int) instead of 2. It only works because the data you're on
little endian and the data is small.
564
565 return 0;
566 }
regards,
dan carpenter
---
---
drivers/thermal/mediatek/lvts_thermal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index ddfdcbcf6d86..b505c6b49031 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -575,7 +575,7 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
memcpy(&lvts_ctrl->calibration[i],
- efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
+ efuse_calibration + lvts_ctrl_data->cal_offset[i], sizeof(int));
return 0;
}
base-commit: 6828e402d06f7c574430b61c05db784cd847b19f
prerequisite-patch-id: 73be949bd16979769e5b94905b244dcee4a8f687
prerequisite-patch-id: d23d83a946e5b876ef01a717fd51b07df1fa08dd
prerequisite-patch-id: d67f2455eef1c4a9ecc460dbf3c2e3ad47d213ec
prerequisite-patch-id: 9076e9b3bd3cc411b7b80344211364db5f0cca17
prerequisite-patch-id: e220d6ae26786f524c249588433f02e5f5f906ad
prerequisite-patch-id: b407d2998e57678952128b3a4bac92a379132b09
prerequisite-patch-id: fbb9212ce8c3530da17d213f56fa334ce4fa1b2b
prerequisite-patch-id: 5db9eed2659028cf4419f2de3d093af7df6c2dad
prerequisite-patch-id: a83c00c628605d1c8fbe1d97074f9f28efb1bcfc
prerequisite-patch-id: 56a245620a4f8238cf1ba3844dc348de3db33845
prerequisite-patch-id: 7df24b0bf11129ddd3356eacf192cc3fdb2bcded
prerequisite-patch-id: 3213ca70cb5b26d54a7137ff40ca8cd2a795c414
prerequisite-patch-id: 6c2202e85215d1c7e8ab16a6b85922e994c68d9b
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
2023-03-07 13:51 [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
@ 2023-03-08 15:55 ` Balsam CHIHI
0 siblings, 0 replies; 5+ messages in thread
From: Balsam CHIHI @ 2023-03-08 15:55 UTC (permalink / raw)
To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
ye.xingchen, p.zabel
Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen, error27
Hi Angelo,
Could we please discuss it here in this thread?
Because the other one
"https://patchwork.kernel.org/project/linux-pm/patch/20230307134245.83599-1-bchihi@baylibre.com/"
does not contain the address of "Dan Carpenter" who reported the bug
and suggested the fix.
It was sent by mistake. sorry.
Best regards,
Balsam
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v12 2/6] dt-bindings: thermal: mediatek: Add LVTS thermal controllers dt-binding definition
@ 2023-01-26 16:10 bchihi
2023-03-07 13:42 ` [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
0 siblings, 1 reply; 5+ messages in thread
From: bchihi @ 2023-01-26 16:10 UTC (permalink / raw)
To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
ye.xingchen, p.zabel
Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen
From: Balsam CHIHI <bchihi@baylibre.com>
Add LVTS thermal controllers dt-binding definition for mt8195.
Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
---
Changelog:
v12:
- Fixed subject prefix
- Fixed licences GPL-2.0+ to GPL-2.0
- Added dual licenses
v11:
- Rebase on top of "thermal/linux-next" :
base=0d568e144ead70189e7f16066dcb155b78ff9266
- Remove unsupported SoC (mt8192) from dt-binding definition
v10:
- Rebase on top of "thermal/linux-next" : thermal-v6.3-rc1
v9:
- Rebase on top of 6.0.0-rc1
- Update dt-bindings :
- Add "allOf:if:then:"
- Use mt8192 as example (instead of mt8195)
- Fix dt-binding errors
- Fix DTS errors
v8:
- Fix coding style issues
- Rebase on top of next-20220803
- Add multi-instance support :
- Rewrite DT-binding and DTS :
- Add DT-binding and DTS for LVTS_v4 (MT8192 and MT8195)
- One LVTS node for each HW Domain (AP and MCU)
- One SW Instance for each HW Domain
v7:
- Fix coding style issues
- Rewrite dt bindings
- was not accurate
- Use mt8195 for example (instead of mt8192)
- Rename mt6873 to mt8192
- Remove clock name
---
---
.../thermal/mediatek,lvts-thermal.yaml | 107 ++++++++++++++++++
include/dt-bindings/thermal/mediatek-lvts.h | 19 ++++
2 files changed, 126 insertions(+)
create mode 100644 Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
create mode 100644 include/dt-bindings/thermal/mediatek-lvts.h
diff --git a/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
new file mode 100644
index 000000000000..12bfbdd8ff89
--- /dev/null
+++ b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
@@ -0,0 +1,107 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/thermal/mediatek,lvts-thermal.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek SoC Low Voltage Thermal Sensor (LVTS)
+
+maintainers:
+ - Balsam CHIHI <bchihi@baylibre.com>
+
+description: |
+ LVTS is a thermal management architecture composed of three subsystems,
+ a Sensing device - Thermal Sensing Micro Circuit Unit (TSMCU),
+ a Converter - Low Voltage Thermal Sensor converter (LVTS), and
+ a Digital controller (LVTS_CTRL).
+
+properties:
+ compatible:
+ enum:
+ - mediatek,mt8195-lvts-ap
+ - mediatek,mt8195-lvts-mcu
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+
+ resets:
+ maxItems: 1
+ description: LVTS reset for clearing temporary data on AP/MCU.
+
+ nvmem-cells:
+ minItems: 1
+ items:
+ - description: Calibration eFuse data 1 for LVTS
+ - description: Calibration eFuse data 2 for LVTS
+
+ nvmem-cell-names:
+ minItems: 1
+ items:
+ - const: lvts-calib-data-1
+ - const: lvts-calib-data-2
+
+ "#thermal-sensor-cells":
+ const: 1
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - clocks
+ - resets
+ - nvmem-cells
+ - nvmem-cell-names
+ - "#thermal-sensor-cells"
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+ #include <dt-bindings/clock/mt8195-clk.h>
+ #include <dt-bindings/reset/mt8195-resets.h>
+ #include <dt-bindings/thermal/mediatek-lvts.h>
+
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ lvts_mcu: thermal-sensor@11278000 {
+ compatible = "mediatek,mt8195-lvts-mcu";
+ reg = <0 0x11278000 0 0x1000>;
+ interrupts = <GIC_SPI 170 IRQ_TYPE_LEVEL_HIGH 0>;
+ clocks = <&infracfg_ao CLK_INFRA_AO_THERM>;
+ resets = <&infracfg_ao MT8195_INFRA_RST4_THERM_CTRL_MCU_SWRST>;
+ nvmem-cells = <&lvts_efuse_data1 &lvts_efuse_data2>;
+ nvmem-cell-names = "lvts-calib-data-1", "lvts-calib-data-2";
+ #thermal-sensor-cells = <1>;
+ };
+ };
+
+ thermal_zones: thermal-zones {
+ cpu0-thermal {
+ polling-delay = <1000>;
+ polling-delay-passive = <250>;
+ thermal-sensors = <&lvts_mcu MT8195_MCU_LITTLE_CPU0>;
+
+ trips {
+ cpu0_alert: trip-alert {
+ temperature = <85000>;
+ hysteresis = <2000>;
+ type = "passive";
+ };
+
+ cpu0_crit: trip-crit {
+ temperature = <100000>;
+ hysteresis = <2000>;
+ type = "critical";
+ };
+ };
+ };
+ };
diff --git a/include/dt-bindings/thermal/mediatek-lvts.h b/include/dt-bindings/thermal/mediatek-lvts.h
new file mode 100644
index 000000000000..902d5b1e4f43
--- /dev/null
+++ b/include/dt-bindings/thermal/mediatek-lvts.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: (GPL-2.0 or MIT) */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ * Author: Balsam CHIHI <bchihi@baylibre.com>
+ */
+
+#ifndef __MEDIATEK_LVTS_DT_H
+#define __MEDIATEK_LVTS_DT_H
+
+#define MT8195_MCU_BIG_CPU0 0
+#define MT8195_MCU_BIG_CPU1 1
+#define MT8195_MCU_BIG_CPU2 2
+#define MT8195_MCU_BIG_CPU3 3
+#define MT8195_MCU_LITTLE_CPU0 4
+#define MT8195_MCU_LITTLE_CPU1 5
+#define MT8195_MCU_LITTLE_CPU2 6
+#define MT8195_MCU_LITTLE_CPU3 7
+
+#endif /* __MEDIATEK_LVTS_DT_H */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
2023-01-26 16:10 [PATCH v12 2/6] dt-bindings: thermal: mediatek: Add LVTS thermal controllers dt-binding definition bchihi
@ 2023-03-07 13:42 ` bchihi
2023-03-08 9:10 ` AngeloGioacchino Del Regno
0 siblings, 1 reply; 5+ messages in thread
From: bchihi @ 2023-03-07 13:42 UTC (permalink / raw)
To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
ye.xingchen, p.zabel
Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen
From: Balsam CHIHI <bchihi@baylibre.com>
Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data.
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
---
Rebased on top of thermal/linux-next
base-commit: 6828e402d06f7c574430b61c05db784cd847b19f
Original email :
Hello Balsam CHIHI,
The patch f5f633b18234: "thermal/drivers/mediatek: Add the Low
Voltage Thermal Sensor driver" from Feb 9, 2023, leads to the
following Smatch static checker warning:
drivers/thermal/mediatek/lvts_thermal.c:562 lvts_calibration_init()
warn: not copying enough bytes for '&lvts_ctrl->calibration[i]' (4 vs 2 bytes)
drivers/thermal/mediatek/lvts_thermal.c
555 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
556 const struct lvts_ctrl_data *lvts_ctrl_data,
557 u8 *efuse_calibration)
558 {
559 int i;
560
561 for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
--> 562 memcpy(&lvts_ctrl->calibration[i],
563 efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
^
This is copying an array of known ints to a u32 array. It should copy
sizeof(int) instead of 2. It only works because the data you're on
little endian and the data is small.
564
565 return 0;
566 }
regards,
dan carpenter
---
---
drivers/thermal/mediatek/lvts_thermal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index ddfdcbcf6d86..b505c6b49031 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -575,7 +575,7 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
memcpy(&lvts_ctrl->calibration[i],
- efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
+ efuse_calibration + lvts_ctrl_data->cal_offset[i], sizeof(int));
return 0;
}
base-commit: 6828e402d06f7c574430b61c05db784cd847b19f
prerequisite-patch-id: 73be949bd16979769e5b94905b244dcee4a8f687
prerequisite-patch-id: d23d83a946e5b876ef01a717fd51b07df1fa08dd
prerequisite-patch-id: d67f2455eef1c4a9ecc460dbf3c2e3ad47d213ec
prerequisite-patch-id: 9076e9b3bd3cc411b7b80344211364db5f0cca17
prerequisite-patch-id: e220d6ae26786f524c249588433f02e5f5f906ad
prerequisite-patch-id: b407d2998e57678952128b3a4bac92a379132b09
prerequisite-patch-id: fbb9212ce8c3530da17d213f56fa334ce4fa1b2b
prerequisite-patch-id: 5db9eed2659028cf4419f2de3d093af7df6c2dad
prerequisite-patch-id: a83c00c628605d1c8fbe1d97074f9f28efb1bcfc
prerequisite-patch-id: 56a245620a4f8238cf1ba3844dc348de3db33845
prerequisite-patch-id: 7df24b0bf11129ddd3356eacf192cc3fdb2bcded
prerequisite-patch-id: 3213ca70cb5b26d54a7137ff40ca8cd2a795c414
prerequisite-patch-id: 6c2202e85215d1c7e8ab16a6b85922e994c68d9b
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
2023-03-07 13:42 ` [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
@ 2023-03-08 9:10 ` AngeloGioacchino Del Regno
2023-03-09 12:37 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-03-08 9:10 UTC (permalink / raw)
To: bchihi, daniel.lezcano, rafael, amitk, rui.zhang, matthias.bgg,
robh+dt, krzysztof.kozlowski+dt, rdunlap, ye.xingchen, p.zabel
Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen
Il 07/03/23 14:42, bchihi@baylibre.com ha scritto:
> From: Balsam CHIHI <bchihi@baylibre.com>
>
> Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data.
sizeof(int) is architecture dependant... please use a fixed size type instead.
Also, shouldn't this be u16?!
Regards,
Angelo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
2023-03-08 9:10 ` AngeloGioacchino Del Regno
@ 2023-03-09 12:37 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-03-09 12:37 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: bchihi, daniel.lezcano, rafael, amitk, rui.zhang, matthias.bgg,
robh+dt, krzysztof.kozlowski+dt, rdunlap, ye.xingchen, p.zabel,
linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
devicetree, khilman, james.lo, rex-bc.chen
On Wed, Mar 08, 2023 at 10:10:34AM +0100, AngeloGioacchino Del Regno wrote:
> Il 07/03/23 14:42, bchihi@baylibre.com ha scritto:
> > From: Balsam CHIHI <bchihi@baylibre.com>
> >
> > Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data.
>
> sizeof(int) is architecture dependant...
>
On Linux sizeof(int) is always 4.
I'm just so confused what you are talking about. Are you thinking about
sizeof(long)? Are you thinking about CPUs from the 1970s? Linux wasn't
invented until the 90s so the old CPUs were already in museums at that
point.
> please use a fixed size type instead.
This is an unusual style opinion that I have not heard before.
Hopefully, you just got ints and longs confused so we can move on
without discussing it too much. We're copying an int so sizeof(int) is
obviously correct. It's hard to know how to respond.
> Also, shouldn't this be u16?!
What? Why would you think that?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-09 12:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-07 13:51 [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
2023-03-08 15:55 ` Balsam CHIHI
-- strict thread matches above, loose matches on Subject: below --
2023-01-26 16:10 [PATCH v12 2/6] dt-bindings: thermal: mediatek: Add LVTS thermal controllers dt-binding definition bchihi
2023-03-07 13:42 ` [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
2023-03-08 9:10 ` AngeloGioacchino Del Regno
2023-03-09 12:37 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox