All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Colin King <colin.king@canonical.com>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: linux-pwm@vger.kernel.org,
	Dan Carpenter <dan.carpenter@oracle.com>,
	kernel-janitors@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de
Subject: [PATCH] pwm: sun4i: Narrow scope of local variable
Date: Thu, 05 Dec 2019 07:24:04 +0000	[thread overview]
Message-ID: <20191205072404.6858-1-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20191002101624.gljyf7g4nia2rcbx@pengutronix.de>

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];
-- 
2.24.0

WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Colin King <colin.king@canonical.com>,
	Thierry Reding <thierry.reding@gmail.com>
Cc: linux-pwm@vger.kernel.org,
	Dan Carpenter <dan.carpenter@oracle.com>,
	kernel-janitors@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de
Subject: [PATCH] pwm: sun4i: Narrow scope of local variable
Date: Thu,  5 Dec 2019 08:24:04 +0100	[thread overview]
Message-ID: <20191205072404.6858-1-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20191002101624.gljyf7g4nia2rcbx@pengutronix.de>

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];
-- 
2.24.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-05  7:24 UTC|newest]

Thread overview: 34+ 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:08 ` Colin King
2019-10-02 10:08 ` Colin King
2019-10-02 10:16 ` Uwe Kleine-König
2019-10-02 10:16   ` Uwe Kleine-König
2019-10-02 10:16   ` Uwe Kleine-König
2019-12-05  7:24   ` Uwe Kleine-König [this message]
2019-12-05  7:24     ` [PATCH] pwm: sun4i: Narrow scope of local variable Uwe Kleine-König
2019-12-05  8:37     ` walter harms
2019-12-05  8:37       ` walter harms
2019-12-10 10:12       ` Uwe Kleine-König
2019-12-10 10:12         ` Uwe Kleine-König
2019-12-10 10:12         ` Uwe Kleine-König
2019-12-10 10:24         ` [PATCH v2] " Uwe Kleine-König
2019-12-10 10:24           ` Uwe Kleine-König
2019-10-02 10:39 ` [PATCH] pwm: sun4i: redundant assignment to variable pval Thierry Reding
2019-10-02 10:39   ` Thierry Reding
2019-10-02 10:39   ` Thierry Reding
2019-10-02 13:25 ` Dan Carpenter
2019-10-02 13:25   ` Dan Carpenter
2019-10-02 13:25   ` Dan Carpenter
2019-10-02 13:25   ` Dan Carpenter
2019-10-02 13:28   ` Colin Ian King
2019-10-02 13:28     ` Colin Ian King
2019-10-02 13:28     ` Colin Ian King
2019-10-02 13:28     ` Colin Ian King
2019-10-02 13:29   ` Dan Carpenter
2019-10-02 13:29     ` Dan Carpenter
2019-10-02 13:29     ` Dan Carpenter
2019-10-02 13:29     ` Dan Carpenter
2019-10-02 13:30     ` Colin Ian King
2019-10-02 13:30       ` Colin Ian King
2019-10-02 13:30       ` Colin Ian King
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=20191205072404.6858-1-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.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 \
    /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.