All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Six <mario.six@gdsys.cc>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 11/19] spi: mpc8xxx: Reduce scope of loop variables
Date: Tue, 10 Apr 2018 13:01:40 +0200	[thread overview]
Message-ID: <01507368b4be8c17ce415753058f133085eb4b31.1523355172.git.mario.six@gdsys.cc> (raw)
In-Reply-To: <cover.1523355172.git.mario.six@gdsys.cc>

The transmission loop starts with setting some variables, which are only
used inside the loop. Reduce the scope to the loop to make the
declaration and initialization of these variables coincide.

In the case of char_size this also always initializes the variable
immediately with the final value actually used in the loop (instead of
the placeholder value 32).

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---
 drivers/spi/mpc8xxx_spi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
index 30249cce57..5bf84aaec6 100644
--- a/drivers/spi/mpc8xxx_spi.c
+++ b/drivers/spi/mpc8xxx_spi.c
@@ -89,10 +89,8 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
 	     ulong flags)
 {
 	spi8xxx_t *spi = &((immap_t *)(CONFIG_SYS_IMMR))->spi;
-	uint tmpdout, tmpdin, event;
+	u32 tmpdin;
 	int num_blks = DIV_ROUND_UP(bitlen, 32);
-	int tm;
-	uchar char_size = 32;
 
 	debug("%s: slave %u:%u dout %08X din %08X bitlen %u\n", __func__,
 	      slave->bus, slave->cs, *(uint *)dout, *(uint *)din, bitlen);
@@ -105,8 +103,9 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
 
 	/* Handle data in 32-bit chunks */
 	while (num_blks--) {
-		tmpdout = 0;
-		char_size = (bitlen >= 32 ? 32 : bitlen);
+		int tm;
+		u32 tmpdout = 0;
+		uchar char_size = (bitlen >= 32 ? 32 : bitlen);
 
 		/* Shift data so it's msb-justified */
 		tmpdout = *(u32 *)dout >> (32 - char_size);
@@ -146,7 +145,7 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din,
 		 * The NE event must be read and cleared first
 		 */
 		for (tm = 0; tm < SPI_TIMEOUT; ++tm) {
-			event = in_be32(&spi->event);
+			u32 event = in_be32(&spi->event);
 			bool have_ne = event & SPI_EV_NE;
 			bool have_nf = event & SPI_EV_NF;
 
-- 
2.11.0

  parent reply	other threads:[~2018-04-10 11:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10 11:01 [U-Boot] [PATCH 00/19] spi: mpc8xxx: DM conversion Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 01/19] spi: mpc8xxx: Use short type names Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 02/19] spi: mpc8xxx: Fix comments Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 03/19] spi: mpc8xxx: Rename camel-case variables Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 04/19] spi: mpc8xxx: Fix space after cast Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 05/19] spi: mpc8xxx: Fix function names in strings Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 06/19] spi: mpc8xxx: Replace defines with enums Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 07/19] spi: mpc8xxx: Use IO accessors Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 08/19] spi: mpc8xxx: Simplify if Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 09/19] spi: mpc8xxx: Get rid of is_read Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 10/19] spi: mpc8xxx: Simplify logic a bit Mario Six
2018-04-10 11:01 ` Mario Six [this message]
2018-04-10 11:01 ` [U-Boot] [PATCH 12/19] spi: mpc8xxx: Make code more readable Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 13/19] spi: mpc8xxx: Rename variable Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 14/19] spi: mpc8xxx: Document LEN setting better Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 15/19] spi: mpc8xxx: Re-order transfer setup Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 16/19] spi: mpc8xxx: Fix if check Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 17/19] spi: mpc8xxx: Use get_timer Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 18/19] spi: mpc8xxx: Prepare DM conversion Mario Six
2018-04-10 11:01 ` [U-Boot] [PATCH 19/19] spi: mpc8xxx: Add DM support Mario Six
2018-04-19 11:32   ` Jagan Teki
2018-04-19 11:45     ` Mario Six
2018-04-19 11:48       ` Jagan Teki
2018-04-19 11:51         ` Mario Six

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=01507368b4be8c17ce415753058f133085eb4b31.1523355172.git.mario.six@gdsys.cc \
    --to=mario.six@gdsys.cc \
    --cc=u-boot@lists.denx.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 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.