From: walter harms <wharms@bfs.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-pwm@vger.kernel.org, kernel-janitors@vger.kernel.org,
Thierry Reding <thierry.reding@gmail.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
kernel@pengutronix.de, Colin King <colin.king@canonical.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] pwm: sun4i: Narrow scope of local variable
Date: Thu, 05 Dec 2019 09:37:55 +0100 [thread overview]
Message-ID: <5DE8C1E3.4080204@bfs.de> (raw)
In-Reply-To: <20191205072404.6858-1-u.kleine-koenig@pengutronix.de>
Am 05.12.2019 08:24, schrieb Uwe Kleine-König:
> The variable pval is only used in a single block in the function
> sun4i_pwm_calculate(). So declare it in a more local scope to simplify
> the function for humans and compilers.
>
> While the diffstat for this patch is negative for this patch I still
> thing the advantage of having a narrower scope is beneficial.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Hello,
>
> for the patch that became
>
> 1b98ad3b3be9 ("pwm: sun4i: Drop redundant assignment to variable pval")
>
> (and which yielded the situation that pval is only used in this single
> block) I suggested to do this change. This was ignored however by both
> Colin and Thierry without comment. So I suggest the change here
> separately.
>
> Best regards
> Uwe
>
> drivers/pwm/pwm-sun4i.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 581d23287333..8919e6ab7577 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -149,7 +149,7 @@ static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm,
> u32 *dty, u32 *prd, unsigned int *prsclr)
> {
> u64 clk_rate, div = 0;
> - unsigned int pval, prescaler = 0;
> + unsigned int prescaler = 0;
>
> clk_rate = clk_get_rate(sun4i_pwm->clk);
>
> @@ -170,6 +170,8 @@ static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm,
> if (prescaler == 0) {
> /* Go up from the first divider */
> for (prescaler = 0; prescaler < PWM_PRESCAL_MASK; prescaler++) {
> + unsigned int pval;
> +
> if (!prescaler_table[prescaler])
> continue;
> pval = prescaler_table[prescaler];
nit picking:
Doing the assignment first would remove the only use
of prescaler_table[prescaler].
unsigned int pval = prescaler_table[prescaler];
if ( ! pval )
continue;
if you feel adventures you could also replace the for() for a while()
since we know that prescaler == 0.
while ( prescaler < PWM_PRESCAL_MASK )
{
unsigned int pval = prescaler_table[prescaler++];
....
jm2c,
wh
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-12-05 8:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-02 10:08 [PATCH] pwm: sun4i: redundant assignment to variable pval Colin King
2019-10-02 10:16 ` Uwe Kleine-König
2019-12-05 7:24 ` [PATCH] pwm: sun4i: Narrow scope of local variable Uwe Kleine-König
2019-12-05 8:37 ` walter harms [this message]
2019-12-10 10:12 ` Uwe Kleine-König
2019-12-10 10:24 ` [PATCH v2] " Uwe Kleine-König
2019-10-02 10:39 ` [PATCH] pwm: sun4i: redundant assignment to variable pval Thierry Reding
2019-10-02 13:25 ` Dan Carpenter
2019-10-02 13:28 ` Colin Ian King
2019-10-02 13:29 ` Dan Carpenter
2019-10-02 13:30 ` Colin Ian King
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=5DE8C1E3.4080204@bfs.de \
--to=wharms@bfs.de \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pwm@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).