All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Convert macros to static inline functions
@ 2016-03-18 19:44 Bhaktipriya Shridhar
  2016-03-18 19:45 ` [PATCH 1/2] staging: comedi: drivers: amplc_pci224: " Bhaktipriya Shridhar
  2016-03-18 19:46 ` [PATCH 2/2] staging: comedi: drivers: amplc_pci230: " Bhaktipriya Shridhar
  0 siblings, 2 replies; 4+ messages in thread
From: Bhaktipriya Shridhar @ 2016-03-18 19:44 UTC (permalink / raw)
  To: outreachy-kernel

Convert macros CLK_CONFIG and GAT_CONFIG into static inline
functions as static inline functions are preferred over macros. This
change is possible since the arguments at all call sites have the same
type. Also, both the macros have same type of arguments and return
values. They have been renamed in lowecase.

Bhaktipriya Shridhar (2):
  staging: comedi: drivers: amplc_pci224: Convert macros to static
    inline functions
  staging: comedi: drivers: amplc_pci230: Convert macros to static
    inline functions

 drivers/staging/comedi/drivers/amplc_pci224.c | 16 ++++++-----
 drivers/staging/comedi/drivers/amplc_pci230.c | 38 +++++++++++++++------------
 2 files changed, 31 insertions(+), 23 deletions(-)

--
2.1.4



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

* [PATCH 1/2] staging: comedi: drivers: amplc_pci224: Convert macros to static inline functions
  2016-03-18 19:44 [PATCH 0/2] Convert macros to static inline functions Bhaktipriya Shridhar
@ 2016-03-18 19:45 ` Bhaktipriya Shridhar
  2016-03-18 19:46 ` [PATCH 2/2] staging: comedi: drivers: amplc_pci230: " Bhaktipriya Shridhar
  1 sibling, 0 replies; 4+ messages in thread
From: Bhaktipriya Shridhar @ 2016-03-18 19:45 UTC (permalink / raw)
  To: outreachy-kernel

Convert macros CLK_CONFIG and GAT_CONFIG into static inline
functions as static inline functions are preferred over macros. This
change is possible since the arguments at all call sites have the same
type. Also, both the macros have same type of arguments and return
values. They have been renamed in lowecase.

This was done using coccinelle:

@r@
identifier f;
expression e;
@@
- #define f(chan, src) e
+ static inline unsigned int f(unsigned int chan,unsigned int src)
+ {
+        return e;
+ }

@r1@
@@

-GAT_CONFIG
+gat_config

@r2@
@@
-CLK_CONFIG
+clk_config

Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index cac011f..21bc6b3 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -202,7 +202,9 @@
 #define CLK_OUTNM1	6	/* output of channel-1 modulo total */
 #define CLK_EXT		7	/* external clock */
 /* Macro to construct clock input configuration register value. */
-#define CLK_CONFIG(chan, src)	((((chan) & 3) << 3) | ((src) & 7))
+static inline unsigned int CLK_CONFIG(unsigned int chan, unsigned int src) {
+	return ((((chan) & 3) << 3) | ((src) & 7));
+}

 /*
  * Counter/timer gate input configuration sources.
@@ -212,7 +214,9 @@
 #define GAT_EXT		2	/* reserved (external gate input) */
 #define GAT_NOUTNM2	3	/* inverted output of channel-2 modulo total */
 /* Macro to construct gate input configuration register value. */
-#define GAT_CONFIG(chan, src)	((((chan) & 3) << 3) | ((src) & 7))
+static inline unsigned int GAT_CONFIG(unsigned int chan, unsigned int src) {
+	return ((((chan) & 3) << 3) | ((src) & 7));
+}

 /*
  * Summary of CLK_OUTNM1 and GAT_NOUTNM2 connections for PCI224 and PCI234:
@@ -812,14 +816,14 @@ static void pci224_ao_start_pacer(struct comedi_device *dev,
 	 * source.
 	 */
 	/* Make sure Z2-0 is gated on.  */
-	outb(GAT_CONFIG(0, GAT_VCC), devpriv->iobase1 + PCI224_ZGAT_SCE);
+	outb(gat_config(0, GAT_VCC), devpriv->iobase1 + PCI224_ZGAT_SCE);
 	/* Cascading with Z2-2. */
 	/* Make sure Z2-2 is gated on.  */
