2007-02-05 16:51:41

by Ahmed S. Darwish

[permalink] [raw]
Subject: [PATCH 00] A series of patches to use ARRAY_SIZE under video subtree

Hi all,

Follows is a series of patches to use ARRAY_SIZE macro in the video drivers
located under /drivers/media/video.
Patches are test compiled and can be applied cleanly on 2.6.20

cpia2/cpia2_v4l.c | 9 +++++----
ov7670.c | 7 ++++---
pvrusb2/pvrusb2-audio.c | 10 ++++------
pvrusb2/pvrusb2-ctrl.c | 4 ++--
pvrusb2/pvrusb2-cx2584x-v4l.c | 10 ++++------
pvrusb2/pvrusb2-debugifc.c | 5 +++--
pvrusb2/pvrusb2-eeprom.c | 3 ++-
pvrusb2/pvrusb2-hdw.c | 3 ++-
tveeprom.c | 6 +++---
tvp5150.c | 3 ++-
usbvideo/quickcam_messenger.c | 2 +-
11 files changed, 32 insertions(+), 30 deletions(-)

Thanks,
--
Ahmed S. Darwish
http://darwish-07.blogspot.com


2007-02-05 16:53:45

by Ahmed S. Darwish

[permalink] [raw]
Subject: [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2)

Hi all,
A patch to use ARRAY_SIZE already defined in kernel.h. This patch is
a complementry (and does not include) the one sent one week earlier.

Signed-off-by: Ahmed S. Darwish <[email protected]>
---
It seems that the earlier grep expression I used to produce the first
patch didn't catch the below occurences. Sorry for the incovenience.

Patch is compile tested.

diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 9846c46..4a32fa2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -24,6 +24,7 @@
#include "pvrusb2-hdw-internal.h"
#include "pvrusb2-debug.h"
#include <linux/videodev2.h>
+#include <linux/kernel.h>
#include <media/msp3400.h>
#include <media/v4l2-common.h>

@@ -99,8 +100,7 @@ static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
unsigned long msk;
unsigned int idx;

- for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
- idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
msk = 1 << idx;
if (ctxt->stale_mask & msk) continue;
if (msp3400_ops[idx].check(ctxt)) {
@@ -116,8 +116,7 @@ static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
unsigned long msk;
unsigned int idx;

- for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
- idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
msk = 1 << idx;
if (!(ctxt->stale_mask & msk)) continue;
ctxt->stale_mask &= ~msk;
@@ -183,8 +182,7 @@ int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
ctxt->astat.ctxt = ctxt;
ctxt->astat.status = (int (*)(void *))get_audio_status;
ctxt->astat.detach = (void (*)(void *))pvr2_msp3400_detach;
- ctxt->stale_mask = (1 << (sizeof(msp3400_ops)/
- sizeof(msp3400_ops[0]))) - 1;
+ ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
cp->handler = &ctxt->i2c_handler;
hdw->audio_stat = &ctxt->astat;
pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index c77de85..22b128c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -24,7 +24,7 @@
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mutex.h>
-
+#include <linux/kernel.h>

/* Set the given control. */
int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
@@ -507,7 +507,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
} else if (cptr->info->type == pvr2_ctl_bool) {
ret = parse_token(
ptr,len,valptr,boolNames,
- sizeof(boolNames)/sizeof(boolNames[0]));
+ ARRAY_SIZE(boolNames));
if (ret == 1) {
*valptr = *valptr ? !0 : 0;
} else if (ret == 0) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 848fb23..e85daf6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -39,6 +39,7 @@
#include <media/v4l2-common.h>
#include <linux/errno.h>
#include <linux/slab.h>
+#include <linux/kernel.h>

