Re: [PATCH] thermal/drivers/sprd: validate the sensor id from the device tree

From: he geoffrey

Date: Tue Sep 29 2026 - 12:52:20 EST


On 9/29/26 10:46, Daniel Lezcano wrote:
> Why is there a mismatch between this check and above in the code:
>
> thm->nr_sensors = of_get_child_count(np);
> if (thm->nr_sensors == 0 || thm->nr_sensors > SPRD_THM_MAX_SENSOR) {
>
> (note the "thm->nr_sensors > SPRD_THM_MAX_SENSOR" instead of
> "thm->nr_sensors >= SPRD_THM_MAX_SENSOR"

Hi Daniel,

Thanks for the review.

The two checks bound different things. nr_sensors is a count, so eight
sensors is still valid and only a count above SPRD_THM_MAX_SENSOR is
rejected. sen->id is an index into thm->sensor[SPRD_THM_MAX_SENSOR], so
it must be below SPRD_THM_MAX_SENSOR, hence ">=".

Thanks,
Weigang