-	outb(GAT_CONFIG(2, GAT_VCC), devpriv->iobase1 + PCI224_ZGAT_SCE);
+	outb(gat_config(2, GAT_VCC), devpriv->iobase1 + PCI224_ZGAT_SCE);
 	/* Z2-2 needs 10 MHz clock. */
-	outb(CLK_CONFIG(2, CLK_10MHZ), devpriv->iobase1 + PCI224_ZCLK_SCE);
+	outb(clk_config(2, CLK_10MHZ), devpriv->iobase1 + PCI224_ZCLK_SCE);
 	/* Z2-0 is clocked from Z2-2's output. */
-	outb(CLK_CONFIG(0, CLK_OUTNM1), devpriv->iobase1 + PCI224_ZCLK_SCE);
+	outb(clk_config(0, CLK_OUTNM1), devpriv->iobase1 + PCI224_ZCLK_SCE);

 	comedi_8254_pacer_enable(dev->pacer, 2, 0, false);
 }
--
2.1.4



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

* [PATCH 2/2] staging: comedi: drivers: amplc_pci230: Convert macros to static inline functions
  2016-03-18 19:44 [PATCH 0/2] Convert macros to static inline functions Bhaktipriya Shridhar
  2016-03-18 19:45 ` [PATCH 1/2] staging: comedi: drivers: amplc_pci224: " Bhaktipriya Shridhar
@ 2016-03-18 19:46 ` Bhaktipriya Shridhar
  2016-03-18 20:13   ` [Outreachy kernel] " Arnd Bergmann
  1 sibling, 1 reply; 4+ messages in thread
From: Bhaktipriya Shridhar @ 2016-03-18 19:46 UTC (permalink / raw)
  To: outreachy-kernel

Convert macros CLK_CONFIG and GAT_CONFIG into static inline
functions as static inline functions are preferred over macros. This
change is possible since the arguments at all call sites have the same
type. Also, both the macros have same type of arguments and return
values. They have been renamed in lowecase.

This was done using coccinelle:

@r@
identifier f;
expression e;
@@
- #define f(chan, src) e
+ static inline unsigned int f(unsigned int chan,unsigned int src)
+ {
+        return e;
+ }

@r1@
@@

-GAT_CONFIG
+gat_config

@r2@
@@
-CLK_CONFIG
+clk_config

Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
---
 drivers/staging/comedi/drivers/amplc_pci230.c | 38 +++++++++++++++------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 907c39c..051787e 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -370,7 +370,9 @@
 #define CLK_OUTNM1	6	/* output of channel-1 modulo total */
 #define CLK_EXT		7	/* external clock */
 /* Macro to construct clock input configuration register value. */
-#define CLK_CONFIG(chan, src)	((((chan) & 3) << 3) | ((src) & 7))
+static inline unsigned int CLK_CONFIG(unsigned int chan, unsigned int src) {
+	return ((((chan) & 3) << 3) | ((src) & 7));
+}

 /*
  * Counter/timer gate input configuration sources.
@@ -380,7 +382,9 @@
 #define GAT_EXT		2	/* external gate input (PPCn on PCI230) */
 #define GAT_NOUTNM2	3	/* inverted output of channel-2 modulo total */
 /* Macro to construct gate input configuration register value. */
-#define GAT_CONFIG(chan, src)	((((chan) & 3) << 3) | ((src) & 7))
+static inline unsigned int GAT_CONFIG(unsigned int chan, unsigned int src) {
+	return ((((chan) & 3) << 3) | ((src) & 7));
+}

 /*
  * Summary of CLK_OUTNM1 and GAT_NOUTNM2 connections for PCI230 and PCI260:
@@ -687,7 +691,7 @@ static void pci230_ct_setup_ns_mode(struct comedi_device *dev, unsigned int ct,
 	/* Determine clock source and count. */
 	clk_src = pci230_choose_clk_count(ns, &count, flags);
 	/* Program clock source. */
-	outb(CLK_CONFIG(ct, clk_src), dev->iobase + PCI230_ZCLK_SCE);
+	outb(clk_config(ct, clk_src), dev->iobase + PCI230_ZCLK_SCE);
 	/* Set initial count. */
 	if (count >= 65536)
 		count = 0;
@@ -1263,7 +1267,7 @@ static void pci230_ao_start(struct comedi_device *dev,
 					       irqflags);
 		}
 		/* Set CT1 gate high to start counting. */
-		outb(GAT_CONFIG(1, GAT_VCC), dev->iobase + PCI230_ZGAT_SCE);
+		outb(gat_config(1, GAT_VCC), dev->iobase + PCI230_ZGAT_SCE);
 		break;
 	case TRIG_INT:
 		async->inttrig = pci230_ao_inttrig_scan_begin;
@@ -1351,7 +1355,7 @@ static int pci230_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 		 * cmd->scan_begin_arg is sampling period in ns.
 		 * Gate it off for now.
 		 */
-		outb(GAT_CONFIG(1, GAT_GND), dev->iobase + PCI230_ZGAT_SCE);
+		outb(gat_config(1, GAT_GND), dev->iobase + PCI230_ZGAT_SCE);
 		pci230_ct_setup_ns_mode(dev, 1, I8254_MODE3,
 					cmd->scan_begin_arg,
 					cmd->flags);
@@ -1792,9 +1796,9 @@ static int pci230_ai_inttrig_scan_begin(struct comedi_device *dev,
 	spin_lock_irqsave(&devpriv->ai_stop_spinlock, irqflags);
 	if (devpriv->ai_cmd_started) {
 		/* Trigger scan by waggling CT0 gate source. */
-		zgat = GAT_CONFIG(0, GAT_GND);
+		zgat = gat_config(0, GAT_GND);
 		outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
-		zgat = GAT_CONFIG(0, GAT_VCC);
+		zgat = gat_config(0, GAT_VCC);
 		outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 	}
 	spin_unlock_irqrestore(&devpriv->ai_stop_spinlock, irqflags);
@@ -1926,20 +1930,20 @@ static void pci230_ai_start(struct comedi_device *dev,
 			 * Conversion timer CT2 needs to be gated by
 			 * inverted output of monostable CT2.
 			 */
-			zgat = GAT_CONFIG(2, GAT_NOUTNM2);
+			zgat = gat_config(2, GAT_NOUTNM2);
 		} else {
 			/*
 			 * Conversion timer CT2 needs to be gated on
 			 * continuously.
 			 */
-			zgat = GAT_CONFIG(2, GAT_VCC);
+			zgat = gat_config(2, GAT_VCC);
 		}
 		outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 		if (cmd->scan_begin_src != TRIG_FOLLOW) {
 			/* Set monostable CT0 trigger source. */
 			switch (cmd->scan_begin_src) {
 			default:
-				zgat = GAT_CONFIG(0, GAT_VCC);
+				zgat = gat_config(0, GAT_VCC);
 				break;
 			case TRIG_EXT:
 				/*
@@ -1950,21 +1954,21 @@ static void pci230_ai_start(struct comedi_device *dev,
 				 * input in order to use it as an external scan
 				 * trigger.
 				 */
-				zgat = GAT_CONFIG(0, GAT_EXT);
+				zgat = gat_config(0, GAT_EXT);
 				break;
 			case TRIG_TIMER:
 				/*
 				 * Monostable CT0 triggered by rising edge on
 				 * inverted output of CT1 (falling edge on CT1).
 				 */
-				zgat = GAT_CONFIG(0, GAT_NOUTNM2);
+				zgat = gat_config(0, GAT_NOUTNM2);
 				break;
 			case TRIG_INT:
 				/*
 				 * Monostable CT0 is triggered by inttrig
 				 * function waggling the CT0 gate source.
 				 */
-				zgat = GAT_CONFIG(0, GAT_VCC);
+				zgat = gat_config(0, GAT_VCC);
 				break;
 			}
 			outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
@@ -1974,7 +1978,7 @@ static void pci230_ai_start(struct comedi_device *dev,
 				 * Scan period timer CT1 needs to be
 				 * gated on to start counting.
 				 */
-				zgat = GAT_CONFIG(1, GAT_VCC);
+				zgat = gat_config(1, GAT_VCC);
 				outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 				break;
 			case TRIG_INT:
@@ -2216,7 +2220,7 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 		 * Note, counter/timer output 2 can be monitored on the
 		 * connector: PCI230 pin 21, PCI260 pin 18.
 		 */
-		zgat = GAT_CONFIG(2, GAT_GND);
+		zgat = gat_config(2, GAT_GND);
 		outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 		/* Set counter/timer 2 to the specified conversion period. */
 		pci230_ct_setup_ns_mode(dev, 2, I8254_MODE3, cmd->convert_arg,
@@ -2234,7 +2238,7 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 			 * monostable to stop it triggering.  The trigger
 			 * source will be changed later.
 			 */
-			zgat = GAT_CONFIG(0, GAT_VCC);
+			zgat = gat_config(0, GAT_VCC);
 			outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 			pci230_ct_setup_ns_mode(dev, 0, I8254_MODE1,
 						((uint64_t)cmd->convert_arg *
@@ -2247,7 +2251,7 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 				 *
 				 * Set up CT1 but gate it off for now.
 				 */
-				zgat = GAT_CONFIG(1, GAT_GND);
+				zgat = gat_config(1, GAT_GND);
 				outb(zgat, dev->iobase + PCI230_ZGAT_SCE);
 				pci230_ct_setup_ns_mode(dev, 1, I8254_MODE3,
 							cmd->scan_begin_arg,
--
2.1.4



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

* Re: [Outreachy kernel] [PATCH 2/2] staging: comedi: drivers: amplc_pci230: Convert macros to static inline functions
  2016-03-18 19:46 ` [PATCH 2/2] staging: comedi: drivers: amplc_pci230: " Bhaktipriya Shridhar