struct pvr2_v4l_cx2584x {
struct pvr2_i2c_handler handler;
@@ -150,8 +151,7 @@ static int decoder_check(struct pvr2_v4l_cx2584x *ctxt)
unsigned long msk;
unsigned int idx;

- for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
- idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
msk = 1 << idx;
if (ctxt->stale_mask & msk) continue;
if (decoder_ops[idx].check(ctxt)) {
@@ -167,8 +167,7 @@ static void decoder_update(struct pvr2_v4l_cx2584x *ctxt)
unsigned long msk;
unsigned int idx;

- for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
- idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
msk = 1 << idx;
if (!(ctxt->stale_mask & msk)) continue;
ctxt->stale_mask &= ~msk;
@@ -256,8 +255,7 @@ int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset;
ctxt->client = cp;
ctxt->hdw = hdw;
- ctxt->stale_mask = (1 << (sizeof(decoder_ops)/
- sizeof(decoder_ops[0]))) - 1;
+ ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
hdw->decoder_ctrl = &ctxt->ctrl;
cp->handler = &ctxt->handler;
{
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index f985f00..0f32772 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -21,6 +21,7 @@

#include <linux/string.h>
#include <linux/slab.h>
+#include <linux/kernel.h>
#include "pvrusb2-debugifc.h"
#include "pvrusb2-hdw.h"
#include "pvrusb2-debug.h"
@@ -152,7 +153,7 @@ static unsigned long debugifc_find_mask(const char *buf,unsigned int count)
{
struct debugifc_mask_item *mip;
unsigned int idx;
- for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
mip = mask_items + idx;
if (debugifc_match_keyword(buf,count,mip->name)) {
return mip->msk;
@@ -169,7 +170,7 @@ static int debugifc_print_mask(char *buf,unsigned int sz,
unsigned int idx;
int bcnt = 0;
int ccnt;
- for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
mip = mask_items + idx;
if (!(mip->msk & msk)) continue;
ccnt = scnprintf(buf,sz,"%s%c%s",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
index 6cff8e7..b64ebc2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
@@ -20,6 +20,7 @@
*
*/

+#include <linux/kernel.h>
#include "pvrusb2-eeprom.h"
#include "pvrusb2-hdw-internal.h"
#include "pvrusb2-debug.h"
@@ -104,7 +105,7 @@ static u8 *pvr2_eeprom_fetch(struct pvr2_hdw *hdw)
msg[1].buf = eeprom+tcnt;
if ((ret = i2c_transfer(
&hdw->i2c_adap,
- msg,sizeof(msg)/sizeof(msg[0]))) != 2) {
+ msg,ARRAY_SIZE(msg))) != 2) {
pvr2_trace(PVR2_TRACE_ERROR_LEGS,
"eeprom fetch set offs err=%d",ret);
kfree(eeprom);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index d200496..1b3b042 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -20,6 +20,7 @@
*/

#include <linux/errno.h>
+#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/firmware.h>
@@ -604,7 +605,7 @@ static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr)

#define DEFENUM(tab) \
.type = pvr2_ctl_enum, \
- .def.type_enum.count = (sizeof(tab)/sizeof((tab)[0])), \
+ .def.type_enum.count = ARRAY_SIZE(tab), \
.def.type_enum.value_names = tab

#define DEFBOOL \

--
Ahmed S. Darwish
http://darwish-07.blogspot.com

2007-02-05 16:54:15

by Ahmed S. Darwish

[permalink] [raw]
Subject: [PATCH 2.6.20] misc-video: use ARRAY_SIZE macro when appropriate

Hi all,

A patch to use ARRAY_SIZE macro in miscellaneous video drivers found
with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <[email protected]>
---
Patches are compile tested.

diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index d09f499..3237c25 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -33,6 +33,7 @@


#include <linux/module.h>
+#include <linux/kernel.h>
#include <linux/time.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -105,7 +106,7 @@ static struct control_menu_info framerate_controls[] =
{ CPIA2_VP_FRAMERATE_25, "25 fps" },
{ CPIA2_VP_FRAMERATE_30, "30 fps" },
};
-#define NUM_FRAMERATE_CONTROLS (sizeof(framerate_controls)/sizeof(framerate_controls[0]))
+#define NUM_FRAMERATE_CONTROLS ARRAY_SIZE(framerate_controls)

static struct control_menu_info flicker_controls[] =
{
@@ -113,7 +114,7 @@ static struct control_menu_info flicker_controls[] =
{ FLICKER_50, "50 Hz" },
{ FLICKER_60, "60 Hz" },
};
-#define NUM_FLICKER_CONTROLS (sizeof(flicker_controls)/sizeof(flicker_controls[0]))
+#define NUM_FLICKER_CONTROLS ARRAY_SIZE(flicker_controls)

static struct control_menu_info lights_controls[] =
{
@@ -122,7 +123,7 @@ static struct control_menu_info lights_controls[] =
{ 128, "Bottom" },
{ 192, "Both" },
};
-#define NUM_LIGHTS_CONTROLS (sizeof(lights_controls)/sizeof(lights_controls[0]))
+#define NUM_LIGHTS_CONTROLS ARRAY_SIZE(lights_controls)
#define GPIO_LIGHTS_MASK 192

static struct v4l2_queryctrl controls[] = {
@@ -235,7 +236,7 @@ static struct v4l2_queryctrl controls[] = {
.default_value = 0,
},
};
-#define NUM_CONTROLS (sizeof(controls)/sizeof(controls[0]))
+#define NUM_CONTROLS ARRAY_SIZE(controls)


/******************************************************************************
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index 5ed0adc..0f6020e 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -11,6 +11,7 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
+#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/videodev.h>
@@ -503,7 +504,7 @@ static struct ov7670_format_struct {
.cmatrix = { 179, -179, 0, -61, -176, 228 },
},
};
-#define N_OV7670_FMTS (sizeof(ov7670_formats)/sizeof(ov7670_formats[0]))
+#define N_OV7670_FMTS ARRAY_SIZE(ov7670_formats)

/*
* All formats we support are 2 bytes/pixel.
@@ -596,7 +597,7 @@ static struct ov7670_win_size {
},
};

-#define N_WIN_SIZES (sizeof(ov7670_win_sizes)/sizeof(ov7670_win_sizes[0]))
+#define N_WIN_SIZES ARRAY_SIZE(ov7670_win_sizes)


/*
@@ -1149,7 +1150,7 @@ static struct ov7670_control {
.query = ov7670_q_hflip,
},
};
-#define N_CONTROLS (sizeof(ov7670_controls)/sizeof(ov7670_controls[0]))
+#define N_CONTROLS ARRAY_SIZE(ov7670_controls)

static struct ov7670_control *ov7670_find_control(__u32 id)
{
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 4e7c1fa..4439080 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -453,7 +453,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
to indicate 4052 mux was removed in favor of using MSP
inputs directly. */
audioic = eeprom_data[i+2] & 0x7f;
- if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+ if (audioic < ARRAY_SIZE(audioIC))
tvee->audio_processor = audioIC[audioic].id;
else
tvee->audio_processor = AUDIO_CHIP_UNKNOWN;
@@ -486,7 +486,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
to indicate 4052 mux was removed in favor of using MSP
inputs directly. */
audioic = eeprom_data[i+1] & 0x7f;
- if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+ if (audioic < ARRAY_SIZE(audioIC))
tvee->audio_processor = audioIC[audioic].id;
else
tvee->audio_processor = AUDIO_CHIP_UNKNOWN;
@@ -641,7 +641,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
tveeprom_info("audio processor is unknown (no idx)\n");
tvee->audio_processor=AUDIO_CHIP_UNKNOWN;
} else {
- if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+ if (audioic < ARRAY_SIZE(audioIC))
tveeprom_info("audio processor is %s (idx %d)\n",
audioIC[audioic].name,audioic);
else
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index bc0a4fc..9eeefee 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -6,6 +6,7 @@
*/

#include <linux/i2c.h>
+#include <linux/kernel.h>
#include <linux/videodev.h>
#include <linux/delay.h>
#include <linux/video_decoder.h>
@@ -1012,7 +1013,7 @@ static int tvp5150_command(struct i2c_client *c,
{
struct v4l2_control *ctrl = arg;
u8 i, n;
- n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
+ n = ARRAY_SIZE(tvp5150_qctrl);
for (i = 0; i < n; i++)
if (ctrl->id == tvp5150_qctrl[i].id) {
if (ctrl->value <
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
index ec0ff22..082560e 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -439,7 +439,7 @@ static int qcm_sensor_init(struct uvd *uvd)
int ret;
int i;

- for (i=0; i < sizeof(regval_table)/sizeof(regval_table[0]) ; i++) {
+ for (i = 0; i < ARRAY_SIZE(regval_table); i++) {
CHECK_RET(ret, qcm_stv_setb(uvd->dev,
regval_table[i].reg,
regval_table[i].val));

--
Ahmed S. Darwish
http://darwish-07.blogspot.com

2007-02-05 19:24:28

by Mike Isely

[permalink] [raw]
Subject: Re: [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2)

On Mon, 5 Feb 2007, Ahmed S. Darwish wrote:

> Hi all,
> A patch to use ARRAY_SIZE already defined in kernel.h. This patch is
> a complementry (and does not include) the one sent one week earlier.
>
> Signed-off-by: Ahmed S. Darwish <[email protected]>

Ahmed:

After that initial patch a while back I then combed through the entire
pvrusb2 driver and cleaned up all the other cases. Those patches should
already be on a trajectory for 2.6.21. I'll check it against this patch
but I think these should already all be handled.

-Mike


--
| Mike Isely | PGP fingerprint
Spammers Die!! | | 03 54 43 4D 75 E5 CC 92
| isely @ pobox (dot) com | 71 16 01 E2 B5 F5 C1 E8
| |