Re: [PATCH 057/144] usb: musb: gadget: prevent a NULL pointer dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 9 Jan 2011, Sergei Shtylyov wrote:

> > static struct field *get_field(void)
> > {
> > 	struct my_mod	*mod = NULL;
> >
> > 	return &mod->f;
> 
>     That's another case: offset of 'f' is not 0, unlike the offset of 'request'.

What happens if somebody in the future adds another member to the 
musb_request structure in front of the .request member?

Felipe's change is simply good programming practice (although the patch 
description could be improved).

> > Now, if change the check:
> 
> > --- t.c.orig	2011-01-09 19:06:31.581642000 +0200
> > +++ t.c	2011-01-09 19:05:41.733642000 +0200
> > @@ -26,7 +26,7 @@ static int __init mod_init(void)
> >   {
> >   	struct field	*f = get_field();
> >
> > -	if (f == NULL)
> > +	if (f)
> >   		pr_info("===>  f (%p) is NULL\n", f);
> >   	else
> >   		pr_info("===>  f (%p) is not NULL\n", f);
> 
> > Everything the pointer is considered NULL:
> 
> > $ dmesg
> > [1385484.405684] ===>  f (0000000c) is NULL
> 
>     Hm, interesting...

Not as interesting as it may appear.  The test is backward, so the fact
that the program printed out "is NULL" means the computer thinks f
really is not NULL.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux