All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NTB: Fix macro parameter conflict with field name
@ 2016-01-21 17:53 Allen Hubbe
  2016-01-21 22:58 ` Jiang, Dave
  0 siblings, 1 reply; 3+ messages in thread
From: Allen Hubbe @ 2016-01-21 17:53 UTC (permalink / raw)
  To: linux-ntb, Jon Mason; +Cc: Allen Hubbe

If the parameter given to the macro is replaced throughout the macro as
it is evaluated.  The intent is that the macro parameter should replace
the only the first parameter to container_of().  However, the way the
macro was written, it would also inadvertantly replace a structure field
name.  If a parameter of any other name is given to the macro, it will
fail to compile, if the structure does not contain a field of the same
name.  At worst, it will compile, and hide improper access of an
unintended field in the structure.

Change the macro parameter name, so it does not conflict with the
structure field name.

Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com>
---
 drivers/ntb/hw/intel/ntb_hw_intel.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.h b/drivers/ntb/hw/intel/ntb_hw_intel.h
index 2eb4addd10d0..43b3fe0d4aed 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.h
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.h
@@ -334,7 +334,8 @@ struct intel_ntb_dev {
 #define ndev_pdev(ndev) ((ndev)->ntb.pdev)
 #define ndev_name(ndev) pci_name(ndev_pdev(ndev))
 #define ndev_dev(ndev) (&ndev_pdev(ndev)->dev)
-#define ntb_ndev(ntb) container_of(ntb, struct intel_ntb_dev, ntb)
-#define hb_ndev(work) container_of(work, struct intel_ntb_dev, hb_timer.work)
+#define ntb_ndev(__ntb) container_of(__ntb, struct intel_ntb_dev, ntb)
+#define hb_ndev(__work) container_of(__work, struct intel_ntb_dev, \
+				     hb_timer.work)
 
 #endif
-- 
2.7.0


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

* Re: [PATCH] NTB: Fix macro parameter conflict with field name
  2016-01-21 17:53 [PATCH] NTB: Fix macro parameter conflict with field name Allen Hubbe
@ 2016-01-21 22:58 ` Jiang, Dave
  2016-01-22  0:53   ` Jon Mason
  0 siblings, 1 reply; 3+ messages in thread
From: Jiang, Dave @ 2016-01-21 22:58 UTC (permalink / raw)
  To: Allen.Hubbe@emc.com, jdmason@kudzu.us, linux-ntb@googlegroups.com

On Thu, 2016-01-21 at 12:53 -0500, Allen Hubbe wrote:
> If the parameter given to the macro is replaced throughout the macro
> as
> it is evaluated.  The intent is that the macro parameter should
> replace
> the only the first parameter to container_of().  However, the way the
> macro was written, it would also inadvertantly replace a structure
> field
> name.  If a parameter of any other name is given to the macro, it
> will
> fail to compile, if the structure does not contain a field of the
> same
> name.  At worst, it will compile, and hide improper access of an
> unintended field in the structure.
> 
> Change the macro parameter name, so it does not conflict with the
> structure field name.
> 
> Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com>
Acked-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/ntb/hw/intel/ntb_hw_intel.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.h
> b/drivers/ntb/hw/intel/ntb_hw_intel.h
> index 2eb4addd10d0..43b3fe0d4aed 100644
> --- a/drivers/ntb/hw/intel/ntb_hw_intel.h
> +++ b/drivers/ntb/hw/intel/ntb_hw_intel.h
> @@ -334,7 +334,8 @@ struct intel_ntb_dev {
>  #define ndev_pdev(ndev) ((ndev)->ntb.pdev)
>  #define ndev_name(ndev) pci_name(ndev_pdev(ndev))
>  #define ndev_dev(ndev) (&ndev_pdev(ndev)->dev)
> -#define ntb_ndev(ntb) container_of(ntb, struct intel_ntb_dev, ntb)
> -#define hb_ndev(work) container_of(work, struct intel_ntb_dev,
> hb_timer.work)
> +#define ntb_ndev(__ntb) container_of(__ntb, struct intel_ntb_dev,
> ntb)
> +#define hb_ndev(__work) container_of(__work, struct intel_ntb_dev, \
> +				     hb_timer.work)
>  
>  #endif
> -- 
> 2.7.0
> 

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

* Re: [PATCH] NTB: Fix macro parameter conflict with field name
  2016-01-21 22:58 ` Jiang, Dave
@ 2016-01-22  0:53   ` Jon Mason
  0 siblings, 0 replies; 3+ messages in thread
From: Jon Mason @ 2016-01-22  0:53 UTC (permalink / raw)
  To: Jiang, Dave; +Cc: Allen.Hubbe@emc.com, linux-ntb@googlegroups.com

On Thu, Jan 21, 2016 at 10:58:07PM +0000, Jiang, Dave wrote:
> On Thu, 2016-01-21 at 12:53 -0500, Allen Hubbe wrote:
> > If the parameter given to the macro is replaced throughout the macro
> > as
> > it is evaluated.��The intent is that the macro parameter should
> > replace
> > the only the first parameter to container_of().��However, the way the
> > macro was written, it would also inadvertantly replace a structure
> > field
> > name.��If a parameter of any other name is given to the macro, it
> > will
> > fail to compile, if the structure does not contain a field of the
> > same
> > name.��At worst, it will compile, and hide improper access of an
> > unintended field in the structure.
> > 
> > Change the macro parameter name, so it does not conflict with the
> > structure field name.
> > 
> > Signed-off-by: Allen Hubbe <Allen.Hubbe@emc.com>
> Acked-by: Dave Jiang <dave.jiang@intel.com>

Included in the NTB git tree.

Thanks,
Jon

> 
> > ---
> > �drivers/ntb/hw/intel/ntb_hw_intel.h | 5 +++--
> > �1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.h
> > b/drivers/ntb/hw/intel/ntb_hw_intel.h
> > index 2eb4addd10d0..43b3fe0d4aed 100644
> > --- a/drivers/ntb/hw/intel/ntb_hw_intel.h
> > +++ b/drivers/ntb/hw/intel/ntb_hw_intel.h
> > @@ -334,7 +334,8 @@ struct intel_ntb_dev {
> > �#define ndev_pdev(ndev) ((ndev)->ntb.pdev)
> > �#define ndev_name(ndev) pci_name(ndev_pdev(ndev))
> > �#define ndev_dev(ndev) (&ndev_pdev(ndev)->dev)
> > -#define ntb_ndev(ntb) container_of(ntb, struct intel_ntb_dev, ntb)
> > -#define hb_ndev(work) container_of(work, struct intel_ntb_dev,
> > hb_timer.work)
> > +#define ntb_ndev(__ntb) container_of(__ntb, struct intel_ntb_dev,
> > ntb)
> > +#define hb_ndev(__work) container_of(__work, struct intel_ntb_dev, \
> > +				�����hb_timer.work)
> > �
> > �#endif
> > --�
> > 2.7.0
> > 

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

end of thread, other threads:[~2016-01-22  0:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-21 17:53 [PATCH] NTB: Fix macro parameter conflict with field name Allen Hubbe
2016-01-21 22:58 ` Jiang, Dave
2016-01-22  0:53   ` Jon Mason

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.