From: Arnd Bergmann <arnd@arndb.de>
To: outreachy-kernel@googlegroups.com
Cc: Bhaktipriya Shridhar <bhaktipriya96@gmail.com>
Subject: Re: [Outreachy kernel] [PATCH 2/2] staging: comedi: drivers: amplc_pci230: Convert macros to static inline functions
Date: Fri, 18 Mar 2016 21:13:04 +0100 [thread overview]
Message-ID: <5409630.80pkvU6136@wuerfel> (raw)
In-Reply-To: <1e269638fb21f156d5f9d2c6af2a6551bb50a2c3.1458330202.git.bhaktipriya96@gmail.com>
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
prev parent reply other threads:[~2016-03-18 20:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Arnd Bergmann [this message]
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=5409630.80pkvU6136@wuerfel \
--to=arnd@arndb.de \
--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.