Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: qcom: camss: Fix overflows in clock rate calculations

Because of u32 type being used to store pixel clock rate, expression used
to calculate pipeline clocks (pixel_clock * bpp) produces wrong value due
to integer overflow. This patch changes data type used to store, pass and
retrieve pixel_clock from u32 to u64 to make this mistake less likely to
be repeated in the future.

Signed-off-by: Vladimir Lypak <junak.pub@gmail.com>
Acked-by: Robert Foss <robert.foss@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Vladimir Lypak and committed by
Mauro Carvalho Chehab
2f908577 78c2cc28

+4 -4
+2 -2
drivers/media/platform/qcom/camss/camss-vfe.c
··· 1112 1112 static int vfe_set_clock_rates(struct vfe_device *vfe) 1113 1113 { 1114 1114 struct device *dev = vfe->camss->dev; 1115 - u32 pixel_clock[MSM_VFE_LINE_NUM]; 1115 + u64 pixel_clock[MSM_VFE_LINE_NUM]; 1116 1116 int i, j; 1117 1117 int ret; 1118 1118 ··· 1194 1194 */ 1195 1195 static int vfe_check_clock_rates(struct vfe_device *vfe) 1196 1196 { 1197 - u32 pixel_clock[MSM_VFE_LINE_NUM]; 1197 + u64 pixel_clock[MSM_VFE_LINE_NUM]; 1198 1198 int i, j; 1199 1199 int ret; 1200 1200
+1 -1
drivers/media/platform/qcom/camss/camss.c
··· 578 578 * 579 579 * Return 0 on success or a negative error code otherwise 580 580 */ 581 - int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock) 581 + int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock) 582 582 { 583 583 struct media_entity *sensor; 584 584 struct v4l2_subdev *subdev;
+1 -1
drivers/media/platform/qcom/camss/camss.h
··· 110 110 struct media_entity *camss_find_sensor(struct media_entity *entity); 111 111 s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp, 112 112 unsigned int lanes); 113 - int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock); 113 + int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock); 114 114 int camss_pm_domain_on(struct camss *camss, int id); 115 115 void camss_pm_domain_off(struct camss *camss, int id); 116 116 void camss_delete(struct camss *camss);