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

media: staging: atomisp: use ARRAY_SIZE

Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless to use a variable to store this constant calculated at
compile time.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
(sizeof(E)@p /sizeof(*E))
|
(sizeof(E)@p /sizeof(E[...]))
|
(sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Jérémy Lefaure and committed by
Mauro Carvalho Chehab
bc64ce98 79bd3daa

+3 -6
+3 -6
drivers/staging/media/atomisp/pci/atomisp2/css2400/camera/pipe/src/pipe_binarydesc.c
··· 22 22 #include <assert_support.h> 23 23 /* HRT_GDC_N */ 24 24 #include "gdc_device.h" 25 + #include <linux/kernel.h> 25 26 26 27 /* This module provides a binary descriptions to used to find a binary. Since, 27 28 * every stage is associated with a binary, it implicity helps stage ··· 148 147 unsigned int *bds_factor_denominator) 149 148 { 150 149 unsigned int i; 151 - unsigned int bds_list_size = sizeof(bds_factors_list) / 152 - sizeof(struct sh_css_bds_factor); 153 150 154 151 /* Loop over all bds factors until a match is found */ 155 - for (i = 0; i < bds_list_size; i++) { 152 + for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) { 156 153 if (bds_factors_list[i].bds_factor == bds_factor) { 157 154 *bds_factor_numerator = bds_factors_list[i].numerator; 158 155 *bds_factor_denominator = bds_factors_list[i].denominator; ··· 169 170 unsigned int *bds_factor) 170 171 { 171 172 unsigned int i; 172 - unsigned int bds_list_size = sizeof(bds_factors_list) / 173 - sizeof(struct sh_css_bds_factor); 174 173 unsigned int in_w = input_res.width, 175 174 in_h = input_res.height, 176 175 out_w = output_res.width, out_h = output_res.height; ··· 183 186 assert(out_w != 0 && out_h != 0); 184 187 185 188 /* Loop over all bds factors until a match is found */ 186 - for (i = 0; i < bds_list_size; i++) { 189 + for (i = 0; i < ARRAY_SIZE(bds_factors_list); i++) { 187 190 unsigned num = bds_factors_list[i].numerator; 188 191 unsigned den = bds_factors_list[i].denominator; 189 192