]> err.no Git - linux-2.6/commitdiff
[PATCH] USB: Use ARRAY_SIZE macro
authorTobias Klauser <tklauser@nuerscht.ch>
Sun, 11 Dec 2005 15:20:08 +0000 (16:20 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 4 Jan 2006 21:51:43 +0000 (13:51 -0800)
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>
drivers/usb/gadget/dummy_hcd.c
drivers/usb/input/aiptek.c
drivers/usb/media/ibmcam.c
drivers/usb/media/sn9c102_core.c
drivers/usb/media/w9968cf.c
drivers/usb/net/zd1201.c
drivers/usb/serial/io_edgeport.c
drivers/usb/serial/io_edgeport.h
drivers/usb/serial/safe_serial.c
drivers/usb/serial/ti_usb_3410_5052.c
drivers/usb/storage/sddr09.c

index ce0d4b412dfe149152f9fdc40ae2466449db289e..9734cb76dd6c24ff499204aa7ff5c60ecae7865f 100644 (file)
@@ -138,7 +138,7 @@ static const char *const ep_name [] = {
        /* or like sa1100: two fixed function endpoints */
        "ep1out-bulk", "ep2in-bulk",
 };
-#define DUMMY_ENDPOINTS        (sizeof(ep_name)/sizeof(char *))
+#define DUMMY_ENDPOINTS        ARRAY_SIZE(ep_name)
 
 /*-------------------------------------------------------------------------*/
 
index 87ae08c99bc41be0f36886c8b5fd99443aa21986..a6693b0d1c4cc92c20b04957c9630bac3a8224f5 100644 (file)
@@ -2093,7 +2093,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
        /* Programming the tablet macro keys needs to be done with a for loop
         * as the keycodes are discontiguous.
         */
-       for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i)
+       for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
                set_bit(macroKeyEvents[i], inputdev->keybit);
 
        /*
@@ -2135,7 +2135,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
         * not an error :-)
         */
 
