public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave
Date: Sat, 21 Feb 2015 00:17:47 +0800	[thread overview]
Message-ID: <1424449067.29368.1.camel@phoenix> (raw)

Don't assume slave is always the first member of struct cf_spi_slave.
Use container_of instead of casting first structure member.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/spi/cf_spi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
index 879a809..7453538 100644
--- a/drivers/spi/cf_spi.c
+++ b/drivers/spi/cf_spi.c
@@ -46,6 +46,11 @@ DECLARE_GLOBAL_DATA_PTR;
 #define SPI_MODE_MOD	0x00200000
 #define SPI_DBLRATE	0x00100000
 
+static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
+{
+	return container_of(slave, struct cf_spi_slave, slave);
+}
+
 void cfspi_init(void)
 {
 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
@@ -105,7 +110,7 @@ u16 cfspi_rx(void)
 int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
 	       void *din, ulong flags)
 {
-	struct cf_spi_slave *cfslave = (struct cf_spi_slave *)slave;
+	struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
 	u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
 	u8 *spi_rd = NULL, *spi_wr = NULL;
 	static u32 ctrl = 0;
@@ -326,7 +331,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 void spi_free_slave(struct spi_slave *slave)
 {
-	free(slave);
+	struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
+
+	free(cfslave);
 }
 
 int spi_claim_bus(struct spi_slave *slave)
-- 
1.9.1

             reply	other threads:[~2015-02-20 16:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 16:17 Axel Lin [this message]
2015-02-20 16:19 ` [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions Axel Lin
2015-03-29 20:14   ` Jagan Teki
2015-03-29 20:14 ` [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Jagan Teki

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=1424449067.29368.1.camel@phoenix \
    --to=axel.lin@ingics.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox