Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH 07/25] drivers/media: Use static const char arrays
       [not found] <cover.1284406638.git.joe@perches.com>
@ 2010-09-13 19:47 ` Joe Perches
  2010-09-13 21:50   ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2010-09-13 19:47 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mauro Carvalho Chehab, mjpeg-users, linux-media

Signed-off-by: Joe Perches <joe@perches.com>
---
 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[] = "0000";
-				char sv[5];
+				char sv[sizeof("0000")];
 				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, "0000");
 				for (i = 0; i < 4; i++) {
 					if (le32_to_cpu(zr->stat_com[i]) & 1)
 						sv[i] = '1';
-- 
1.7.3.rc1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 07/25] drivers/media: Use static const char arrays
  2010-09-13 19:47 ` [PATCH 07/25] drivers/media: Use static const char arrays Joe Perches
@ 2010-09-13 21:50   ` Mauro Carvalho Chehab
  2010-09-13 22:07     ` [PATCH 07/25] drivers/media/video/zoran: Don't use initialized char array Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Mauro Carvalho Chehab @ 2010-09-13 21:50 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, mjpeg-users, linux-media

Em 13-09-2010 16:47, Joe Perches escreveu:
> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  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[] = "0000";
> -				char sv[5];
> +				char sv[sizeof("0000")];
>  				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, "0000");
>  				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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 07/25] drivers/media/video/zoran: Don't use initialized char array
  2010-09-13 21:50   ` Mauro Carvalho Chehab
@ 2010-09-13 22:07     ` Joe Perches
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2010-09-13 22:07 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-kernel, mjpeg-users, linux-media

Just fill the array as necessary and terminate with 0

Signed-off-by: Joe Perches <joe@perches.com>
---
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[] = "0000";
-				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,



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-13 22:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1284406638.git.joe@perches.com>
2010-09-13 19:47 ` [PATCH 07/25] drivers/media: Use static const char arrays Joe Perches
2010-09-13 21:50   ` Mauro Carvalho Chehab
2010-09-13 22:07     ` [PATCH 07/25] drivers/media/video/zoran: Don't use initialized char array Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox