Re: [PATCH v2 1/1] serial: sc16is7xx: improve regmap debugfs by using one regmap per port

From: Jiri Slaby
Date: Tue Nov 21 2023 - 00:58:07 EST


On 20. 11. 23, 17:39, Hugo Villeneuve wrote:
From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>

With this current driver regmap implementation, it is hard to make sense
of the register addresses displayed using the regmap debugfs interface,
because they do not correspond to the actual register addresses documented
in the datasheet. For example, register 1 is displayed as registers 04 thru
07:
...
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
...
#ifdef CONFIG_SERIAL_SC16IS7XX_SPI
static int sc16is7xx_spi_probe(struct spi_device *spi)
{
const struct sc16is7xx_devtype *devtype;
- struct regmap *regmap;
+ struct regmap *regmaps[2];

IMO, in all places, it would make sense to declare a VLA with devtype->nr_uart.

+ unsigned int i;
int ret;
/* Setup SPI bus */
@@ -1732,11 +1736,20 @@ static int sc16is7xx_spi_probe(struct spi_device *spi)
devtype = (struct sc16is7xx_devtype *)id_entry->driver_data;
}
- regcfg.max_register = (0xf << SC16IS7XX_REG_SHIFT) |
- (devtype->nr_uart - 1);
- regmap = devm_regmap_init_spi(spi, &regcfg);
+ for (i = 0; i < devtype->nr_uart; i++) {
+ regcfg.name = sc16is7xx_regmap_name(i);
+ /*
+ * If read_flag_mask is 0, the regmap code sets it to a default
+ * of 0x80. Since we specify our own mask, we must add the READ
+ * bit ourselves:
+ */
+ regcfg.read_flag_mask = sc16is7xx_regmap_port_mask(i) |
+ SC16IS7XX_SPI_READ_BIT;
+ regcfg.write_flag_mask = sc16is7xx_regmap_port_mask(i);
+ regmaps[i] = devm_regmap_init_spi(spi, &regcfg);

As you trip over the array until devtype->nr_uart which is of course up to 2. For now.

Or at least add an asserion: devtype->nr_uart <= 2 somewhere.

thanks,
--
js
suse labs