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

[PATCH] USB: Use ARRAY_SIZE macro

Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove
duplicates of ARRAY_SIZE. Some trailing whitespaces are also removed.

Patch is compile-tested on i386.

Signed-off-by: Tobias Klauser <tklauser@nuerscht.ch>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Tobias Klauser and committed by
Greg Kroah-Hartman
52950ed4 f3d34ed4

+24 -35
+1 -1
drivers/usb/gadget/dummy_hcd.c
··· 138 138 /* or like sa1100: two fixed function endpoints */ 139 139 "ep1out-bulk", "ep2in-bulk", 140 140 }; 141 - #define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *)) 141 + #define DUMMY_ENDPOINTS ARRAY_SIZE(ep_name) 142 142 143 143 /*-------------------------------------------------------------------------*/ 144 144
+2 -2
drivers/usb/input/aiptek.c
··· 2093 2093 /* Programming the tablet macro keys needs to be done with a for loop 2094 2094 * as the keycodes are discontiguous. 2095 2095 */ 2096 - for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i) 2096 + for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i) 2097 2097 set_bit(macroKeyEvents[i], inputdev->keybit); 2098 2098 2099 2099 /* ··· 2135 2135 * not an error :-) 2136 2136 */ 2137 2137 2138 - for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) { 2138 + for (i = 0; i < ARRAY_SIZE(speeds); ++i) { 2139 2139 aiptek->curSetting.programmableDelay = speeds[i]; 2140 2140 (void)aiptek_program_tablet(aiptek); 2141 2141 if (aiptek->inputdev->absmax[ABS_X] > 0) {
+1 -1
drivers/usb/media/ibmcam.c
··· 3457 3457 if(init_model3_input) { 3458 3458 if (debug > 0) 3459 3459 info("Setting input to RCA."); 3460 - for (i=0; i < (sizeof(initData)/sizeof(initData[0])); i++) { 3460 + for (i=0; i < ARRAY_SIZE(initData); i++) { 3461 3461 ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index); 3462 3462 } 3463 3463 }
+10 -13
drivers/usb/media/sn9c102_core.c
··· 1316 1316 struct v4l2_control ctrl; 1317 1317 struct v4l2_queryctrl *qctrl; 1318 1318 struct v4l2_rect* rect; 1319 - u8 i = 0, n = 0; 1319 + u8 i = 0; 1320 1320 int err = 0; 1321 1321 1322 1322 if (!(cam->state & DEV_INITIALIZED)) { ··· 1352 1352 return err; 1353 1353 1354 1354 if (s->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X) 1355 - DBG(3, "Compressed video format is active, quality %d", 1355 + DBG(3, "Compressed video format is active, quality %d", 1356 1356 cam->compression.quality) 1357 1357 else 1358 1358 DBG(3, "Uncompressed video format is active") ··· 1364 1364 } 1365 1365 1366 1366 if (s->set_ctrl) { 1367 - n = sizeof(s->qctrl) / sizeof(s->qctrl[0]); 1368 - for (i = 0; i < n; i++) 1369 - if (s->qctrl[i].id != 0 && 1367 + for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1368 + if (s->qctrl[i].id != 0 && 1370 1369 !(s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)) { 1371 1370 ctrl.id = s->qctrl[i].id; 1372 1371 ctrl.value = qctrl[i].default_value; ··· 1387 1388 init_waitqueue_head(&cam->wait_stream); 1388 1389 cam->nreadbuffers = 2; 1389 1390 memcpy(s->_qctrl, s->qctrl, sizeof(s->qctrl)); 1390 - memcpy(&(s->_rect), &(s->cropcap.defrect), 1391 + memcpy(&(s->_rect), &(s->cropcap.defrect), 1391 1392 sizeof(struct v4l2_rect)); 1392 1393 cam->state |= DEV_INITIALIZED; 1393 1394 } ··· 1809 1810 { 1810 1811 struct sn9c102_sensor* s = cam->sensor; 1811 1812 struct v4l2_queryctrl qc; 1812 - u8 i, n; 1813 + u8 i; 1813 1814 1814 1815 if (copy_from_user(&qc, arg, sizeof(qc))) 1815 1816 return -EFAULT; 1816 1817 1817 - n = sizeof(s->qctrl) / sizeof(s->qctrl[0]); 1818 - for (i = 0; i < n; i++) 1818 + for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1819 1819 if (qc.id && qc.id == s->qctrl[i].id) { 1820 1820 memcpy(&qc, &(s->qctrl[i]), sizeof(qc)); 1821 1821 if (copy_to_user(arg, &qc, sizeof(qc))) ··· 1850 1852 { 1851 1853 struct sn9c102_sensor* s = cam->sensor; 1852 1854 struct v4l2_control ctrl; 1853 - u8 i, n; 1855 + u8 i; 1854 1856 int err = 0; 1855 1857 1856 1858 if (!s->set_ctrl) ··· 1859 1861 if (copy_from_user(&ctrl, arg, sizeof(ctrl))) 1860 1862 return -EFAULT; 1861 1863 1862 - n = sizeof(s->qctrl) / sizeof(s->qctrl[0]); 1863 - for (i = 0; i < n; i++) 1864 + for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) 1864 1865 if (ctrl.id == s->qctrl[i].id) { 1865 1866 if (ctrl.value < s->qctrl[i].minimum || 1866 1867 ctrl.value > s->qctrl[i].maximum) ··· 2541 2544 unsigned int i, n; 2542 2545 int err = 0, r; 2543 2546 2544 - n = sizeof(sn9c102_id_table)/sizeof(sn9c102_id_table[0]); 2547 + n = ARRAY_SIZE(sn9c102_id_table); 2545 2548 for (i = 0; i < n-1; i++) 2546 2549 if (le16_to_cpu(udev->descriptor.idVendor) == 2547 2550 sn9c102_id_table[i].idVendor &&
+1 -1
drivers/usb/media/w9968cf.c
··· 2958 2958 }; 2959 2959 2960 2960 #define V4L1_IOCTL(cmd) \ 2961 - ((_IOC_NR((cmd)) < sizeof(v4l1_ioctls)/sizeof(char*)) ? \ 2961 + ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \ 2962 2962 v4l1_ioctls[_IOC_NR((cmd))] : "?") 2963 2963 2964 2964 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
+4 -4
drivers/usb/net/zd1201.c
··· 1722 1722 IW_PRIV_TYPE_NONE, "sethostauth" }, 1723 1723 { ZD1201GIWHOSTAUTH, IW_PRIV_TYPE_NONE, 1724 1724 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostauth" }, 1725 - { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 1725 + { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 1726 1726 IW_PRIV_TYPE_NONE, "authstation" }, 1727 1727 { ZD1201SIWMAXASSOC, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 1728 1728 IW_PRIV_TYPE_NONE, "setmaxassoc" }, ··· 1731 1731 }; 1732 1732 1733 1733 static const struct iw_handler_def zd1201_iw_handlers = { 1734 - .num_standard = sizeof(zd1201_iw_handler)/sizeof(iw_handler), 1735 - .num_private = sizeof(zd1201_private_handler)/sizeof(iw_handler), 1736 - .num_private_args = sizeof(zd1201_private_args)/sizeof(struct iw_priv_args), 1734 + .num_standard = ARRAY_SIZE(zd1201_iw_handler), 1735 + .num_private = ARRAY_SIZE(zd1201_private_handler), 1736 + .num_private_args = ARRAY_SIZE(zd1201_private_args), 1737 1737 .standard = (iw_handler *)zd1201_iw_handler, 1738 1738 .private = (iw_handler *)zd1201_private_handler, 1739 1739 .private_args = (struct iw_priv_args *) zd1201_private_args,
+1 -1
drivers/usb/serial/io_edgeport.c
··· 2353 2353 2354 2354 dbg("%s - %d", __FUNCTION__, baudrate); 2355 2355 2356 - for (i = 0; i < NUM_ENTRIES(divisor_table); i++) { 2356 + for (i = 0; i < ARRAY_SIZE(divisor_table); i++) { 2357 2357 if ( divisor_table[i].BaudRate == baudrate ) { 2358 2358 *divisor = divisor_table[i].Divisor; 2359 2359 return 0;
-3
drivers/usb/serial/io_edgeport.h
··· 31 31 #ifndef HIGH8 32 32 #define HIGH8(a) ((unsigned char)((a & 0xff00) >> 8)) 33 33 #endif 34 - #ifndef NUM_ENTRIES 35 - #define NUM_ENTRIES(x) (sizeof(x)/sizeof((x)[0])) 36 - #endif 37 34 38 35 #ifndef __KERNEL__ 39 36 #define __KERNEL__
+1 -1
drivers/usb/serial/safe_serial.c
··· 425 425 if (vendor || product) { 426 426 info ("vendor: %x product: %x\n", vendor, product); 427 427 428 - for (i = 0; i < (sizeof (id_table) / sizeof (struct usb_device_id)); i++) { 428 + for (i = 0; i < ARRAY_SIZE(id_table); i++) { 429 429 if (!id_table[i].idVendor && !id_table[i].idProduct) { 430 430 id_table[i].idVendor = vendor; 431 431 id_table[i].idProduct = product;
+2 -5
drivers/usb/serial/ti_usb_3410_5052.c
··· 351 351 int i,j; 352 352 int ret; 353 353 354 - 355 354 /* insert extra vendor and product ids */ 356 - j = sizeof(ti_id_table_3410)/sizeof(struct usb_device_id) 357 - - TI_EXTRA_VID_PID_COUNT - 1; 355 + j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1; 358 356 for (i=0; i<min(vendor_3410_count,product_3410_count); i++,j++) { 359 357 ti_id_table_3410[j].idVendor = vendor_3410[i]; 360 358 ti_id_table_3410[j].idProduct = product_3410[i]; 361 359 ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE; 362 360 } 363 - j = sizeof(ti_id_table_5052)/sizeof(struct usb_device_id) 364 - - TI_EXTRA_VID_PID_COUNT - 1; 361 + j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1; 365 362 for (i=0; i<min(vendor_5052_count,product_5052_count); i++,j++) { 366 363 ti_id_table_5052[j].idVendor = vendor_5052[i]; 367 364 ti_id_table_5052[j].idProduct = product_5052[i];
+1 -3
drivers/usb/storage/sddr09.c
··· 133 133 { 0,} 134 134 }; 135 135 136 - #define SIZE(a) (sizeof(a)/sizeof((a)[0])) 137 - 138 136 static struct nand_flash_dev * 139 137 nand_find_id(unsigned char id) { 140 138 int i; 141 139 142 - for (i = 0; i < SIZE(nand_flash_ids); i++) 140 + for (i = 0; i < ARRAY_SIZE(nand_flash_ids); i++) 143 141 if (nand_flash_ids[i].model_id == id) 144 142 return &(nand_flash_ids[i]); 145 143 return NULL;