@ 2016-03-18 20:13   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-03-18 20:13 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhaktipriya Shridhar

On Saturday 19 March 2016 01:16:32 Bhaktipriya Shridhar wrote:
> 
> diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
> index 907c39c..051787e 100644
> --- a/drivers/staging/comedi/drivers/amplc_pci230.c
> +++ b/drivers/staging/comedi/drivers/amplc_pci230.c
> @@ -370,7 +370,9 @@
>  #define CLK_OUTNM1	6	/* output of channel-1 modulo total */
>  #define CLK_EXT		7	/* external clock */
>  /* Macro to construct clock input configuration register value. */
> -#define CLK_CONFIG(chan, src)	((((chan) & 3) << 3) | ((src) & 7))
> +static inline unsigned int CLK_CONFIG(unsigned int chan, unsigned int src) {
> +	return ((((chan) & 3) << 3) | ((src) & 7));
> +}

We often use macros for cases like this, as this really just puts some bits
in a particular position.

With the conversion above, you should remove the extra () around the arguments.

>  /*
> @@ -687,7 +691,7 @@ static void pci230_ct_setup_ns_mode(struct comedi_device *dev, unsigned int ct,
>  	/* Determine clock source and count. */
>  	clk_src = pci230_choose_clk_count(ns, &count, flags);
>  	/* Program clock source. */
> -	outb(CLK_CONFIG(ct, clk_src), dev->iobase + PCI230_ZCLK_SCE);
> +	outb(clk_config(ct, clk_src), dev->iobase + PCI230_ZCLK_SCE);
>  	/* Set initial count. */
>  	if (count >= 65536)
>  		count = 0;

This won't work: you have changed the user from uppercase to lowercase, but not
the definition. The change is ok, but you have to do it consistently.

It looks like you did not build-test this correctly, otherwise you would have
run into the problem.

I also see that every single user of this macro passes the argument into
the outb() function, with (dev->iobase + ...) as the address. I would
suggest merging the two calls into one when you convert it, and do

static inline void pci230_clk_config(struct comedi_device *dev, unsigned int reg,
				      unsigned int chan, unsigned int src)
{
	outb(((chan & 3) << 3) | (src & 7), dev->iobase + reg);
}

which lets the caller above get simplified to

	pci230_clk_config(dev, PCI230_ZCLK_SCE, ct, clk_src);

	Arnd


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

end of thread, other threads:[~2016-03-18 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 19:44 [PATCH 0/2] Convert macros to static inline functions Bhaktipriya Shridhar
2016-03-18 19:45 ` [PATCH 1/2] staging: comedi: drivers: amplc_pci224: " Bhaktipriya Shridhar
2016-03-18 19:46 ` [PATCH 2/2] staging: comedi: drivers: amplc_pci230: " Bhaktipriya Shridhar
2016-03-18 20:13   ` [Outreachy kernel] " Arnd Bergmann

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.