From: Greg KH <gregkh@linuxfoundation.org>
To: Madhumitha Prabakaran <madhumithabiw@gmail.com>
Cc: sudipm.mukherjee@gmail.com, teddy.wang@siliconmotion.com,
outreachy-kernel@googlegroups.com
Subject: Re: [PATCH] Staging: sm750fb: Remove unnecessary local variables
Date: Tue, 12 Mar 2019 15:03:20 -0700 [thread overview]
Message-ID: <20190312220320.GA17305@kroah.com> (raw)
In-Reply-To: <20190312215737.29200-1-madhumithabiw@gmail.com>
On Tue, Mar 12, 2019 at 04:57:37PM -0500, Madhumitha Prabakaran wrote:
> Remove unnecessary local variables in function get_mxclk_freq.
> Issue found by Coccinelle using ret.cocci.
>
> Signed-off-by: Madhumitha Prabakaran <madhumithabiw@gmail.com>
> ---
> drivers/staging/sm750fb/ddk750_chip.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/sm750fb/ddk750_chip.c b/drivers/staging/sm750fb/ddk750_chip.c
> index 90f5480304f4..d0462f21fe36 100644
> --- a/drivers/staging/sm750fb/ddk750_chip.c
> +++ b/drivers/staging/sm750fb/ddk750_chip.c
> @@ -33,19 +33,16 @@ void sm750_set_chip_type(unsigned short dev_id, u8 rev_id)
>
> static unsigned int get_mxclk_freq(void)
> {
> - unsigned int pll_reg;
> - unsigned int M, N, OD, POD;
> -
> if (sm750_get_chip_type() == SM750LE)
> return MHz(130);
>
> - pll_reg = peek32(MXCLK_PLL_CTRL);
> - M = (pll_reg & PLL_CTRL_M_MASK) >> PLL_CTRL_M_SHIFT;
> - N = (pll_reg & PLL_CTRL_N_MASK) >> PLL_CTRL_N_SHIFT;
> - OD = (pll_reg & PLL_CTRL_OD_MASK) >> PLL_CTRL_OD_SHIFT;
> - POD = (pll_reg & PLL_CTRL_POD_MASK) >> PLL_CTRL_POD_SHIFT;
> -
> - return DEFAULT_INPUT_CLOCK * M / N / (1 << OD) / (1 << POD);
> + return DEFAULT_INPUT_CLOCK * (peek32(MXCLK_PLL_CTRL) &
> + PLL_CTRL_M_MASK) >> PLL_CTRL_M_SHIFT /
> + (peek32(MXCLK_PLL_CTRL) & PLL_CTRL_N_MASK) >>
> + PLL_CTRL_N_SHIFT / (1 << (peek32(MXCLK_PLL_CTRL) &
> + PLL_CTRL_OD_MASK) >> PLL_CTRL_OD_SHIFT) / (1 <<
> + (peek32(MXCLK_PLL_CTRL) & PLL_CTRL_POD_MASK) >>
> + PLL_CTRL_POD_SHIFT);
Oh wow, that's almost impossible to now read.
Sometimes you want intermediate variables for the programmer, not for
the compiler. The end result is the same, but please tell me that you
could figure out what that one single return line actually does :(
Remember, we write C code for people to understand first, and the CPU to
understand second as we have to maintain it for the future.
thanks,
greg k-h
next prev parent reply other threads:[~2019-03-12 22:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-12 21:57 [PATCH] Staging: sm750fb: Remove unnecessary local variables Madhumitha Prabakaran
2019-03-12 22:03 ` Greg KH [this message]
2019-03-12 22:08 ` [Outreachy kernel] " Greg KH
2019-03-12 22:26 ` Madhumthia Prabakaran
2019-03-12 22:09 ` [Outreachy kernel] " Julia Lawall
2019-03-12 22:23 ` Madhumthia Prabakaran
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=20190312220320.GA17305@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=madhumithabiw@gmail.com \
--cc=outreachy-kernel@googlegroups.com \
--cc=sudipm.mukherjee@gmail.com \
--cc=teddy.wang@siliconmotion.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.