Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: rc: ir-spi: constrain carrier frequency

Carrier frequency is currently unconstrained, allowing the SPI transfer
to be allocated and filled only for it to be later rejected by the SPI
controller since the frequency is too large.

Add a check to constrain the carrier frequency inside
ir_spi_set_tx_carrier().

Also, move the number of bits per pulse to a macro since it is not used
in multiple places.

Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

authored by

Cosmin Tanislav and committed by
Hans Verkuil
032a68cc c898efdd

+5 -1
+5 -1
drivers/media/rc/ir-spi.c
··· 21 21 #define IR_SPI_DRIVER_NAME "ir-spi" 22 22 23 23 #define IR_SPI_DEFAULT_FREQUENCY 38000 24 + #define IR_SPI_BITS_PER_PULSE 16 24 25 25 26 struct ir_spi_data { 26 27 u32 freq; ··· 71 70 72 71 memset(&xfer, 0, sizeof(xfer)); 73 72 74 - xfer.speed_hz = idata->freq * 16; 73 + xfer.speed_hz = idata->freq * IR_SPI_BITS_PER_PULSE; 75 74 xfer.len = len * sizeof(*tx_buf); 76 75 xfer.tx_buf = tx_buf; 77 76 ··· 97 96 struct ir_spi_data *idata = dev->priv; 98 97 99 98 if (!carrier) 99 + return -EINVAL; 100 + 101 + if (carrier > idata->spi->max_speed_hz / IR_SPI_BITS_PER_PULSE) 100 102 return -EINVAL; 101 103 102 104 idata->freq = carrier;