Skip to contentSkip to conversation

thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver

bug report Dan Carpenter 2 participants 2 messages Feb 27, 2023 – Mar 2, 2023 Arm MediaTek

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 25 lines · Dan Carpenter

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.

Quoted 6 lines
    564
    565         return 0;
    566 }

regards,
dan carpenter

Hello Dan Carpenter,

Thank you for reporting this bug.
I will create a patch to fix it ASAP.

Best regards,
Balsam