* [PATCH] davinci: dm355: Fix uninitialized variable compiler warnings
@ 2013-01-02 11:53 Lad, Prabhakar
2013-01-02 11:53 ` [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning Lad, Prabhakar
0 siblings, 1 reply; 4+ messages in thread
From: Lad, Prabhakar @ 2013-01-02 11:53 UTC (permalink / raw)
To: LMML; +Cc: LKML, Mauro Carvalho Chehab, DLOS, Lad, Prabhakar
drivers/media/platform/davinci/dm355_ccdc.c:593:9: warning: ‘val1’ may be
used uninitialized in this function [-Wuninitialized]
drivers/media/platform/davinci/dm355_ccdc.c:560:6: note: ‘val1’ was declared here
This is a false positive but the compiler has no way to know about it,
so initialize the variable to 0.
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
---
drivers/media/platform/davinci/dm355_ccdc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/media/platform/davinci/dm355_ccdc.c b/drivers/media/platform/davinci/dm355_ccdc.c
index ce0e413..3c28aaa 100644
--- a/drivers/media/platform/davinci/dm355_ccdc.c
+++ b/drivers/media/platform/davinci/dm355_ccdc.c
@@ -557,7 +557,7 @@ static int ccdc_config_vdfc(struct ccdc_vertical_dft *dfc)
*/
static void ccdc_config_csc(struct ccdc_csc *csc)
{
- u32 val1, val2;
+ u32 val1 = 0, val2;
int i;
if (!csc->enable)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning
2013-01-02 11:53 [PATCH] davinci: dm355: Fix uninitialized variable compiler warnings Lad, Prabhakar
@ 2013-01-02 11:53 ` Lad, Prabhakar
2013-02-05 16:24 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 4+ messages in thread
From: Lad, Prabhakar @ 2013-01-02 11:53 UTC (permalink / raw)
To: LMML; +Cc: LKML, Mauro Carvalho Chehab, DLOS, Lad, Prabhakar
while the effect is harmless this patch fixes following build warning,
drivers/media/platform/davinci/dm644x_ccdc.c: In function ‘validate_ccdc_param’:
drivers/media/platform/davinci/dm644x_ccdc.c:233:32: warning: comparison between
‘enum ccdc_gama_width’ and ‘enum ccdc_data_size’ [-Wenum-compare]
Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
---
drivers/media/platform/davinci/dm644x_ccdc.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/drivers/media/platform/davinci/dm644x_ccdc.c b/drivers/media/platform/davinci/dm644x_ccdc.c
index ee7942b..42b473a 100644
--- a/drivers/media/platform/davinci/dm644x_ccdc.c
+++ b/drivers/media/platform/davinci/dm644x_ccdc.c
@@ -228,9 +228,12 @@ static void ccdc_readregs(void)
static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
{
if (ccdcparam->alaw.enable) {
+ u32 gama_wd = ccdcparam->alaw.gama_wd;
+ u32 data_sz = ccdcparam->data_sz;
+
if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) ||
(ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) ||
- (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) {
+ (gama_wd < data_sz)) {
dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
return -1;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning
2013-01-02 11:53 ` [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning Lad, Prabhakar
@ 2013-02-05 16:24 ` Mauro Carvalho Chehab
2013-02-05 17:18 ` Prabhakar Lad
0 siblings, 1 reply; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2013-02-05 16:24 UTC (permalink / raw)
To: Lad, Prabhakar; +Cc: LMML, LKML, DLOS, Lad, Prabhakar
Em Wed, 2 Jan 2013 17:23:50 +0530
"Lad, Prabhakar" <prabhakar.csengg@gmail.com> escreveu:
> while the effect is harmless this patch
I disagree that this is a harmless warning. It is here for a reason:
you should not be relying on the enum "magic" value, since the main
reason to use an enum is to fill/compare the enum fields only by their
names, and not by their number.
> fixes following build warning,
>
> drivers/media/platform/davinci/dm644x_ccdc.c: In function ‘validate_ccdc_param’:
> drivers/media/platform/davinci/dm644x_ccdc.c:233:32: warning: comparison between
> ‘enum ccdc_gama_width’ and ‘enum ccdc_data_size’ [-Wenum-compare]
>
> Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
> ---
> drivers/media/platform/davinci/dm644x_ccdc.c | 5 ++++-
> 1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/media/platform/davinci/dm644x_ccdc.c b/drivers/media/platform/davinci/dm644x_ccdc.c
> index ee7942b..42b473a 100644
> --- a/drivers/media/platform/davinci/dm644x_ccdc.c
> +++ b/drivers/media/platform/davinci/dm644x_ccdc.c
> @@ -228,9 +228,12 @@ static void ccdc_readregs(void)
> static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
> {
> if (ccdcparam->alaw.enable) {
> + u32 gama_wd = ccdcparam->alaw.gama_wd;
> + u32 data_sz = ccdcparam->data_sz;
> +
> if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) ||
> (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) ||
> - (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) {
> + (gama_wd < data_sz)) {
hmm... from include/media/davinci/dm644x_ccdc.h:
enum ccdc_gama_width {
CCDC_GAMMA_BITS_15_6, // 0
CCDC_GAMMA_BITS_14_5, // 1
CCDC_GAMMA_BITS_13_4, // 2
CCDC_GAMMA_BITS_12_3, // 3
CCDC_GAMMA_BITS_11_2, // 4
CCDC_GAMMA_BITS_10_1, // 5
CCDC_GAMMA_BITS_09_0 // 6
};
enum ccdc_data_size {
CCDC_DATA_16BITS, // 0
CCDC_DATA_15BITS, // 1
CCDC_DATA_14BITS, // 2
CCDC_DATA_13BITS, // 3
CCDC_DATA_12BITS, // 4
CCDC_DATA_11BITS, // 5
CCDC_DATA_10BITS, // 6
CCDC_DATA_8BITS // 7
};
That doesn't seem right, as comparing the enum integer value won't
warrant that the number of bits of gamma. For example, gamma == 6
means 9 bits, while ccdc == 6 means 10 bits.
In any case, the code is just crappy, as one could anytime add more
values at the enum or reorder.
So, a better fix would be to have an array that would convert from the
enum "magic" number into the number of bits.
Hmm... wait a moment: why are you using an enum here at the first place???
It seems that it would be a way better to just use 2 unsigned integers:
ccdc_data_num_bits and ccdc_gama_num_bits, and just fill it with the
number of bits, instead of declaring an enum for it.
Another alternative would be to merge them into just one enum, like:
enum ccdc_bits {
CCDC_8_BITS = 8,
CCDC_9_BITS = 9,
CCDC_10_BITS = 10,
CCDC_11_BITS = 11,
CCDC_12_BITS = 12,
CCDC_13_BITS = 13,
CCDC_14_BITS = 14,
CCDC_15_BITS = 15,
CCDC_16_BITS = 16,
};
and replace all occurrences of ccdc_data_size and ccdc_gama_width by
the new enum.
This way, you could trust on compare one field with the other.
> dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
> return -1;
> }
Regards,
Mauro
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning
2013-02-05 16:24 ` Mauro Carvalho Chehab
@ 2013-02-05 17:18 ` Prabhakar Lad
0 siblings, 0 replies; 4+ messages in thread
From: Prabhakar Lad @ 2013-02-05 17:18 UTC (permalink / raw)
To: Mauro Carvalho Chehab; +Cc: LMML, LKML, DLOS, Lad, Prabhakar
Hi Mauro,
On Tue, Feb 5, 2013 at 9:54 PM, Mauro Carvalho Chehab
<mchehab@infradead.org> wrote:
> Em Wed, 2 Jan 2013 17:23:50 +0530
> "Lad, Prabhakar" <prabhakar.csengg@gmail.com> escreveu:
>
>> while the effect is harmless this patch
>
> I disagree that this is a harmless warning. It is here for a reason:
> you should not be relying on the enum "magic" value, since the main
> reason to use an enum is to fill/compare the enum fields only by their
> names, and not by their number.
>
OK
>> fixes following build warning,
>>
>> drivers/media/platform/davinci/dm644x_ccdc.c: In function ‘validate_ccdc_param’:
>> drivers/media/platform/davinci/dm644x_ccdc.c:233:32: warning: comparison between
>> ‘enum ccdc_gama_width’ and ‘enum ccdc_data_size’ [-Wenum-compare]
>>
>> Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com>
>> ---
>> drivers/media/platform/davinci/dm644x_ccdc.c | 5 ++++-
>> 1 files changed, 4 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/media/platform/davinci/dm644x_ccdc.c b/drivers/media/platform/davinci/dm644x_ccdc.c
>> index ee7942b..42b473a 100644
>> --- a/drivers/media/platform/davinci/dm644x_ccdc.c
>> +++ b/drivers/media/platform/davinci/dm644x_ccdc.c
>> @@ -228,9 +228,12 @@ static void ccdc_readregs(void)
>> static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
>> {
>> if (ccdcparam->alaw.enable) {
>> + u32 gama_wd = ccdcparam->alaw.gama_wd;
>> + u32 data_sz = ccdcparam->data_sz;
>> +
>> if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) ||
>> (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) ||
>> - (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) {
>> + (gama_wd < data_sz)) {
>
> hmm... from include/media/davinci/dm644x_ccdc.h:
> enum ccdc_gama_width {
> CCDC_GAMMA_BITS_15_6, // 0
> CCDC_GAMMA_BITS_14_5, // 1
> CCDC_GAMMA_BITS_13_4, // 2
> CCDC_GAMMA_BITS_12_3, // 3
> CCDC_GAMMA_BITS_11_2, // 4
> CCDC_GAMMA_BITS_10_1, // 5
> CCDC_GAMMA_BITS_09_0 // 6
> };
>
> enum ccdc_data_size {
> CCDC_DATA_16BITS, // 0
> CCDC_DATA_15BITS, // 1
> CCDC_DATA_14BITS, // 2
> CCDC_DATA_13BITS, // 3
> CCDC_DATA_12BITS, // 4
> CCDC_DATA_11BITS, // 5
> CCDC_DATA_10BITS, // 6
> CCDC_DATA_8BITS // 7
> };
>
> That doesn't seem right, as comparing the enum integer value won't
> warrant that the number of bits of gamma. For example, gamma == 6
> means 9 bits, while ccdc == 6 means 10 bits.
>
> In any case, the code is just crappy, as one could anytime add more
> values at the enum or reorder.
>
yes
> So, a better fix would be to have an array that would convert from the
> enum "magic" number into the number of bits.
>
> Hmm... wait a moment: why are you using an enum here at the first place???
>
> It seems that it would be a way better to just use 2 unsigned integers:
> ccdc_data_num_bits and ccdc_gama_num_bits, and just fill it with the
> number of bits, instead of declaring an enum for it.
>
I will pick this option :)
Regards,
--Prabhakar
> Another alternative would be to merge them into just one enum, like:
>
> enum ccdc_bits {
> CCDC_8_BITS = 8,
> CCDC_9_BITS = 9,
> CCDC_10_BITS = 10,
> CCDC_11_BITS = 11,
> CCDC_12_BITS = 12,
> CCDC_13_BITS = 13,
> CCDC_14_BITS = 14,
> CCDC_15_BITS = 15,
> CCDC_16_BITS = 16,
> };
>
> and replace all occurrences of ccdc_data_size and ccdc_gama_width by
> the new enum.
>
> This way, you could trust on compare one field with the other.
>
>> dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
>> return -1;
>> }
>
> Regards,
> Mauro
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-02-05 17:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-02 11:53 [PATCH] davinci: dm355: Fix uninitialized variable compiler warnings Lad, Prabhakar
2013-01-02 11:53 ` [PATCH] davinci: dm644x: fix enum ccdc_gama_width and enum ccdc_data_size comparision warning Lad, Prabhakar
2013-02-05 16:24 ` Mauro Carvalho Chehab
2013-02-05 17:18 ` Prabhakar Lad
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).