lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20141119135121.GF7857@localhost>
Date:	Wed, 19 Nov 2014 14:51:21 +0100
From:	Johan Hovold <johan@...nel.org>
To:	Laurentiu Palcu <laurentiu.palcu@...el.com>
Cc:	Mark Brown <broonie@...nel.org>,
	Samuel Ortiz <sameo@...ux.intel.com>,
	Lee Jones <lee.jones@...aro.org>,
	Johan Havold <johan@...nel.org>,
	Octavian Purdila <octavian.purdila@...el.com>,
	linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 1/2] spi: add support for DLN-2 USB-SPI adapter

On Wed, Nov 19, 2014 at 03:07:47PM +0200, Laurentiu Palcu wrote:

> +/*
> + * Perform one read operation.
> + */
> +static int dln2_spi_read_one(struct dln2_spi *dln2, u8 *data,
> +			     u16 data_len, u8 attr)
> +{
> +	int ret;
> +	struct {
> +		u8 port;
> +		__le16 size;
> +		u8 attr;
> +	} __packed tx;
> +	struct {
> +		__le16 size;
> +		u8 buf[DLN2_SPI_MAX_XFER_SIZE];
> +	} __packed *rx = dln2->buf;

You said you verified that the dln2 protocol headers did not mess up the
alignment, yet they do. Here you have a two byte header.

> +	unsigned rx_len = sizeof(*rx);
> +
> +	BUILD_BUG_ON(sizeof(*rx) > DLN2_SPI_BUF_SIZE);
> +
> +	if (data_len > DLN2_SPI_MAX_XFER_SIZE)
> +		return -EINVAL;
> +
> +	tx.port = dln2->port;
> +	tx.size = cpu_to_le16(data_len);
> +	tx.attr = attr;
> +
> +	ret = dln2_transfer(dln2->pdev, DLN2_SPI_READ, &tx, sizeof(tx),
> +			    rx, &rx_len);
> +	if (ret < 0)
> +		return ret;
> +	if (rx_len < sizeof(rx->size) + data_len)
> +		return -EPROTO;
> +	if (le16_to_cpu(rx->size) != data_len)
> +		return -EPROTO;
> +
> +	dln2_spi_copy_from_buf(data, rx->buf, data_len, dln2->bpw);

So you need to use the unaligned macros in dln2_spi_copy_from_buf for
rx->buf (at least for bpw 32).

Make sure to document why.

> +
> +	return 0;
> +}
> +
> +/*
> + * Perform one write & read operation.
> + */
> +static int dln2_spi_read_write_one(struct dln2_spi *dln2, const u8 *tx_data,
> +				   u8 *rx_data, u16 data_len, u8 attr)
> +{
> +	int ret;
> +	struct {
> +		u8 port;
> +		__le16 size;
> +		u8 attr;
> +		u8 buf[DLN2_SPI_MAX_XFER_SIZE];
> +	} __packed *tx;

tx is ok.

> +	struct {
> +		__le16 size;
> +		u8 buf[DLN2_SPI_MAX_XFER_SIZE];
> +	} __packed *rx;

But here you have the same two-byte header.

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