Re: [PATCH] spi: dln2: validate chip select count reported by the device

From: Andy Shevchenko

Date: Fri Sep 11 2026 - 03:00:55 EST


On Thu, Sep 10, 2026 at 09:43:38PM +0000, Farhad Alemi wrote:
> dln2_spi_get_cs_num() stores the chip select count reported by the device
> straight into host->num_chipselect, and dln2_spi_cs_enable_all() then
> evaluates GENMASK(num_chipselect - 1, 0), whose shift exponent is out of
> bounds whenever that count is zero or larger than BITS_PER_LONG. The
> resulting mask is handed back to the device in a u8 field, so any count
> outside 1..8 is invalid regardless. Reject such counts with -EPROTO in
> dln2_spi_get_cs_num(), where the value is first read.

You need to check with the datasheet. It says that only 4 SS lines can be
programmed. The reserved bits must be held in 1. So, all in all, the _MAX_CS
should be 4.

> Closes: https://lore.kernel.org/all/CA+0ovCioY634b646jDcs2cFmg_1q2UMN4wuTQ1V26Gy+Dm_c+A@xxxxxxxxxxxxxx/
> Signed-off-by: Farhad Alemi <farhad.alemi@xxxxxxxxxxxx>
> ---

Datasheet: https://diolan.com/media/wysiwyg/downloads/dln-api-manual.pdf

--
With Best Regards,
Andy Shevchenko