Skip to contentSkip to conversation

spi: fsl-spi: Convert to let spi core validate xfer->bits_per_word

PATCH In review Axel Lin 2 participants 3 messages Feb 12, 2014 – Feb 13, 2014 1 message not in the archive SPI

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 spi: fsl-spi: Convert to let spi core validate xfer->bits_per_word

Set bits_per_word_mask so spi core will reject transfers that attempt to use an unsupported bits_per_word value.

---
 drivers/spi/spi-fsl-spi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/spi/spi-fsl-spi.c +2 -6
index 4dcb292..28064ad 100644
@@ -239,12 +239,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi,
 	if (!bits_per_word)
 		bits_per_word = spi->bits_per_word;
 
-	/* Make sure its a bit width we support [4..16, 32] */
-	if ((bits_per_word < 4)
-	    || ((bits_per_word > 16) && (bits_per_word != 32))
-	    || (bits_per_word > mpc8xxx_spi->max_bits_per_word))
-		return -EINVAL;
-
 	if (!hz)
 		hz = spi->max_speed_hz;
 
@@ -631,6 +625,8 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
 
 	master->setup = fsl_spi_setup;
 	master->cleanup = fsl_spi_cleanup;
+	master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16) |
+				     SPI_BPW_MASK(32);
 
 	mpc8xxx_spi = spi_master_get_devdata(master);
 	mpc8xxx_spi->spi_do_one_msg = fsl_spi_do_one_msg;
Signature · 8 lines
1.8.1.2



--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

Hi!

This patch probably also needs to make sure that bits_per_word can not be greater than mpc8xxx_spi->max_bits_per_word.

Quoted 13 lines · Axel Lin

Set bits_per_word_mask so spi core will reject transfers that attempt to use an unsupported bits_per_word value.

---
  drivers/spi/spi-fsl-spi.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/spi/spi-fsl-spi.c +0 -0
index 4dcb292..28064ad 100644

drivers/spi/spi-fsl-spi.c static int fsl_spi_setup_transfer(struct spi_device *spi, · line 245

Quoted 7 lines
drivers/spi/spi-fsl-spi.c +0 -4
@@ -239,12 +239,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi,
  	if (!bits_per_word)
  		bits_per_word = spi->bits_per_word;
 
-	/* Make sure its a bit width we support [4..16, 32] */
-	if ((bits_per_word < 4)
-	    || ((bits_per_word > 16) && (bits_per_word != 32))
-	    || (bits_per_word > mpc8xxx_spi->max_bits_per_word))

This max_bits_per_word check here...

drivers/spi/spi-fsl-spi.c static struct spi_master * fsl_spi_probe(struct device *dev, · line 629

Quoted 11 lines
drivers/spi/spi-fsl-spi.c +2 -2
-		return -EINVAL;
-
  	if (!hz)
  		hz = spi->max_speed_hz;
 
@@ -631,6 +625,8 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
 
  	master->setup = fsl_spi_setup;
  	master->cleanup = fsl_spi_cleanup;
+	master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16) |
+				     SPI_BPW_MASK(32);

...has no corresponding logic down here.

drivers/spi/spi-fsl-spi.c static struct spi_master * fsl_spi_probe(struct device *dev,

Quoted 4 lines
drivers/spi/spi-fsl-spi.c +0 -0
  	mpc8xxx_spi = spi_master_get_devdata(master);
  	mpc8xxx_spi->spi_do_one_msg = fsl_spi_do_one_msg;
 

Best regards,
Andreas Larsson
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 52FC8100.4020408-FkzTOoA/[email protected]

author
#3 lore raw

2014-02-13 16:23 GMT+08:00 Andreas Larsson <andreas-FkzTOoA/[email protected]>:

Quoted 43 lines

Hi!

This patch probably also needs to make sure that bits_per_word can not be greater than mpc8xxx_spi->max_bits_per_word.

Quoted 15 lines · Axel Lin

Set bits_per_word_mask so spi core will reject transfers that attempt to use
an unsupported bits_per_word value.

---
  drivers/spi/spi-fsl-spi.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
drivers/spi/spi-fsl-spi.c +0 -0
index 4dcb292..28064ad 100644

drivers/spi/spi-fsl-spi.c static int fsl_spi_setup_transfer(struct spi_device · line 246

Quoted 8 lines
drivers/spi/spi-fsl-spi.c +0 -4
@@ -239,12 +239,6 @@ static int fsl_spi_setup_transfer(struct spi_device
 *spi,
        if (!bits_per_word)
                bits_per_word = spi->bits_per_word;
 
-       /* Make sure its a bit width we support [4..16, 32] */
-       if ((bits_per_word < 4)
-           || ((bits_per_word > 16) && (bits_per_word != 32))
-           || (bits_per_word > mpc8xxx_spi->max_bits_per_word))

This max_bits_per_word check here...

Quoted 8 lines
drivers/spi/spi-fsl-spi.c +0 -2
-               return -EINVAL;
-
        if (!hz)
                hz = spi->max_speed_hz;
@@ -631,6 +625,8 @@ static struct spi_master * fsl_spi_probe(struct device
 *dev,
 
Quoted 7 lines

drivers/spi/spi-fsl-spi.c static struct spi_master * fsl_spi_probe(struct device *dev, · line 629

Quoted 4 lines
drivers/spi/spi-fsl-spi.c +2 -0
        master->setup = fsl_spi_setup;
        master->cleanup = fsl_spi_cleanup;
+       master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16) |
+                                    SPI_BPW_MASK(32);

...has no corresponding logic down here.

Actually, it does.
see spi.c and take a look at __spi_validate().

                if (master->bits_per_word_mask) {
                        /* Only 32 bits fit in the mask */
                        if (xfer->bits_per_word > 32)
                                return -EINVAL;
                        if (!(master->bits_per_word_mask &
                                        BIT(xfer->bits_per_word - 1)))
                                return -EINVAL;
                }

Regards,
Axel
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html