From: Gerhard Sittig <gsi-ynQEQJNshbs@public.gmane.org>
To: "Ivan T. Ivanov" <iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2] spi: core: Validate lenght of the transfers in message
Date: Sun, 16 Feb 2014 15:25:12 +0100 [thread overview]
Message-ID: <20140216142512.GR4524@book.gsilab.sittig.org> (raw)
In-Reply-To: <1392444566-23605-1-git-send-email-iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
On Sat, Feb 15, 2014 at 08:09 +0200, Ivan T. Ivanov wrote:
>
> From: "Ivan T. Ivanov" <iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
>
> SPI transfer lenght should be a power-of-two multiple
> of eight bits.
Please re-check for "lenght" typos in subjects and commit logs
(code comments appear to be correct already).
The commit message still confuses me. You don't check that the
length of an SPI transfer has a power-of-two length in bytes.
Instead what the check implements is IIUC
- pad "odd" bits-per-word settings before the check to full 1/2/4
byte length specs (this is the power-of-two thing)
- the total length of the SPI transfer cannot be empty (which I'd
consider an optimization, not a violation, and may need a
separate discussion)
- the total length of the SPI transfer must be such that each
"word" must be provided within a full 1/2/4 byte entity, with
padding bits if the bits-per-word is "odd"
Is this a misunderstanding on my side? A terminology thing? To
me, the "SPI transfer" is the total payload and may have any
arbitrary length. What you check for is a constraint on the
transfer's length derived from or based on the "word length"
('word' in SPI context).
So the code may be appropriate, yet the description may need an
update, to not have the next person ask the same questions again.
> @@ -1668,6 +1669,22 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
> return -EINVAL;
> }
>
> + /*
> + * SPI transfer length should be multiple of SPI word size
> + * where SPI word size should be power-of-two multiple
> + */
> + if (xfer->bits_per_word <= 8)
> + w_size = 1;
> + else if (xfer->bits_per_word <= 16)
> + w_size = 2;
> + else
> + w_size = 4;
> +
> + n_words = xfer->len / w_size;
> + /* No partial transfers accepted */
> + if (!n_words || xfer->len % xfer->bits_per_word)
> + return -EINVAL;
> +
> if (xfer->speed_hz && master->min_speed_hz &&
> xfer->speed_hz < master->min_speed_hz)
> return -EINVAL;
[ just left the code here for comparison with the above description ]
virtually yours
Gerhard Sittig
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office-ynQEQJNshbs@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-02-16 14:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-15 6:09 [PATCH v2] spi: core: Validate lenght of the transfers in message Ivan T. Ivanov
[not found] ` <1392444566-23605-1-git-send-email-iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org>
2014-02-16 14:25 ` Gerhard Sittig [this message]
[not found] ` <20140216142512.GR4524-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-02-17 7:41 ` Ivan T. Ivanov
2014-02-18 0:09 ` Mark Brown
[not found] ` <20140218000938.GE2669-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-02-18 19:37 ` Gerhard Sittig
[not found] ` <20140218193747.GE4524-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-02-19 1:51 ` Mark Brown
2014-02-17 15:20 ` Ivan T. Ivanov
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=20140216142512.GR4524@book.gsilab.sittig.org \
--to=gsi-ynqeqjnshbs@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=iivanov-NEYub+7Iv8PQT0dZR+AlfA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).