diff mbox series

[7/7] serial: max310x: use separate regmap name for each port

Message ID 20231130191050.3165862-8-hugo@hugovil.com
State New
Headers show
Series serial: sc16is7xx and max310x: regmap fixes and improvements | expand

Commit Message

Hugo Villeneuve Nov. 30, 2023, 7:10 p.m. UTC
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Use a separate regmap name for each port so that each port can have its own
debugfs entry, allowing to access each port registers independently.

For example, a four channels/ports device like the MAX14830 will have four
entries in its regmap debugfs:

$ find /sys/kernel/debug/regmap -type d | grep spi0.0
/sys/kernel/debug/regmap/spi0.0-port0
/sys/kernel/debug/regmap/spi0.0-port1
/sys/kernel/debug/regmap/spi0.0-port2
/sys/kernel/debug/regmap/spi0.0-port3

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/tty/serial/max310x.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Jan Kundrát Dec. 1, 2023, 4 p.m. UTC | #1
On čtvrtek 30. listopadu 2023 20:10:49 CET, Hugo Villeneuve wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> Use a separate regmap name for each port so that each port can have its own
> debugfs entry, allowing to access each port registers independently.
>
> For example, a four channels/ports device like the MAX14830 will have four
> entries in its regmap debugfs:
>
> $ find /sys/kernel/debug/regmap -type d | grep spi0.0
> /sys/kernel/debug/regmap/spi0.0-port0
> /sys/kernel/debug/regmap/spi0.0-port1
> /sys/kernel/debug/regmap/spi0.0-port2
> /sys/kernel/debug/regmap/spi0.0-port3
>
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>

I was carrying a similar patch locally, and this one works for me as well.

Reviewed-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Tested-by: Jan Kundrát <jan.kundrat@cesnet.cz>

> ---
>  drivers/tty/serial/max310x.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
> index 58dd5cc62014..d2eca05a6966 100644
> --- a/drivers/tty/serial/max310x.c
> +++ b/drivers/tty/serial/max310x.c
> @@ -27,6 +27,7 @@
>  #include <linux/uaccess.h>
>  
>  #define MAX310X_NAME			"max310x"
> +#define MAX310X_PORT_NAME_SUFFIX	"port"
>  #define MAX310X_MAJOR			204
>  #define MAX310X_MINOR			209
>  #define MAX310X_UART_NRMAX		16
> @@ -1486,6 +1487,15 @@ static struct regmap_config regcfg = {
>  	.max_raw_write = MAX310X_FIFO_SIZE,
>  };
>  
> +static const char *max310x_regmap_name(unsigned int port_id)
> +{
> +	static char buf[sizeof(MAX310X_PORT_NAME_SUFFIX 
> __stringify(MAX310X_MAX_PORTS))];
> +
> +	snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
> +
> +	return buf;
> +}
> +
>  #ifdef CONFIG_SPI_MASTER
>  static int max310x_spi_extended_reg_enable(struct device *dev, bool enable)
>  {
> @@ -1521,6 +1531,8 @@ static int max310x_spi_probe(struct spi_device *spi)
>  
>  	for (i = 0; i < devtype->nr; i++) {
>  		u8 port_mask = i * 0x20;
> +
> +		regcfg.name = max310x_regmap_name(i);
>  		regcfg.read_flag_mask = port_mask;
>  		regcfg.write_flag_mask = port_mask | MAX310X_WRITE_BIT;
>  		regmaps[i] = devm_regmap_init_spi(spi, &regcfg);
> @@ -1617,6 +1629,7 @@ static int max310x_i2c_probe(struct 
> i2c_client *client)
>  				     client->addr, devtype->slave_addr.min,
>  				     devtype->slave_addr.max);
>  
> +	regcfg_i2c.name = max310x_regmap_name(0);
>  	regmaps[0] = devm_regmap_init_i2c(client, &regcfg_i2c);
>  
>  	for (i = 1; i < devtype->nr; i++) {
> @@ -1625,6 +1638,7 @@ static int max310x_i2c_probe(struct 
> i2c_client *client)
>  							client->adapter,
>  							port_addr);
>  
> +		regcfg_i2c.name = max310x_regmap_name(i);
>  		regmaps[i] = devm_regmap_init_i2c(port_client, &regcfg_i2c);
>  	}
>
kernel test robot Dec. 6, 2023, 2:22 p.m. UTC | #2
Hi Hugo,

kernel test robot noticed the following build warnings:

[auto build test WARNING on d804987153e7bedf503f8e4ba649afe52cfd7f6d]

