* [patch] tgafb: potential NULL dereference in init
@ 2013-08-26 14:56 Dan Carpenter
2013-08-26 17:51 ` Geert Uytterhoeven
2013-08-27 1:16 ` Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-08-26 14:56 UTC (permalink / raw)
To: linux-fbdev
Static checkers complain that there are paths where "tga_type_name" can
be NULL. I've re-arranged the code slightly so that's impossible.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index c9c8e5a..2dcaf2e 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -1475,7 +1475,7 @@ tgafb_init_fix(struct fb_info *info)
int tga_bus_pci = TGA_BUS_PCI(par->dev);
int tga_bus_tc = TGA_BUS_TC(par->dev);
u8 tga_type = par->tga_type;
- const char *tga_type_name = NULL;
+ const char *tga_type_name;
switch (tga_type) {
case TGA_TYPE_8PLANE:
@@ -1496,10 +1496,9 @@ tgafb_init_fix(struct fb_info *info)
if (tga_bus_tc)
tga_type_name = "Digital ZLX-E3";
break;
- default:
- tga_type_name = "Unknown";
- break;
}
+ if (!tga_type_name)
+ tga_type_name = "Unknown";
strlcpy(info->fix.id, tga_type_name, sizeof(info->fix.id));
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch] tgafb: potential NULL dereference in init
2013-08-26 14:56 [patch] tgafb: potential NULL dereference in init Dan Carpenter
@ 2013-08-26 17:51 ` Geert Uytterhoeven
2013-08-27 1:16 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2013-08-26 17:51 UTC (permalink / raw)
To: linux-fbdev
On Mon, Aug 26, 2013 at 4:56 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> --- a/drivers/video/tgafb.c
> +++ b/drivers/video/tgafb.c
> @@ -1475,7 +1475,7 @@ tgafb_init_fix(struct fb_info *info)
> int tga_bus_pci = TGA_BUS_PCI(par->dev);
> int tga_bus_tc = TGA_BUS_TC(par->dev);
> u8 tga_type = par->tga_type;
> - const char *tga_type_name = NULL;
> + const char *tga_type_name;
Now the real compiler (at least some versions of gcc) will complain
about an uninitialized variable...
> switch (tga_type) {
> case TGA_TYPE_8PLANE:
> @@ -1496,10 +1496,9 @@ tgafb_init_fix(struct fb_info *info)
> if (tga_bus_tc)
> tga_type_name = "Digital ZLX-E3";
> break;
> - default:
> - tga_type_name = "Unknown";
> - break;
> }
> + if (!tga_type_name)
It will only by NULL if the garbage on the stack was NULL...
> + tga_type_name = "Unknown";
>
> strlcpy(info->fix.id, tga_type_name, sizeof(info->fix.id));
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] tgafb: potential NULL dereference in init
2013-08-26 14:56 [patch] tgafb: potential NULL dereference in init Dan Carpenter
2013-08-26 17:51 ` Geert Uytterhoeven
@ 2013-08-27 1:16 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-08-27 1:16 UTC (permalink / raw)
To: linux-fbdev
On Mon, Aug 26, 2013 at 07:51:04PM +0200, Geert Uytterhoeven wrote:
> On Mon, Aug 26, 2013 at 4:56 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > --- a/drivers/video/tgafb.c
> > +++ b/drivers/video/tgafb.c
> > @@ -1475,7 +1475,7 @@ tgafb_init_fix(struct fb_info *info)
> > int tga_bus_pci = TGA_BUS_PCI(par->dev);
> > int tga_bus_tc = TGA_BUS_TC(par->dev);
> > u8 tga_type = par->tga_type;
> > - const char *tga_type_name = NULL;
> > + const char *tga_type_name;
>
> Now the real compiler (at least some versions of gcc) will complain
> about an uninitialized variable...
Oh crap! The compiler is totally correct here. I don't know what I was
thinking. I've just double checked now and my compiler does not catch
this (GCC 4.7.2).
Sorry about that.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-27 1:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-26 14:56 [patch] tgafb: potential NULL dereference in init Dan Carpenter
2013-08-26 17:51 ` Geert Uytterhoeven
2013-08-27 1:16 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox