V4L: stk11xx, use ARRAY_SIZE in another 2 cases
PATCH 1/3 V4L: stk11xx, use ARRAY_SIZE in another 2 cases
stk11xx, use ARRAY_SIZE in another 2 cases
There were 2 places with constant in for loop. Use ARRARY_SIZE instead to allow easy update of the tables.
---
commit addcd116df57eaca525a1c827efdd5bf3e61b7b5
tree a4ee11673dfdbaabe1500cd9e4301bd535177bfa
parent 926af968884e1e153ad2f91892ff71ec33005d22
author Jiri Slaby <[email protected]> Tue, 28 Aug 2007 09:53:55 +0200 committer Jiri Slaby <[email protected]> Tue, 28 Aug 2007 09:53:55 +0200
drivers/media/video/stk1125.c | 2 +- drivers/media/video/stk1135.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/video/stk1125.c +1 -1
@@ -80,7 +80,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)break ; } -for (i =0 ; i <59 ; i++) { +for (i =0 ; i <ARRAY_SIZE (values_1_204); i++) {stk11xx_read_dummy (dev,0x02ff );stk11xx_write_reg (dev,0x02ff ,0x00 );
drivers/media/video/stk1135.c +1 -1
@@ -53,7 +53,7 @@ static int stk1135_load_microcode(struct stk11xx *dev) 0xe4, 0x09, 0xc8, 0x08, 0x08, 0x10, 0x14 }; -for (i =0 ; i <117 ; i++) { +for (i =0 ; i <ARRAY_SIZE (values_204); i++) {stk11xx_read_dummy (dev,0x02ff );stk11xx_write_reg (dev,0x02ff ,0x00 );
PATCH 2/3 V4L: stk11xx, use retval from stk11xx_check_device
stk11xx, use retval from stk11xx_check_device
stk11xx_check_device returns 0 for success of non-inited device, 1 for success of inited device and negative for error cases. bubble the negative value to the caller.
---
commit 95de679efc8c9fbd13121f3fbe4144196a66f387
tree bdc82d59c4ea9ec96abdde81209cb319d71192b6
parent addcd116df57eaca525a1c827efdd5bf3e61b7b5
author Jiri Slaby <[email protected]> Tue, 28 Aug 2007 09:55:20 +0200 committer Jiri Slaby <[email protected]> Tue, 28 Aug 2007 09:55:20 +0200
drivers/media/video/stk1125.c | 2 +- drivers/media/video/stk1135.c | 2 +- drivers/media/video/stkdcnew.c | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-)
drivers/media/video/stk1125.c +1 -1
@@ -91,7 +91,7 @@ static int stk1125_load_microcode(struct stk11xx *dev) retok =stk11xx_check_device (dev,500 );if (retok !=1 ) {dev_err (&dev->udev->dev,"load microcode fail\n" ); -return -EIO ; +return retok <0 ? retok : -EIO ; }stk11xx_write_reg (dev,0x02ff ,0x00 );
drivers/media/video/stk1135.c +1 -1
@@ -64,7 +64,7 @@ static int stk1135_load_microcode(struct stk11xx *dev) retok =stk11xx_check_device (dev,500 );if (retok !=1 ) {dev_err (&dev->udev->dev,"load microcode failed\n" ); -return -EIO ; +return retok <0 ? retok : -EIO ; }stk11xx_write_reg (dev,0x02ff ,0x00 );
drivers/media/video/stkdcnew.c +1 -2
@@ -102,10 +102,9 @@ static int stkdcnew_load_microcode(struct stk11xx *dev)stk11xx_write_reg (dev,0x0200 ,0x01 ); retok =stk11xx_check_device (dev,500 ); -if (retok !=1 ) {dev_err (&dev->udev->dev,"load microcode fail!\n" ); -return -EIO ; +return retok <0 ? retok : -EIO ; }stk11xx_write_reg (dev,0x02ff ,0x00 );
PATCH 3/3 V4L: stk11xx, add static to tables
In reply to Jiri Slabystk11xx, add static to tables
ensure, that the compiler will put all the tables in static storage
---
commit 49fa12761f1fef6f0e6bf7d8ef7e599c5eef6871
tree 565c5d471c554349fafc4d3ba27553d2fc77c45d
parent 95de679efc8c9fbd13121f3fbe4144196a66f387
author Jiri Slaby <[email protected]> Tue, 28 Aug 2007 10:14:19 +0200 committer Jiri Slaby <[email protected]> Tue, 28 Aug 2007 10:14:19 +0200
drivers/media/video/stk1125.c | 58 +++++++++++++++++----------------- drivers/media/video/stk1135.c | 54 ++++++++++++++++---------------- drivers/media/video/stkdcnew.c | 68 ++++++++++++++++++++-------------------- 3 files changed, 90 insertions(+), 90 deletions(-)
drivers/media/video/stk1125.c +29 -29
@@ -26,7 +26,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)int retok;/* From 80x60 to 640x480 */ -const u8 values_1_204[] = { +static const u8 values_1_204[] = {0x12 ,0x11 ,0x3b ,0x6a ,0x13 ,0x10 ,0x00 ,0x01 ,0x02 ,0x13 ,0x39 ,0x38 ,0x37 ,0x35 ,0x0e ,0x12 ,0x04 ,0x0c ,0x0d ,0x17 ,0x18 ,0x32 ,0x19 ,0x1a ,0x03 ,0x1b ,0x16 ,0x33 ,0x34 ,0x41 ,
@@ -34,7 +34,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)0x95 ,0x40 ,0x29 ,0x0f ,0xa5 ,0x1e ,0xa9 ,0xaa ,0xab ,0x90 ,0x91 ,0x9f ,0xa0 ,0x24 ,0x25 ,0x26 ,0x14 ,0x2a ,0x2b }; -const u8 values_1_205[] = { +static const u8 values_1_205[] = {0x45 ,0x80 ,0x01 ,0x7d ,0x80 ,0x00 ,0x00 ,0x80 ,0x80 ,0x80 ,0x50 ,0x93 ,0x00 ,0x81 ,0x20 ,0x45 ,0x00 ,0x00 ,0x00 ,0x24 , 0xc4, 0xb6, 0x00, 0x3c, 0x36, 0x00, 0x07, 0xe2, 0xbf, 0x00,
@@ -44,7 +44,7 @@ static int stk1125_load_microcode(struct stk11xx *dev) };/* From 800x600 to 1280x1024 */ -const u8 values_2_204[] = { +static const u8 values_2_204[] = {0x12 ,0x11 ,0x3b ,0x6a ,0x13 ,0x10 ,0x00 ,0x01 ,0x02 ,0x13 ,0x39 ,0x38 ,0x37 ,0x35 ,0x0e ,0x12 ,0x04 ,0x0c ,0x0d ,0x17 ,0x18 ,0x32 ,0x19 ,0x1a ,0x03 ,0x1b ,0x16 ,0x33 ,0x34 ,0x41 ,
@@ -52,7 +52,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)0x95 ,0x40 ,0x29 ,0x0f ,0xa5 ,0x1e ,0xa9 ,0xaa ,0xab ,0x90 ,0x91 ,0x9f ,0xa0 ,0x24 ,0x25 ,0x26 ,0x14 ,0x2a ,0x2b }; -const u8 values_2_205[] = { +static const u8 values_2_205[] = {0x05 ,0x80 ,0x01 ,0x7d ,0x80 ,0x00 ,0x00 ,0x80 ,0x80 ,0x80 ,0x50 ,0x93 ,0x00 ,0x81 ,0x20 ,0x05 ,0x00 ,0x00 ,0x00 ,0x1b , 0xbb, 0xa4, 0x01, 0x81, 0x12, 0x00, 0x07, 0xe2, 0xbf, 0x00,
@@ -119,43 +119,43 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 */ -const u8 vals_001B[] = { +static const u8 vals_001B[] = {0x0e ,0x03 ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e ,0x0e }; -const u8 vals_001C[] = { +static const u8 vals_001C[] = {0x06 ,0x02 ,0x46 ,0x46 ,0x46 ,0x46 ,0x46 ,0x46 ,0x46 ,0x46 ,0x46 ,0x0e }; -const u8 vals_0202[] = { +static const u8 vals_0202[] = {0x1e ,0x0a ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e ,0x1e }; -const u8 vals_0110[] = { +static const u8 vals_0110[] = {0x07 ,0x00 ,0x00 ,0x00 ,0x00 ,0x3e ,0x3e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; -const u8 vals_0112[] = { +static const u8 vals_0112[] = {0x07 ,0x00 ,0x00 ,0x00 ,0x00 ,0x09 ,0x09 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; -const u8 vals_0114[] = { +static const u8 vals_0114[] = {0x87 ,0x80 ,0x80 ,0x80 ,0x80 ,0xbe ,0xbe ,0x80 ,0x80 ,0x80 ,0x80 ,0x00 }; -const u8 vals_0115[] = { +static const u8 vals_0115[] = {0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x02 ,0x05 }; -const u8 vals_0116[] = { +static const u8 vals_0116[] = {0xe7 ,0xe0 ,0xe0 ,0xe0 ,0xe0 ,0xe9 ,0xe9 ,0xe0 ,0xe0 ,0xe0 ,0xe0 ,0x00 }; -const u8 vals_0117[] = { +static const u8 vals_0117[] = {0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x04 }; -const u8 vals_0100[] = { +static const u8 vals_0100[] = {0x20 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 ,0x21 };
@@ -190,7 +190,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)switch (step) {case 0 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x40 ,2 }, {0x0204 ,0x41 ,2 }, {0x0205 ,0x01 ,2 }, {0x0204 ,0x1c ,2 }, { 0x0205, 0x02, 2 }, { 0x0200, 0x05, 2 }, { }
@@ -200,7 +200,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 1 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x22 ,2 }, {0x0204 ,0x27 ,2 }, {0x0205 ,0xa5 ,2 }, {0x0200 ,0x05 ,2 }, { } };
@@ -209,7 +209,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 2 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x60 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x13 ,2 }, {0x0205 ,0xbf ,2 }, {0x0200 ,0x05 ,2 }, { }
@@ -219,7 +219,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 3 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x42 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x24 ,2 }, {0x0205 ,0xa5 ,2 }, {0x0200 ,0x05 ,2 }, { }
@@ -229,7 +229,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 4 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x42 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x13 ,2 }, {0x0205 ,0xe0 ,2 }, {0x0204 ,0x24 ,2 },
@@ -240,7 +240,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 5 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x60 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x13 ,2 }, {0x0205 ,0xff ,2 }, {0x0200 ,0x05 ,2 }, { }
@@ -250,7 +250,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 6 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x60 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x13 ,2 }, {0x0205 ,0xff ,2 }, {0x0200 ,0x05 ,2 }, { }
@@ -260,7 +260,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)break ; }case 7 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0203 ,0x60 ,2 }, {0x0204 ,0x12 ,2 }, {0x0205 ,0x80 ,2 }, {0x0204 ,0x13 ,2 }, {0x0205 ,0xb7 ,2 }, {0x0200 ,0x05 ,2 }, { }
@@ -294,7 +294,7 @@ static int stk1125_dev_configure(struct stk11xx *dev, unsigned int step)case 10 :case 11 : { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0106 ,0x00 ,2 }, {0x02ff ,0x00 ,1 }, {0x02ff ,0x00 ,2 }, {0x0204 ,0x2a ,2 }, {0x0205 ,0x00 ,2 }, {0x0200 ,0x01 ,2 },
@@ -322,7 +322,7 @@ err:static int stk1125_cam_asleep (struct stk11xx *dev) { -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x0104 ,0x00 ,1 }, {0x0105 ,0x00 ,1 }, {0x0106 ,0x00 ,1 }, {0x0100 ,0x21 ,2 }, {0x0116 ,0x00 ,2 }, {0x0117 ,0x00 ,2 }, {0x0018 ,0x00 ,2 }, {0x0000 ,0x00 ,1 }, {0x0000 ,0x4c ,2 },
@@ -412,7 +412,7 @@ static int stk1125_cam_init(struct stk11xx *dev) {int ret; -const struct stk11xx_table table[] = { +static const struct stk11xx_table table[] = { {0x02ff ,0x00 ,1 }, {0x02ff ,0x00 ,2 }, {0x0204 ,0x2a ,2 }, {0x0205 ,0x00 ,2 }, {0x0200 ,0x01 ,2 }, {500 ,0x00 ,3 }, {0x02ff ,0x00 ,2 }, {0x02ff ,0x00 ,1 }, {0x02ff ,0x00 ,2 },
@@ -500,7 +500,7 @@ static int stk1125_dev_init(struct stk11xx *dev)int ret;u8 value; -const struct stk11xx_table table_1[] = { +static const struct stk11xx_table table_1[] = { {0x0000 ,0x24 ,2 }, {0x0002 ,0x68 ,2 }, {0x0003 ,0x80 ,2 }, {0x0002 ,0x6f ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x26 ,2 }, {0x0000 ,0x27 ,2 }, {0x0000 ,0x26 ,2 },
@@ -515,7 +515,7 @@ static int stk1125_dev_init(struct stk11xx *dev) { 0x0000, 0x24, 2 }, { } }; -const struct stk11xx_table table_2[] = { +static const struct stk11xx_table table_2[] = { {0x0000 ,0x25 ,2 }, {0x0000 ,0x20 ,2 }, {0x0002 ,0x6f ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x26 ,2 }, { 0x0000, 0x27, 2 }, { 0x0000, 0x26, 2 }, { 0x0000, 0x26, 2 },
@@ -531,7 +531,7 @@ static int stk1125_dev_init(struct stk11xx *dev) { 0x0000, 0x25, 2 }, { 0x0002, 0x6d, 2 }, { 0x0000, 0x24, 2 }, { } }; -const struct stk11xx_table table_3[] = { +static const struct stk11xx_table table_3[] = { {0x0000 ,0x25 ,2 }, {0x0000 ,0x20 ,2 }, {0x0002 ,0x6f ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x26 ,2 }, { 0x0000, 0x27, 2 }, { 0x0000, 0x26, 2 }, { 0x0000, 0x26, 2 },
@@ -549,7 +549,7 @@ static int stk1125_dev_init(struct stk11xx *dev) { 0x0000, 0x25, 2 }, { 0x0002, 0x6d, 2 }, { 0x0000, 0x24, 2 }, { } }; -const struct stk11xx_table table_4[] = { +static const struct stk11xx_table table_4[] = { {0x0000 ,0x25 ,2 }, {0x0000 ,0x20 ,2 }, {0x0002 ,0x6f ,2 }, {0x0000 ,0x24 ,2 }, {0x0000 ,0x20 ,2 }, {0x0117 ,0x00 ,2 }, { 0x0103, 0x00, 1 }, { 0x0103, 0x01, 2 }, { 0x0103, 0x00, 1 },
drivers/media/video/stk1135.c +27 -27
192 lines not on this page · raw message
drivers/media/video/stkdcnew.c +34 -34
242 lines not on this page · raw message
Re: [PATCH 3/3] V4L: stk11xx, add static to tables
Hi Jiri,
Quoted 6 lines · Jiri Slaby
stk11xx, add static to tables
ensure, that the compiler will put all the tables in static storage
drivers/media/video/stk1125.c static int stk1125_load_microcode(struct stk11xx *dev) · line 32
Quoted 8 lines
drivers/media/video/stk1125.c +1
-1@@ -26,7 +26,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)int retok;/* From 80x60 to 640x480 */ -const u8 values_1_204[] = { +static const u8 values_1_204[] = {0x12 ,0x11 ,0x3b ,0x6a ,0x13 ,0x10 ,0x00 ,0x01 ,0x02 ,0x13 ,0x39 ,0x38 ,0x37 ,0x35 ,0x0e ,0x12 ,0x04 ,0x0c ,0x0d ,0x17 ,0x18 ,0x32 ,0x19 ,0x1a ,0x03 ,0x1b ,0x16 ,0x33 ,0x34 ,0x41 ,
Probably I'm missing something (or am wrong/mistaken, in which case I hope somebody corrects me), but what do we get with this change?
I think having "static const" on data having function-local scope (as is the case with all occurrences in this patch) is often redundant/pointless thing to do. "static" on function-local data serves only to instruct the compiler to allocate storage in .data instead of stack -- .data because it lives for as long as the program will, and also because it is read-write. "const", OTOH will send it to the .rodata section anyway -- which has similar storage lifetime, with additional restriction that it is read-only and also allows the compiler to do all sorts of optimization tricks (because such data is known to remain constant during runtime as well). For "static const", .rodata is chosen over .data, neither of which is the function's stack, so effectively it's not any more beneficial than simple "const", and if anything might only confuse the compiler.
Note that having "static const" on _global_ (not function-local) data is still a useful thing to do -- "static" scopes it within the current file, and "const" throws it into the .rodata with all its other implications. But that is not the case with any of the cases in this particular patch.
The reason I ask is because I did something similar recently -- allocated an array of constant strings -- const char *stringarray[xxx] = {...}; inside a function, and am even fearlessly returning a pointer to one of those strings back to the caller(!) Things do work correctly as expected, but is there something subtle I missed?
Satyam
Re: [PATCH 3/3] V4L: stk11xx, add static to tables
In reply to Jiri SlabyQuoted 13 lines · On Tue, 28 Aug 2007 01:18:34 -0700 Jiri Slaby <[email protected]> wrote:
stk11xx, add static to tables
ensure, that the compiler will put all the tables in static storage
Signed-off-by Jiri Slaby <[email protected]>...
drivers/media/video/stk1125.c +0
-0
drivers/media/video/stk1125.c static int stk1125_load_microcode(struct stk11xx *dev) · line 31
Quoted 7 lines
drivers/media/video/stk1125.c +1
-1@@ -26,7 +26,7 @@ static int stk1125_load_microcode(struct stk11xx *dev)int retok;/* From 80x60 to 640x480 */ -const u8 values_1_204[] = { +static const u8 values_1_204[] = {0x12 ,0x11 ,0x3b ,0x6a ,0x13 ,0x10 ,0x00 ,0x01 ,0x02 ,0x13 ,0x39 ,0x38 ,0x37 ,0x35 ,0x0e ,0x12 ,0x04 ,0x0c ,0x0d ,0x17 ,
I think you'll find that the compiler is already putting this array into static storage. But yes, I think the change is useful for commentary and peace-of-mind reasons.