All of lore.kernel.org
 help / color / mirror / Atom feed
* Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
       [not found] <e11b8f5e-1b85-fe24-36d5-c8d707ce4e66@wp.pl>
@ 2020-09-01 12:06   ` antoni.przybylik
  0 siblings, 0 replies; 6+ messages in thread
From: antoni.przybylik @ 2020-09-01 12:06 UTC (permalink / raw)
  To: Greg KH, linux-kernel, devel

On 01.09.2020 13:08, Greg KH wrote:
> On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
>> Such macros are dangerous. Consider following example:
>> 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
>> 	GDM_TTY_READY(a + b)
>> This macro will be expanded in such a way:
>> 	(a + b && a + b->tty_dev && a + b->port.count)
>> And it will lead to errors.
> This is for a pointer, no one would ever do that :)

Nobody adds a pointer to a pointer, but it's common to add to it some 
value like that:

GDM_TTY_READY(myptr + 0x1000)

> But, if you really worry about this, turn it into an inline function,
> that way you get the proper typedef safety, which is what something like
> this should really be, not a macro.

How to do it? Do I need to send another patch?

Antoni Przybylik


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
@ 2020-09-01 12:06   ` antoni.przybylik
  0 siblings, 0 replies; 6+ messages in thread
From: antoni.przybylik @ 2020-09-01 12:06 UTC (permalink / raw)
  To: Greg KH, linux-kernel, devel

On 01.09.2020 13:08, Greg KH wrote:
> On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
>> Such macros are dangerous. Consider following example:
>> 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
>> 	GDM_TTY_READY(a + b)
>> This macro will be expanded in such a way:
>> 	(a + b && a + b->tty_dev && a + b->port.count)
>> And it will lead to errors.
> This is for a pointer, no one would ever do that :)

Nobody adds a pointer to a pointer, but it's common to add to it some 
value like that:

GDM_TTY_READY(myptr + 0x1000)

> But, if you really worry about this, turn it into an inline function,
> that way you get the proper typedef safety, which is what something like
> this should really be, not a macro.

How to do it? Do I need to send another patch?

Antoni Przybylik

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
  2020-09-01 12:06   ` antoni.przybylik
@ 2020-09-01 12:21     ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-09-01 12:21 UTC (permalink / raw)
  To: antoni.przybylik; +Cc: Greg KH, linux-kernel, devel

On Tue, Sep 01, 2020 at 02:06:23PM +0200, antoni.przybylik@wp.pl wrote:
> On 01.09.2020 13:08, Greg KH wrote:
> > On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
> > > Such macros are dangerous. Consider following example:
> > > 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > > 	GDM_TTY_READY(a + b)
> > > This macro will be expanded in such a way:
> > > 	(a + b && a + b->tty_dev && a + b->port.count)
> > > And it will lead to errors.
> > This is for a pointer, no one would ever do that :)
> 
> Nobody adds a pointer to a pointer, but it's common to add to it some value
> like that:
> 
> GDM_TTY_READY(myptr + 0x1000)

That won't compile at all, because it expands to "gdm + 0x1000->tty_dev".

> 
> > But, if you really worry about this, turn it into an inline function,
> > that way you get the proper typedef safety, which is what something like
> > this should really be, not a macro.
> 
> How to do it? Do I need to send another patch?

Yeah.  If you want.  Or you could just find something else to patch.
Probably just find a different bug and fix that instead...  If at first
you don't succeed, there are tons of other stuff to work on and maybe
you will succeed there.  ;)

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
@ 2020-09-01 12:21     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-09-01 12:21 UTC (permalink / raw)
  To: antoni.przybylik; +Cc: devel, Greg KH, linux-kernel

On Tue, Sep 01, 2020 at 02:06:23PM +0200, antoni.przybylik@wp.pl wrote:
> On 01.09.2020 13:08, Greg KH wrote:
> > On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
> > > Such macros are dangerous. Consider following example:
> > > 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > > 	GDM_TTY_READY(a + b)
> > > This macro will be expanded in such a way:
> > > 	(a + b && a + b->tty_dev && a + b->port.count)
> > > And it will lead to errors.
> > This is for a pointer, no one would ever do that :)
> 
> Nobody adds a pointer to a pointer, but it's common to add to it some value
> like that:
> 
> GDM_TTY_READY(myptr + 0x1000)

That won't compile at all, because it expands to "gdm + 0x1000->tty_dev".

> 
> > But, if you really worry about this, turn it into an inline function,
> > that way you get the proper typedef safety, which is what something like
> > this should really be, not a macro.
> 
> How to do it? Do I need to send another patch?

Yeah.  If you want.  Or you could just find something else to patch.
Probably just find a different bug and fix that instead...  If at first
you don't succeed, there are tons of other stuff to work on and maybe
you will succeed there.  ;)

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
  2020-09-01 12:06   ` antoni.przybylik
