[Mjpeg-users] [PATCH 07/25] drivers/media/video/zoran: Don't use initialized char array

2010-09-15 Thread Joe Perches
Just fill the array as necessary and terminate with 0

Signed-off-by: Joe Perches 
---
diff --git a/drivers/media/video/zoran/zoran_device.c 
b/drivers/media/video/zoran/zoran_device.c
index 6f846ab..b02007e 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -1470,8 +1470,7 @@ zoran_irq (int irq,
(zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
if (zr36067_debug > 1 && (!zr->frame_num || 
zr->JPEG_error)) {
-   char sc[] = "";
-   char sv[5];
+   char sv[BUZ_NUM_STAT_COM + 1];
int i;
 
printk(KERN_INFO
@@ -1481,12 +1480,9 @@ zoran_irq (int irq,
   zr->jpg_settings.field_per_buff,
   zr->JPEG_missed);
 
-   strcpy(sv, sc);
-   for (i = 0; i < 4; i++) {
-   if (le32_to_cpu(zr->stat_com[i]) & 1)
-   sv[i] = '1';
-   }
-   sv[4] = 0;
+   for (i = 0; i < BUZ_NUM_STAT_COM; i++)
+   sv[i] = le32_to_cpu(zr->stat_com[i]) & 
1 ? '1' : '0';
+   sv[BUZ_NUM_STAT_COM] = 0;
printk(KERN_INFO
   "%s: stat_com=%s 
queue_state=%ld/%ld/%ld/%ld\n",
   ZR_DEVNAME(zr), sv,



--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Mjpeg-users mailing list
Mjpeg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mjpeg-users


[Mjpeg-users] [PATCH 00/25] treewide-next: Use static const char arrays

2010-09-15 Thread Joe Perches
Using static const char foo[] = "bar" can save some
code and text space, so change the places where it's possible.

Also change the places that use
char foo[] = "barX";
...
foo[3] = value + '0';
where X is typically changed
char foo[sizeof("barX")];
...
sprintf(foo, "bar%c", value + '0');

Joe Perches (25):
  arch/mips: Use static const char arrays
  arch/powerpc: Use static const char arrays
  drivers/acpi: Use static const char arrays
  drivers/char: Use static const char arrays
  drivers/i2c: Use static const char arrays
  drivers/isdn: Use static const char arrays
  drivers/media: Use static const char arrays
  drivers/net/atl1c: Use static const char arrays
  drivers/net/atl1e: Use static const char arrays
  drivers/net/(intel): Use static const char arrays
  drivers/net/netxen: Use static const char arrays
  drivers/net/qlcnic: Use static const char arrays
  drivers/net/spider_net.c: Use static const char arrays
  drivers/net/vnxnet3: Use static const char arrays
  drivers/net/wireless/ipw2x00: Use static const char arrays
  drivers/s390/char: Use static const char arrays
  drivers/scsi: Use static const char arrays
  drivers/serial/suncore.c: Use static const char arrays
  drivers/staging: Use static const char arrays
  drivers/usb: Use static const char arrays
  drivers/video: Use static const char arrays
  net/dsa: Use static const char arrays
  net/sunrpc: Use static const char arrays
  sound: Use static const char arrays
  tools/perf/util: Use static const char arrays

 arch/mips/pnx8550/common/reset.c   |4 ++--
 arch/powerpc/boot/addnote.c|4 ++--
 arch/powerpc/boot/cuboot-c2k.c |4 ++--
 arch/powerpc/kernel/irq.c  |2 +-
 drivers/acpi/sleep.c   |4 ++--
 drivers/char/hvc_vio.c |2 +-
 drivers/i2c/busses/i2c-stu300.c|4 ++--
 drivers/isdn/hysdn/hycapi.c|2 +-
 drivers/isdn/mISDN/dsp_cmx.c   |2 +-
 drivers/media/video/zoran/zoran_device.c   |5 ++---
 drivers/net/atl1c/atl1c.h  |4 ++--
 drivers/net/atl1c/atl1c_main.c |4 ++--
 drivers/net/atl1e/atl1e.h  |4 ++--
 drivers/net/atl1e/atl1e_main.c |4 ++--
 drivers/net/e1000/e1000.h  |2 +-
 drivers/net/e1000/e1000_main.c |4 ++--
 drivers/net/e1000e/e1000.h |2 +-
 drivers/net/e1000e/netdev.c|2 +-
 drivers/net/igb/igb.h  |4 ++--
 drivers/net/igb/igb_main.c |4 ++--
 drivers/net/igbvf/igbvf.h  |2 +-
 drivers/net/igbvf/netdev.c |2 +-
 drivers/net/ixgb/ixgb.h|2 +-
 drivers/net/ixgb/ixgb_main.c   |2 +-
 drivers/net/ixgbe/ixgbe.h  |2 +-
 drivers/net/ixgbe/ixgbe_main.c |4 ++--
 drivers/net/ixgbevf/ixgbevf.h  |2 +-
 drivers/net/ixgbevf/ixgbevf_main.c |2 +-
 drivers/net/netxen/netxen_nic.h|2 +-
 drivers/net/netxen/netxen_nic_main.c   |2 +-
 drivers/net/qlcnic/qlcnic.h|2 +-
 drivers/net/qlcnic/qlcnic_main.c   |2 +-
 drivers/net/spider_net.c   |2 +-
 drivers/net/vmxnet3/vmxnet3_drv.c  |2 +-
 drivers/net/vmxnet3/vmxnet3_int.h  |2 +-
 drivers/net/wireless/ipw2x00/ipw2100.c |2 +-
 drivers/net/wireless/ipw2x00/ipw2200.c |2 +-
 drivers/net/wireless/ipw2x00/libipw_module.c   |2 +-
 drivers/s390/char/vmlogrdr.c   |4 ++--
 drivers/scsi/bnx2i/bnx2i_hwi.c |6 +++---
 drivers/scsi/lpfc/lpfc_init.c  |2 +-
 drivers/scsi/megaraid/megaraid_mbox.c  |6 +++---
 drivers/serial/suncore.c   |4 ++--
 drivers/staging/brcm80211/util/bcmutils.c  |2 +-
 drivers/staging/comedi/drivers/comedi_bond.c   |2 +-
 drivers/staging/cxt1e1/ossiRelease.c   |2 +-
 drivers/staging/go7007/go7007-driver.c |2 +-
 drivers/staging/msm/mdp.c  |2 +-
 .../staging/rtl8192e/ieee80211/ieee80211_module.c  |2 +-
 .../staging/rtl8192u/ieee80211/ieee80211_module.c  |2 +-
 drivers/staging/tidspbridge/rmgr/dbdcd.c   |6 +++---
 drivers/usb/atm/ueagle-atm.c   |   14 +-
 drivers/usb/otg/langwell_otg.c |2 +-
 drivers/video/sh_mipi_dsi.c|4 ++--
 drivers/video/sis/sis_main.c  

Re: [Mjpeg-users] [PATCH 07/25] drivers/media: Use static const char arrays

2010-09-15 Thread Mauro Carvalho Chehab
Em 13-09-2010 16:47, Joe Perches escreveu:
> Signed-off-by: Joe Perches 
> ---
>  drivers/media/video/zoran/zoran_device.c |5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/video/zoran/zoran_device.c 
> b/drivers/media/video/zoran/zoran_device.c
> index 6f846ab..ea8a1e9 100644
> --- a/drivers/media/video/zoran/zoran_device.c
> +++ b/drivers/media/video/zoran/zoran_device.c
> @@ -1470,8 +1470,7 @@ zoran_irq (int irq,
>   (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
>zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
>   if (zr36067_debug > 1 && (!zr->frame_num || 
> zr->JPEG_error)) {
> - char sc[] = "";
> - char sv[5];
> + char sv[sizeof("")];
>   int i;
>  
>   printk(KERN_INFO
> @@ -1481,7 +1480,7 @@ zoran_irq (int irq,
>  zr->jpg_settings.field_per_buff,
>  zr->JPEG_missed);
>  
> - strcpy(sv, sc);
> + strcpy(sv, "");
>   for (i = 0; i < 4; i++) {
>   if (le32_to_cpu(zr->stat_com[i]) & 1)
>   sv[i] = '1';

This looks ugly to me, as someone may change the string at strcpy and not 
change at sizeof.
Could you please try to work on a better alternative?

The cleaner way seems to be to rewrite it as:

#define BUZ_MODE_STAT   4

char sv[BUZ_MODE_STAT + 1];
...
for (i = 0; i < BUZ_MODE_STAT; i++)
sv[i] = (le32_to_cpu(zr->stat_com[i]) & 1)? '1' : '0';



Cheers,
Mauro

--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Mjpeg-users mailing list
Mjpeg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mjpeg-users


[Mjpeg-users] [PATCH 07/25] drivers/media: Use static const char arrays

2010-09-15 Thread Joe Perches
Signed-off-by: Joe Perches 
---
 drivers/media/video/zoran/zoran_device.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/video/zoran/zoran_device.c 
b/drivers/media/video/zoran/zoran_device.c
index 6f846ab..ea8a1e9 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -1470,8 +1470,7 @@ zoran_irq (int irq,
(zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
if (zr36067_debug > 1 && (!zr->frame_num || 
zr->JPEG_error)) {
-   char sc[] = "";
-   char sv[5];
+   char sv[sizeof("")];
int i;
 
printk(KERN_INFO
@@ -1481,7 +1480,7 @@ zoran_irq (int irq,
   zr->jpg_settings.field_per_buff,
   zr->JPEG_missed);
 
-   strcpy(sv, sc);
+   strcpy(sv, "");
for (i = 0; i < 4; i++) {
if (le32_to_cpu(zr->stat_com[i]) & 1)
sv[i] = '1';
-- 
1.7.3.rc1


--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
___
Mjpeg-users mailing list
Mjpeg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mjpeg-users