url:    https://github.com/intel-lab-lkp/linux/commits/Hugo-Villeneuve/serial-sc16is7xx-fix-snprintf-format-specifier-in-sc16is7xx_regmap_name/20231201-031413
base:   d804987153e7bedf503f8e4ba649afe52cfd7f6d
patch link:    https://lore.kernel.org/r/20231130191050.3165862-8-hugo%40hugovil.com
patch subject: [PATCH 7/7] serial: max310x: use separate regmap name for each port
config: arm-randconfig-r081-20231201 (https://download.01.org/0day-ci/archive/20231206/202312062240.v39k99mQ-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312062240.v39k99mQ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312062240.v39k99mQ-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In function 'max310x_regmap_name',
       inlined from 'max310x_i2c_probe' at drivers/tty/serial/max310x.c:1641:21:
>> drivers/tty/serial/max310x.c:30:41: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 2 [-Wformat-truncation=]
      30 | #define MAX310X_PORT_NAME_SUFFIX        "port"
         |                                         ^~~~~~
   drivers/tty/serial/max310x.c:1494:36: note: in expansion of macro 'MAX310X_PORT_NAME_SUFFIX'
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/max310x.c: In function 'max310x_i2c_probe':
   drivers/tty/serial/max310x.c:1494:62: note: format string is defined here
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                                              ^~
   In function 'max310x_regmap_name',
       inlined from 'max310x_i2c_probe' at drivers/tty/serial/max310x.c:1641:21:
   drivers/tty/serial/max310x.c:30:41: note: directive argument in the range [1, 4294967294]
      30 | #define MAX310X_PORT_NAME_SUFFIX        "port"
         |                                         ^~~~~~
   drivers/tty/serial/max310x.c:1494:36: note: in expansion of macro 'MAX310X_PORT_NAME_SUFFIX'
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/max310x.c:1494:9: note: 'snprintf' output between 6 and 15 bytes into a destination of size 6
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In function 'max310x_regmap_name',
       inlined from 'max310x_spi_probe' at drivers/tty/serial/max310x.c:1535:17:
>> drivers/tty/serial/max310x.c:30:41: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 2 [-Wformat-truncation=]
      30 | #define MAX310X_PORT_NAME_SUFFIX        "port"
         |                                         ^~~~~~
   drivers/tty/serial/max310x.c:1494:36: note: in expansion of macro 'MAX310X_PORT_NAME_SUFFIX'
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/max310x.c: In function 'max310x_spi_probe':
   drivers/tty/serial/max310x.c:1494:62: note: format string is defined here
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                                              ^~
   In function 'max310x_regmap_name',
       inlined from 'max310x_spi_probe' at drivers/tty/serial/max310x.c:1535:17:
   drivers/tty/serial/max310x.c:30:41: note: directive argument in the range [0, 4294967294]
      30 | #define MAX310X_PORT_NAME_SUFFIX        "port"
         |                                         ^~~~~~
   drivers/tty/serial/max310x.c:1494:36: note: in expansion of macro 'MAX310X_PORT_NAME_SUFFIX'
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/tty/serial/max310x.c:1494:9: note: 'snprintf' output between 6 and 15 bytes into a destination of size 6
    1494 |         snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +30 drivers/tty/serial/max310x.c

    28	
    29	#define MAX310X_NAME			"max310x"
  > 30	#define MAX310X_PORT_NAME_SUFFIX	"port"
    31	#define MAX310X_MAJOR			204
    32	#define MAX310X_MINOR			209
    33	#define MAX310X_UART_NRMAX		16
    34	#define MAX310X_MAX_PORTS		4 /* Maximum number of UART ports per IC. */
    35
diff mbox series

Patch

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 58dd5cc62014..d2eca05a6966 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -27,6 +27,7 @@ 
 #include <linux/uaccess.h>
 
 #define MAX310X_NAME			"max310x"
+#define MAX310X_PORT_NAME_SUFFIX	"port"
 #define MAX310X_MAJOR			204
 #define MAX310X_MINOR			209
 #define MAX310X_UART_NRMAX		16
@@ -1486,6 +1487,15 @@  static struct regmap_config regcfg = {
 	.max_raw_write = MAX310X_FIFO_SIZE,
 };
 
+static const char *max310x_regmap_name(unsigned int port_id)
+{
+	static char buf[sizeof(MAX310X_PORT_NAME_SUFFIX __stringify(MAX310X_MAX_PORTS))];
+
+	snprintf(buf, sizeof(buf), MAX310X_PORT_NAME_SUFFIX "%u", port_id);
+
+	return buf;
+}
+
 #ifdef CONFIG_SPI_MASTER
 static int max310x_spi_extended_reg_enable(struct device *dev, bool enable)
 {
@@ -1521,6 +1531,8 @@  static int max310x_spi_probe(struct spi_device *spi)
 
 	for (i = 0; i < devtype->nr; i++) {
 		u8 port_mask = i * 0x20;
+
+		regcfg.name = max310x_regmap_name(i);
 		regcfg.read_flag_mask = port_mask;
 		regcfg.write_flag_mask = port_mask | MAX310X_WRITE_BIT;
 		regmaps[i] = devm_regmap_init_spi(spi, &regcfg);
@@ -1617,6 +1629,7 @@  static int max310x_i2c_probe(struct i2c_client *client)
 				     client->addr, devtype->slave_addr.min,
 				     devtype->slave_addr.max);
 
+	regcfg_i2c.name = max310x_regmap_name(0);
 	regmaps[0] = devm_regmap_init_i2c(client, &regcfg_i2c);
 
 	for (i = 1; i < devtype->nr; i++) {
@@ -1625,6 +1638,7 @@  static int max310x_i2c_probe(struct i2c_client *client)
 							client->adapter,
 							port_addr);
 
+		regcfg_i2c.name = max310x_regmap_name(i);
 		regmaps[i] = devm_regmap_init_i2c(port_client, &regcfg_i2c);
 	}