Skip to content

Commit 1ecb7d2

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Improve checks in the info_get operations
SCMI protocols abstract and expose a number of protocol specific resources like clocks, sensors and so on. Information about such specific domain resources are generally exposed via an `info_get` protocol operation. Improve the sanity check on these operations where needed. Link: https://lore.kernel.org/r/20220817172731.1185305-3-cristian.marussi@arm.com Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent 2e42b16 commit 1ecb7d2

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/firmware/arm_scmi/clock.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,13 @@ static int scmi_clock_count_get(const struct scmi_protocol_handle *ph)
450450
static const struct scmi_clock_info *
451451
scmi_clock_info_get(const struct scmi_protocol_handle *ph, u32 clk_id)
452452
{
453+
struct scmi_clock_info *clk;
453454
struct clock_info *ci = ph->get_priv(ph);
454-
struct scmi_clock_info *clk = ci->clk + clk_id;
455455

456+
if (clk_id >= ci->num_clocks)
457+
return NULL;
458+
459+
clk = ci->clk + clk_id;
456460
if (!clk->name[0])
457461
return NULL;
458462

drivers/firmware/arm_scmi/sensors.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ scmi_sensor_info_get(const struct scmi_protocol_handle *ph, u32 sensor_id)
948948
{
949949
struct sensors_info *si = ph->get_priv(ph);
950950

951+
if (sensor_id >= si->num_sensors)
952+
return NULL;
953+
951954
return si->sensors + sensor_id;
952955
}
953956

include/linux/scmi_protocol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct scmi_protocol_handle;
8484
struct scmi_clk_proto_ops {
8585
int (*count_get)(const struct scmi_protocol_handle *ph);
8686

87-
const struct scmi_clock_info *(*info_get)
87+
const struct scmi_clock_info __must_check *(*info_get)
8888
(const struct scmi_protocol_handle *ph, u32 clk_id);
8989
int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
9090
u64 *rate);
@@ -466,7 +466,7 @@ enum scmi_sensor_class {
466466
*/
467467
struct scmi_sensor_proto_ops {
468468
int (*count_get)(const struct scmi_protocol_handle *ph);
469-
const struct scmi_sensor_info *(*info_get)
469+
const struct scmi_sensor_info __must_check *(*info_get)
470470
(const struct scmi_protocol_handle *ph, u32 sensor_id);
471471
int (*trip_point_config)(const struct scmi_protocol_handle *ph,
472472
u32 sensor_id, u8 trip_id, u64 trip_value);

0 commit comments

Comments
 (0)