* [patch] edac: sb_edac: add sanity check to silence static checker
@ 2011-11-01 6:28 Dan Carpenter
2011-11-01 12:32 ` walter harms
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2011-11-01 6:28 UTC (permalink / raw)
To: Mauro Carvalho Chehab; +Cc: Mark A. Grondona, linux-kernel, kernel-janitors
I assume the the check on if (limit <= prv) prevents n_tads from
actually reaching MAX_TAD. The problem with that is that it relies
on the hardware returning the right value and Smatch complains that
if it doesn't we could have a buffer overflow.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Feel free to ignore this patch if you want. I don't have very stong
feelings about this either way.
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index 7a402bf..ebf386c 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -970,6 +970,12 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
break;
prv = limit;
}
+ if (n_tads == MAX_TAD) {
+ sprintf(msg, "Could not discover the memory channel");
+ edac_mc_handle_ce_no_info(mci, msg);
+ return -EINVAL;
+ }
+
ch_way = TAD_CH(reg) + 1;
sck_way = TAD_SOCK(reg) + 1;
/*
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [patch] edac: sb_edac: add sanity check to silence static checker
2011-11-01 6:28 [patch] edac: sb_edac: add sanity check to silence static checker Dan Carpenter
@ 2011-11-01 12:32 ` walter harms
2011-11-01 12:53 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 4+ messages in thread
From: walter harms @ 2011-11-01 12:32 UTC (permalink / raw)
To: Dan Carpenter
Cc: Mauro Carvalho Chehab, Mark A. Grondona, linux-kernel,
kernel-janitors
Am 01.11.2011 07:28, schrieb Dan Carpenter:
> I assume the the check on if (limit <= prv) prevents n_tads from
> actually reaching MAX_TAD. The problem with that is that it relies
> on the hardware returning the right value and Smatch complains that
> if it doesn't we could have a buffer overflow.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Feel free to ignore this patch if you want. I don't have very stong
> feelings about this either way.
>
> diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
> index 7a402bf..ebf386c 100644
> --- a/drivers/edac/sb_edac.c
> +++ b/drivers/edac/sb_edac.c
> @@ -970,6 +970,12 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
> break;
> prv = limit;
> }
> + if (n_tads == MAX_TAD) {
> + sprintf(msg, "Could not discover the memory channel");
why the sprintf() ? can you not simply:
edac_mc_handle_ce_no_info(mci,"Could not discover the memory channel");
re,
wh
> + edac_mc_handle_ce_no_info(mci, msg);
> + return -EINVAL;
> + }
> +
> ch_way = TAD_CH(reg) + 1;
> sck_way = TAD_SOCK(reg) + 1;
> /*
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] edac: sb_edac: add sanity check to silence static checker
2011-11-01 12:32 ` walter harms
@ 2011-11-01 12:53 ` Mauro Carvalho Chehab
2011-11-01 13:59 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2011-11-01 12:53 UTC (permalink / raw)
To: wharms; +Cc: Dan Carpenter, Mark A. Grondona, linux-kernel, kernel-janitors
Em 01-11-2011 10:32, walter harms escreveu:
>
>
> Am 01.11.2011 07:28, schrieb Dan Carpenter:
>> I assume the the check on if (limit <= prv) prevents n_tads from
>> actually reaching MAX_TAD. The problem with that is that it relies
>> on the hardware returning the right value and Smatch complains that
>> if it doesn't we could have a buffer overflow.
>>
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>> ---
>> Feel free to ignore this patch if you want. I don't have very stong
>> feelings about this either way.
>>
>> diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
>> index 7a402bf..ebf386c 100644
>> --- a/drivers/edac/sb_edac.c
>> +++ b/drivers/edac/sb_edac.c
>> @@ -970,6 +970,12 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
>> break;
>> prv = limit;
>> }
>> + if (n_tads == MAX_TAD) {
>> + sprintf(msg, "Could not discover the memory channel");
>
> why the sprintf() ? can you not simply:
> edac_mc_handle_ce_no_info(mci,"Could not discover the memory channel");
Yes, please us the edac-specific call. I'm working on some patches that will
provide an additional functionality to those edac report calls. So, using
sprintf() won't do the right thing after applying those patches (likely for
Kernel v3.3).
>
> re,
> wh
>> + edac_mc_handle_ce_no_info(mci, msg);
>> + return -EINVAL;
>> + }
>> +
>> ch_way = TAD_CH(reg) + 1;
>> sck_way = TAD_SOCK(reg) + 1;
>> /*
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] edac: sb_edac: add sanity check to silence static checker
2011-11-01 12:53 ` Mauro Carvalho Chehab
@ 2011-11-01 13:59 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2011-11-01 13:59 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: wharms, Mark A. Grondona, linux-kernel, kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]
On Tue, Nov 01, 2011 at 10:53:18AM -0200, Mauro Carvalho Chehab wrote:
> >> --- a/drivers/edac/sb_edac.c
> >> +++ b/drivers/edac/sb_edac.c
> >> @@ -970,6 +970,12 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
> >> break;
> >> prv = limit;
> >> }
> >> + if (n_tads == MAX_TAD) {
> >> + sprintf(msg, "Could not discover the memory channel");
> >
> > why the sprintf() ? can you not simply:
> > edac_mc_handle_ce_no_info(mci,"Could not discover the memory channel");
>
> Yes, please us the edac-specific call. I'm working on some patches that will
> provide an additional functionality to those edac report calls. So, using
> sprintf() won't do the right thing after applying those patches (likely for
> Kernel v3.3).
>
I did use the edac-specific call. Walter is saying that the
sprintf() is not needed because I could just pass the string
directly. That's true enough, but I'd prefer to leave it how I wrote
it so it matches everything else in this file. Also passing it
directly as edac_mc_handle_ce_no_info(mci,"Could not discover the memory channel");
makes the line too long for the 80 character limit so someone will
complain if I do that. This isn't a fast path so the sprintf()
doesn't hurt anything.
Also looking at it now, I suspect this patch might be a bug fix
instead of just to silence the warning. We have a similar check for
the MAX_SAD loop earlier to the check that I added here for MAX_TAD.
regards,
dan carpenter
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-01 13:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-01 6:28 [patch] edac: sb_edac: add sanity check to silence static checker Dan Carpenter
2011-11-01 12:32 ` walter harms
2011-11-01 12:53 ` Mauro Carvalho Chehab
2011-11-01 13:59 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox