Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Nov 2013 00:00:35 +0100
From:      Kristof Provost <kristof@sigsegv.be>
To:        Warner Losh <imp@bsdimp.com>
Cc:        Grzegorz Bernacki <gber@FreeBSD.org>, freebsd-embedded@freebsd.org
Subject:   Re: Incorrect struct onfi_params definition
Message-ID:  <20131106230035.GG58987@vega.codepro.be>
In-Reply-To: <BA053B08-AD98-4FD2-AAB5-FBC8CEBDCEE0@bsdimp.com>
References:  <20131106212855.GF58987@vega.codepro.be> <BA053B08-AD98-4FD2-AAB5-FBC8CEBDCEE0@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2013-11-06 13:56:46 (-0800), Warner Losh <imp@bsdimp.com> wrote:
> On Nov 6, 2013, at 1:28 PM, Kristof Provost wrote:
> > The definition of struct onfi_params in sys/dev/nand/nand.h is
> > incorrect. The total structure size should be 256 bytes, but it's only
> > 176 bytes.
> > 
> > That's because the vendor_spec array was declared as being 8 bytes,
> > rather than the 88 bytes it should be. Clearly a typo.
> > 
> > This patch should fix it:
> 
> I'd add a CT_ASSERT sizeof(onfi_params) == 256 too.
> 
Ok, here's an updated patch:

diff --git a/sys/dev/nand/nand.h b/sys/dev/nand/nand.h
index 0d6d7b4..6e3fc04 100644
--- a/sys/dev/nand/nand.h
+++ b/sys/dev/nand/nand.h
@@ -31,6 +31,7 @@
 
 #include <sys/bus.h>
 #include <sys/param.h>
+#include <sys/systm.h>
 #include <sys/lock.h>
 #include <sys/sx.h>
 #include <sys/taskqueue.h>
@@ -217,9 +218,10 @@ struct onfi_params {
 	uint8_t		driver_strength_support;
 	uint8_t		res4[12];
 	uint16_t	vendor_rev;
-	uint8_t		vendor_spec[8];
+	uint8_t		vendor_spec[88];
 	uint16_t	crc;
 }__attribute__((packed));
+CTASSERT(sizeof(struct onfi_params) == 256);
 
 struct nand_ecc_data {
 	int	eccsize;		/* Number of data bytes per ECC step */


Regards,
Kristof



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131106230035.GG58987>