diff mbox

[v2,08/15] DMA: shdma: move two macros to a header

Message ID 1374251374-30186-9-git-send-email-g.liakhovetski@gmx.de (mailing list archive)
State Superseded
Headers show

Commit Message

Guennadi Liakhovetski July 19, 2013, 4:29 p.m. UTC
Move two generic pointer-conversion macros to a header for common shdma use.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
---
 drivers/dma/sh/shdma-base.c |    3 ---
 drivers/dma/sh/shdma-of.c   |    2 --
 include/linux/shdma-base.h  |    3 +++
 3 files changed, 3 insertions(+), 5 deletions(-)

Comments

Laurent Pinchart July 21, 2013, 10:16 p.m. UTC | #1
Hi Guennadi,

Thanks for the patch.

On Friday 19 July 2013 18:29:33 Guennadi Liakhovetski wrote:
> Move two generic pointer-conversion macros to a header for common shdma use.
> 
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> ---
>  drivers/dma/sh/shdma-base.c |    3 ---
>  drivers/dma/sh/shdma-of.c   |    2 --
>  include/linux/shdma-base.h  |    3 +++
>  3 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
> index c5ea256..5b92e72 100644
> --- a/drivers/dma/sh/shdma-base.c
> +++ b/drivers/dma/sh/shdma-base.c
> @@ -36,9 +36,6 @@ enum shdma_desc_status {
> 
>  #define NR_DESCS_PER_CHANNEL 32
> 
> -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> -#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> -
>  /*
>   * For slave DMA we assume, that there is a finite number of DMA slaves in
> the * system, and that each such slave can only use a finite number of
> channels. diff --git a/drivers/dma/sh/shdma-of.c
> b/drivers/dma/sh/shdma-of.c index 2acf7b6..80d07b5 100644
> --- a/drivers/dma/sh/shdma-of.c
> +++ b/drivers/dma/sh/shdma-of.c
> @@ -17,8 +17,6 @@
>  #include <linux/platform_device.h>
>  #include <linux/shdma-base.h>
> 
> -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> -
>  static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
>  				       struct of_dma *ofdma)
>  {
> diff --git a/include/linux/shdma-base.h b/include/linux/shdma-base.h
> index 31cf89f..45191d7 100644
> --- a/include/linux/shdma-base.h
> +++ b/include/linux/shdma-base.h
> @@ -114,6 +114,9 @@ struct shdma_dev {
>  #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
>  				i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
> 
> +#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> +#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> +

While you're at it, it might be a good idea to turn the macros into static 
inline functions. This would help catching type errors at compilation time.

>  int shdma_request_irq(struct shdma_chan *, int,
>  			   unsigned long, const char *);
>  bool shdma_reset(struct shdma_dev *sdev);
Guennadi Liakhovetski July 22, 2013, 6:40 a.m. UTC | #2
Hi Laurent

On Mon, 22 Jul 2013, Laurent Pinchart wrote:

> Hi Guennadi,
> 
> Thanks for the patch.
> 
> On Friday 19 July 2013 18:29:33 Guennadi Liakhovetski wrote:
> > Move two generic pointer-conversion macros to a header for common shdma use.
> > 
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> > ---
> >  drivers/dma/sh/shdma-base.c |    3 ---
> >  drivers/dma/sh/shdma-of.c   |    2 --
> >  include/linux/shdma-base.h  |    3 +++
> >  3 files changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
> > index c5ea256..5b92e72 100644
> > --- a/drivers/dma/sh/shdma-base.c
> > +++ b/drivers/dma/sh/shdma-base.c
> > @@ -36,9 +36,6 @@ enum shdma_desc_status {
> > 
> >  #define NR_DESCS_PER_CHANNEL 32
> > 
> > -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > -#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> > -
> >  /*
> >   * For slave DMA we assume, that there is a finite number of DMA slaves in
> > the * system, and that each such slave can only use a finite number of
> > channels. diff --git a/drivers/dma/sh/shdma-of.c
> > b/drivers/dma/sh/shdma-of.c index 2acf7b6..80d07b5 100644
> > --- a/drivers/dma/sh/shdma-of.c
> > +++ b/drivers/dma/sh/shdma-of.c
> > @@ -17,8 +17,6 @@
> >  #include <linux/platform_device.h>
> >  #include <linux/shdma-base.h>
> > 
> > -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > -
> >  static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
> >  				       struct of_dma *ofdma)
> >  {
> > diff --git a/include/linux/shdma-base.h b/include/linux/shdma-base.h
> > index 31cf89f..45191d7 100644
> > --- a/include/linux/shdma-base.h
> > +++ b/include/linux/shdma-base.h
> > @@ -114,6 +114,9 @@ struct shdma_dev {
> >  #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
> >  				i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
> > 
> > +#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > +#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> > +
> 
> While you're at it, it might be a good idea to turn the macros into static 
> inline functions. This would help catching type errors at compilation time.

Doesn't container_of() already catch all the possible type mismatches in 
this case? E.g. to_shdma_chan() can only work for arguments of the same 
type as the .dma_chan member of struct shdma_chan. Similar for 
to_shdma_dev().

Thanks
Guennadi

> >  int shdma_request_irq(struct shdma_chan *, int,
> >  			   unsigned long, const char *);
> >  bool shdma_reset(struct shdma_dev *sdev);
> 
> -- 
> Regards,
> 
> Laurent Pinchart
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart July 22, 2013, 11:30 p.m. UTC | #3
Hi Guennadi,

On Monday 22 July 2013 08:40:42 Guennadi Liakhovetski wrote:
> On Mon, 22 Jul 2013, Laurent Pinchart wrote:
> > On Friday 19 July 2013 18:29:33 Guennadi Liakhovetski wrote:
> > > Move two generic pointer-conversion macros to a header for common shdma
> > > use.
> > > 
> > > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
> > > ---
> > > 
> > >  drivers/dma/sh/shdma-base.c |    3 ---
> > >  drivers/dma/sh/shdma-of.c   |    2 --
> > >  include/linux/shdma-base.h  |    3 +++
> > >  3 files changed, 3 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
> > > index c5ea256..5b92e72 100644
> > > --- a/drivers/dma/sh/shdma-base.c
> > > +++ b/drivers/dma/sh/shdma-base.c
> > > @@ -36,9 +36,6 @@ enum shdma_desc_status {
> > > 
> > >  #define NR_DESCS_PER_CHANNEL 32
> > > 
> > > -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > > -#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> > > -
> > > 
> > >  /*
> > >  
> > >   * For slave DMA we assume, that there is a finite number of DMA slaves
> > >   in
> > > 
> > > the * system, and that each such slave can only use a finite number of
> > > channels. diff --git a/drivers/dma/sh/shdma-of.c
> > > b/drivers/dma/sh/shdma-of.c index 2acf7b6..80d07b5 100644
> > > --- a/drivers/dma/sh/shdma-of.c
> > > +++ b/drivers/dma/sh/shdma-of.c
> > > @@ -17,8 +17,6 @@
> > > 
> > >  #include <linux/platform_device.h>
> > >  #include <linux/shdma-base.h>
> > > 
> > > -#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > > -
> > > 
> > >  static struct dma_chan *shdma_of_xlate(struct of_phandle_args
> > >  *dma_spec,
> > >  
> > >  				       struct of_dma *ofdma)
> > >  
> > >  {
> > > 
> > > diff --git a/include/linux/shdma-base.h b/include/linux/shdma-base.h
> > > index 31cf89f..45191d7 100644
> > > --- a/include/linux/shdma-base.h
> > > +++ b/include/linux/shdma-base.h
> > > @@ -114,6 +114,9 @@ struct shdma_dev {
> > > 
> > >  #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
> > >  
> > >  				i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
> > > 
> > > +#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
> > > +#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
> > > +
> > 
> > While you're at it, it might be a good idea to turn the macros into static
> > inline functions. This would help catching type errors at compilation
> > time.
> 
> Doesn't container_of() already catch all the possible type mismatches in
> this case? E.g. to_shdma_chan() can only work for arguments of the same
> type as the .dma_chan member of struct shdma_chan. Similar for
> to_shdma_dev().

Hmmm... You're right. I recall that a static inline would bring additional 
safety compared to directly using container_of() but I can't recall why. Never 
mind then.

> > >  int shdma_request_irq(struct shdma_chan *, int,
> > >  
> > >  			   unsigned long, const char *);
> > >  
> > >  bool shdma_reset(struct shdma_dev *sdev);
diff mbox

Patch

diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
index c5ea256..5b92e72 100644
--- a/drivers/dma/sh/shdma-base.c
+++ b/drivers/dma/sh/shdma-base.c
@@ -36,9 +36,6 @@  enum shdma_desc_status {
 
 #define NR_DESCS_PER_CHANNEL 32
 
-#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
-#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
-
 /*
  * For slave DMA we assume, that there is a finite number of DMA slaves in the
  * system, and that each such slave can only use a finite number of channels.
diff --git a/drivers/dma/sh/shdma-of.c b/drivers/dma/sh/shdma-of.c
index 2acf7b6..80d07b5 100644
--- a/drivers/dma/sh/shdma-of.c
+++ b/drivers/dma/sh/shdma-of.c
@@ -17,8 +17,6 @@ 
 #include <linux/platform_device.h>
 #include <linux/shdma-base.h>
 
-#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
-
 static struct dma_chan *shdma_of_xlate(struct of_phandle_args *dma_spec,
 				       struct of_dma *ofdma)
 {
diff --git a/include/linux/shdma-base.h b/include/linux/shdma-base.h
index 31cf89f..45191d7 100644
--- a/include/linux/shdma-base.h
+++ b/include/linux/shdma-base.h
@@ -114,6 +114,9 @@  struct shdma_dev {
 #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \
 				i < (d)->dma_dev.chancnt; c = (d)->schan[++i])
 
+#define to_shdma_chan(c) container_of(c, struct shdma_chan, dma_chan)
+#define to_shdma_dev(d) container_of(d, struct shdma_dev, dma_dev)
+
 int shdma_request_irq(struct shdma_chan *, int,
 			   unsigned long, const char *);
 bool shdma_reset(struct shdma_dev *sdev);