-       for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) {
+       for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
                aiptek->curSetting.programmableDelay = speeds[i];
                (void)aiptek_program_tablet(aiptek);
                if (aiptek->inputdev->absmax[ABS_X] > 0) {
index ba41fc7b95c2168c7314b0d04f4d4f4177e9b9e5..a42c222941245b16088a8e45341e3e4cad7104be 100644 (file)
@@ -3457,7 +3457,7 @@ static void ibmcam_model3_setup_after_video_if(struct uvd *uvd)
        if(init_model3_input) {
                if (debug > 0)
                        info("Setting input to RCA.");
-               for (i=0; i < (sizeof(initData)/sizeof(initData[0])); i++) {
+               for (i=0; i < ARRAY_SIZE(initData); i++) {
                        ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index);
                }
        }
index 08723459da86fdb9a4be724e66675c5e86d1c28b..8d1a1c357d5a6d7c01b39fc7b53036a5780f218a 100644 (file)
@@ -1316,7 +1316,7 @@ static int sn9c102_init(struct sn9c102_device* cam)
        struct v4l2_control ctrl;
        struct v4l2_queryctrl *qctrl;
        struct v4l2_rect* rect;
-       u8 i = 0, n = 0;
+       u8 i = 0;
        int err = 0;
 
        if (!(cam->state & DEV_INITIALIZED)) {
@@ -1352,7 +1352,7 @@ static int sn9c102_init(struct sn9c102_device* cam)
                return err;
 
        if (s->pix_format.pixelformat == V4L2_PIX_FMT_SN9C10X)
-               DBG(3, "Compressed video format is active, quality %d", 
+               DBG(3, "Compressed video format is active, quality %d",
                    cam->compression.quality)
        else
                DBG(3, "Uncompressed video format is active")
@@ -1364,9 +1364,8 @@ static int sn9c102_init(struct sn9c102_device* cam)
                }
 
        if (s->set_ctrl) {
-               n = sizeof(s->qctrl) / sizeof(s->qctrl[0]);
-               for (i = 0; i < n; i++)
-                       if (s->qctrl[i].id != 0 && 
+               for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
+                       if (s->qctrl[i].id != 0 &&
                            !(s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)) {
                                ctrl.id = s->qctrl[i].id;
                                ctrl.value = qctrl[i].default_value;
@@ -1388,7 +1387,7 @@ static int sn9c102_init(struct sn9c102_device* cam)
                init_waitqueue_head(&cam->wait_stream);
                cam->nreadbuffers = 2;
                memcpy(s->_qctrl, s->qctrl, sizeof(s->qctrl));
-               memcpy(&(s->_rect), &(s->cropcap.defrect), 
+               memcpy(&(s->_rect), &(s->cropcap.defrect),
                       sizeof(struct v4l2_rect));
                cam->state |= DEV_INITIALIZED;
        }
@@ -1810,13 +1809,12 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
        {
                struct sn9c102_sensor* s = cam->sensor;
                struct v4l2_queryctrl qc;
-               u8 i, n;
+               u8 i;
 
                if (copy_from_user(&qc, arg, sizeof(qc)))
                        return -EFAULT;
 
-               n = sizeof(s->qctrl) / sizeof(s->qctrl[0]);
-               for (i = 0; i < n; i++)
+               for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
                        if (qc.id && qc.id == s->qctrl[i].id) {
                                memcpy(&qc, &(s->qctrl[i]), sizeof(qc));
                                if (copy_to_user(arg, &qc, sizeof(qc)))
@@ -1852,7 +1850,7 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
        {
                struct sn9c102_sensor* s = cam->sensor;
                struct v4l2_control ctrl;
-               u8 i, n;
+               u8 i;
                int err = 0;
 
                if (!s->set_ctrl)
@@ -1861,8 +1859,7 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
                if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                        return -EFAULT;
 
-               n = sizeof(s->qctrl) / sizeof(s->qctrl[0]);
-               for (i = 0; i < n; i++)
+               for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
                        if (ctrl.id == s->qctrl[i].id) {
                                if (ctrl.value < s->qctrl[i].minimum ||
                                    ctrl.value > s->qctrl[i].maximum)
@@ -2544,7 +2541,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        unsigned int i, n;
        int err = 0, r;
 
-       n = sizeof(sn9c102_id_table)/sizeof(sn9c102_id_table[0]);
+       n = ARRAY_SIZE(sn9c102_id_table);
        for (i = 0; i < n-1; i++)
                if (le16_to_cpu(udev->descriptor.idVendor) == 
                    sn9c102_id_table[i].idVendor &&
index 52b90d50febbc8228b87f2ea755f4e557b2b30e2..8d6a1ff6595fea54fdb95da37a27f8b082ddf73e 100644 (file)
@@ -2958,7 +2958,7 @@ static int w9968cf_v4l_ioctl(struct inode* inode, struct file* filp,
        };
 
        #define V4L1_IOCTL(cmd) \
-               ((_IOC_NR((cmd)) < sizeof(v4l1_ioctls)/sizeof(char*)) ? \
+               ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \
                v4l1_ioctls[_IOC_NR((cmd))] : "?")
 
        cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
index 4d6673adc8fc4263cde8ea374192f42481e34cb9..2af21a620c0788c736c5c052f0675f13b8e298ab 100644 (file)
@@ -1722,7 +1722,7 @@ static const struct iw_priv_args zd1201_private_args[] = {
            IW_PRIV_TYPE_NONE, "sethostauth" },
        { ZD1201GIWHOSTAUTH, IW_PRIV_TYPE_NONE,
            IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostauth" },
-       { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 
+       { ZD1201SIWAUTHSTA, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1,
            IW_PRIV_TYPE_NONE, "authstation" },
        { ZD1201SIWMAXASSOC, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
            IW_PRIV_TYPE_NONE, "setmaxassoc" },
@@ -1731,9 +1731,9 @@ static const struct iw_priv_args zd1201_private_args[] = {
 };
 
 static const struct iw_handler_def zd1201_iw_handlers = {
-       .num_standard           = sizeof(zd1201_iw_handler)/sizeof(iw_handler),
-       .num_private            = sizeof(zd1201_private_handler)/sizeof(iw_handler),
-       .num_private_args       = sizeof(zd1201_private_args)/sizeof(struct iw_priv_args),
+       .num_standard           = ARRAY_SIZE(zd1201_iw_handler),
+       .num_private            = ARRAY_SIZE(zd1201_private_handler),
+       .num_private_args       = ARRAY_SIZE(zd1201_private_args),
        .standard               = (iw_handler *)zd1201_iw_handler,
        .private                = (iw_handler *)zd1201_private_handler,
        .private_args           = (struct iw_priv_args *) zd1201_private_args,
index 89bb3563c9195f6a0a8b423ca4559c6a75aee225..faedbeb6ba49a1a958f03cb182cb3780b7d71296 100644 (file)
@@ -2353,7 +2353,7 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
 
        dbg("%s - %d", __FUNCTION__, baudrate);
 
-       for (i = 0; i < NUM_ENTRIES(divisor_table); i++) {
+       for (i = 0; i < ARRAY_SIZE(divisor_table); i++) {
                if ( divisor_table[i].BaudRate == baudrate ) {
                        *divisor = divisor_table[i].Divisor;
                        return 0;
index 5112d7aac05506d6822c9b0b053d8592226d350b..123fa8a904e65a15a9c7a5eb7b0a44dc07e043e7 100644 (file)
@@ -31,9 +31,6 @@
 #ifndef HIGH8
        #define HIGH8(a)        ((unsigned char)((a & 0xff00) >> 8))
 #endif
-#ifndef NUM_ENTRIES
-       #define NUM_ENTRIES(x)  (sizeof(x)/sizeof((x)[0]))
-#endif
 
 #ifndef __KERNEL__
 #define __KERNEL__
index 86dc21c728a534b091e73cfd4d7d103ffb92a48f..f0215f850d2d3eea98faf2b6569075f596aec3cd 100644 (file)
@@ -425,7 +425,7 @@ static int __init safe_init (void)
        if (vendor || product) {
                info ("vendor: %x product: %x\n", vendor, product);
 
-               for (i = 0; i < (sizeof (id_table) / sizeof (struct usb_device_id)); i++) {
+               for (i = 0; i < ARRAY_SIZE(id_table); i++) {
                        if (!id_table[i].idVendor && !id_table[i].idProduct) {
                                id_table[i].idVendor = vendor;
                                id_table[i].idProduct = product;
index 9e53ec75bcfdd94d1c70b5f2ad4c999d74e5f416..abb830cb77bd926365d20c67ed5516b2d11d0b49 100644 (file)
@@ -351,17 +351,14 @@ static int __init ti_init(void)
        int i,j;
        int ret;
 
-
        /* insert extra vendor and product ids */
-       j = sizeof(ti_id_table_3410)/sizeof(struct usb_device_id)
-               - TI_EXTRA_VID_PID_COUNT - 1;
+       j = ARRAY_SIZE(ti_id_table_3410) - TI_EXTRA_VID_PID_COUNT - 1;
        for (i=0; i<min(vendor_3410_count,product_3410_count); i++,j++) {
                ti_id_table_3410[j].idVendor = vendor_3410[i];
                ti_id_table_3410[j].idProduct = product_3410[i];
                ti_id_table_3410[j].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
        }
-       j = sizeof(ti_id_table_5052)/sizeof(struct usb_device_id)
-               - TI_EXTRA_VID_PID_COUNT - 1;
+       j = ARRAY_SIZE(ti_id_table_5052) - TI_EXTRA_VID_PID_COUNT - 1;
        for (i=0; i<min(vendor_5052_count,product_5052_count); i++,j++) {
                ti_id_table_5052[j].idVendor = vendor_5052[i];
                ti_id_table_5052[j].idProduct = product_5052[i];
index b8e7802c871d91237908d5afd7f403448c849932..fb8bacaae27cbcb5eaaf6f845fc5e10dc8ddaa7f 100644 (file)
@@ -133,13 +133,11 @@ static struct nand_flash_dev nand_flash_ids[] = {
        { 0,}
 };
 
-#define SIZE(a)        (sizeof(a)/sizeof((a)[0]))
-
 static struct nand_flash_dev *
 nand_find_id(unsigned char id) {
        int i;
 
-       for (i = 0; i < SIZE(nand_flash_ids); i++)
+       for (i = 0; i < ARRAY_SIZE(nand_flash_ids); i++)
                if (nand_flash_ids[i].model_id == id)
                        return &(nand_flash_ids[i]);
        return NULL;