@ 2020-09-01 13:10     ` Greg KH
  -1 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2020-09-01 13:10 UTC (permalink / raw)
  To: antoni.przybylik; +Cc: linux-kernel, devel

On Tue, Sep 01, 2020 at 02:06:23PM +0200, antoni.przybylik@wp.pl wrote:
> On 01.09.2020 13:08, Greg KH wrote:
> > On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
> > > Such macros are dangerous. Consider following example:
> > > 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > > 	GDM_TTY_READY(a + b)
> > > This macro will be expanded in such a way:
> > > 	(a + b && a + b->tty_dev && a + b->port.count)
> > > And it will lead to errors.
> > This is for a pointer, no one would ever do that :)
> 
> Nobody adds a pointer to a pointer, but it's common to add to it some value
> like that:
> 
> GDM_TTY_READY(myptr + 0x1000)

In this driver?  And adding random numbers to a pointer should not be
common, when those pointers are structures, right?

> > But, if you really worry about this, turn it into an inline function,
> > that way you get the proper typedef safety, which is what something like
> > this should really be, not a macro.
> 
> How to do it? Do I need to send another patch?

If you wish to fix this up, please do, I can't take this as-is.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets
@ 2020-09-01 13:10     ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2020-09-01 13:10 UTC (permalink / raw)
  To: antoni.przybylik; +Cc: devel, linux-kernel

On Tue, Sep 01, 2020 at 02:06:23PM +0200, antoni.przybylik@wp.pl wrote:
> On 01.09.2020 13:08, Greg KH wrote:
> > On Tue, Sep 01, 2020 at 12:43:11PM +0200, antoniprzybylik wrote:
> > > Such macros are dangerous. Consider following example:
> > > 	#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > > 	GDM_TTY_READY(a + b)
> > > This macro will be expanded in such a way:
> > > 	(a + b && a + b->tty_dev && a + b->port.count)
> > > And it will lead to errors.
> > This is for a pointer, no one would ever do that :)
> 
> Nobody adds a pointer to a pointer, but it's common to add to it some value
> like that:
> 
> GDM_TTY_READY(myptr + 0x1000)

In this driver?  And adding random numbers to a pointer should not be
common, when those pointers are structures, right?

> > But, if you really worry about this, turn it into an inline function,
> > that way you get the proper typedef safety, which is what something like
> > this should really be, not a macro.
> 
> How to do it? Do I need to send another patch?

If you wish to fix this up, please do, I can't take this as-is.

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-01 13:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <e11b8f5e-1b85-fe24-36d5-c8d707ce4e66@wp.pl>
2020-09-01 12:06 ` Fwd: Re: [PATCH] staging: gdm724x: gdm_tty: corrected macro by adding brackets antoni.przybylik
2020-09-01 12:06   ` antoni.przybylik
2020-09-01 12:21   ` Dan Carpenter
2020-09-01 12:21     ` Dan Carpenter
2020-09-01 13:10   ` Greg KH
2020-09-01 13:10     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.