From: Greg KH <gregkh@linuxfoundation.org>
To: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH v2 1/4] staging: comedi: amplc_pci230: Convert macro CLK_CONFIG to static inline function
Date: Mon, 21 Mar 2016 18:04:49 -0400 [thread overview]
Message-ID: <20160321220449.GD5091@kroah.com> (raw)
In-Reply-To: <89df043b193021a979cffa87472398640097fc9e.1458500647.git.bhaktipriya96@gmail.com>
On Mon, Mar 21, 2016 at 12:41:27AM +0530, Bhaktipriya Shridhar wrote:
> Convert macro CLK_CONFIG to static inline function as static inline
> functions are preferred over macros. Since every single user of this
> macro passes the argument into the outb() function, with
> (dev->iobase + ...) as the address, the two calls have been merged
> into one.
>
> This was done using Coccinelle:
>
> @r@
> identifier f;
> expression e;
> @@
> - #define CLK_CONFIG(chan, src) e
> + 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);
> +}
>
> @r1@
> expression dev,reg,chan,src;
> @@
> -outb(CLK_CONFIG(chan, src), dev->iobase + reg);
> +pci230_clk_config(dev, reg, chan, src);
>
> Also, the comment describing the macro has been removed manually.
>
> Signed-off-by: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
> ---
> Changes in v2:
> - Since every single usage of this macro passes the argument into
> the outb() function, with (dev->iobase + ...) as the address,
> the two calls have been merged into one.
>
> drivers/staging/comedi/drivers/amplc_pci230.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
> index 907c39c..635cd46 100644
> --- a/drivers/staging/comedi/drivers/amplc_pci230.c
> +++ b/drivers/staging/comedi/drivers/amplc_pci230.c
> @@ -369,8 +369,12 @@
> #define CLK_1KHZ 5 /* internal 1 kHz clock */
> #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 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);
> +}
>
> /*
> * Counter/timer gate input configuration sources.
> @@ -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);
> + pci230_clk_config(dev, PCI230_ZCLK_SCE, ct, clk_src);
This is only done in one place, just "open code" it, no need for a
separate function at all here.
Actually, the original code is nicer, it makes more sense, and a macro
is just fine, no need to change it.
thanks,
greg k-h
next prev parent reply other threads:[~2016-03-21 22:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-20 19:07 [PATCH v2 0/4] Convert macros to static inline functions Bhaktipriya Shridhar
2016-03-20 19:11 ` [PATCH v2 1/4] staging: comedi: amplc_pci230: Convert macro CLK_CONFIG to static inline function Bhaktipriya Shridhar
2016-03-21 22:04 ` Greg KH [this message]
2016-03-20 19:15 ` [PATCH v2 2/4] staging: comedi: amplc_pci224: " Bhaktipriya Shridhar
2016-03-21 22:04 ` [Outreachy kernel] " Greg KH
2016-03-20 19:16 ` [PATCH v2 3/4] staging: comedi: amplc_pci224: Convert macro GAT_CONFIG " Bhaktipriya Shridhar
2016-03-21 22:04 ` [Outreachy kernel] " Greg KH
2016-03-20 19:20 ` [PATCH v2 4/4] staging: comedi: amplc_pci230: " Bhaktipriya Shridhar
2016-03-21 22:04 ` [Outreachy kernel] " Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160321220449.GD5091@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=bhaktipriya96@gmail.com \
--cc=outreachy-kernel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.