All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd: lpc_ich: convert name to const char*
@ 2021-12-02  9:42 Heiner Kallweit
  2021-12-29 13:16 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2021-12-02  9:42 UTC (permalink / raw)
  To: Peter Tyser, Lee Jones; +Cc: Linux Kernel Mailing List

This change reduces the memory footprint of the structs (admittedly
not much), and it allows the compiler to store names only once.
E.g. i2c-i801 uses name "Intel PCH" twice. All users assign static
strings to name, and only usage of name is in iTCO_wdt_probe() for
printing a syslog info message. So we don't really have to worry
about potential issues like use after free.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/mfd/lpc_ich.c                  | 2 +-
 include/linux/mfd/lpc_ich.h            | 2 +-
 include/linux/platform_data/itco_wdt.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/lpc_ich.c b/drivers/mfd/lpc_ich.c
index f10e53187..acb33a180 100644
--- a/drivers/mfd/lpc_ich.c
+++ b/drivers/mfd/lpc_ich.c
@@ -889,7 +889,7 @@ static int lpc_ich_finalize_wdt_cell(struct pci_dev *dev)
 	info = &lpc_chipset_info[priv->chipset];
 
 	pdata->version = info->iTCO_version;
-	strlcpy(pdata->name, info->name, sizeof(pdata->name));
+	pdata->name = info->name;
 
 	cell->platform_data = pdata;
 	cell->pdata_size = sizeof(*pdata);
diff --git a/include/linux/mfd/lpc_ich.h b/include/linux/mfd/lpc_ich.h
index 39967a5ec..6dec7d992 100644
--- a/include/linux/mfd/lpc_ich.h
+++ b/include/linux/mfd/lpc_ich.h
@@ -27,7 +27,7 @@ enum {
 };
 
 struct lpc_ich_info {
-	char name[32];
+	const char *name;
 	unsigned int iTCO_version;
 	unsigned int gpio_version;
 	enum intel_spi_type spi_type;
diff --git a/include/linux/platform_data/itco_wdt.h b/include/linux/platform_data/itco_wdt.h
index 45d860cac..c6941c089 100644
--- a/include/linux/platform_data/itco_wdt.h
+++ b/include/linux/platform_data/itco_wdt.h
@@ -19,7 +19,7 @@
  * @no_reboot_use_pmc: Use PMC BXT API to set and clear NO_REBOOT bit
  */
 struct itco_wdt_platform_data {
-	char name[32];
+	const char *name;
 	unsigned int version;
 	bool no_reboot_use_pmc;
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mfd: lpc_ich: convert name to const char*
  2021-12-02  9:42 [PATCH] mfd: lpc_ich: convert name to const char* Heiner Kallweit
@ 2021-12-29 13:16 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2021-12-29 13:16 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: Peter Tyser, Linux Kernel Mailing List

On Thu, 02 Dec 2021, Heiner Kallweit wrote:

> This change reduces the memory footprint of the structs (admittedly
> not much), and it allows the compiler to store names only once.
> E.g. i2c-i801 uses name "Intel PCH" twice. All users assign static
> strings to name, and only usage of name is in iTCO_wdt_probe() for
> printing a syslog info message. So we don't really have to worry
> about potential issues like use after free.

Something about this patch makes me uneasy.

Honestly I'd rather copy this tiny amount of data over to a known safe
location than use pointers to potentially stale data structures.

> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/mfd/lpc_ich.c                  | 2 +-
>  include/linux/mfd/lpc_ich.h            | 2 +-
>  include/linux/platform_data/itco_wdt.h | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mfd/lpc_ich.c b/drivers/mfd/lpc_ich.c
> index f10e53187..acb33a180 100644
> --- a/drivers/mfd/lpc_ich.c
> +++ b/drivers/mfd/lpc_ich.c
> @@ -889,7 +889,7 @@ static int lpc_ich_finalize_wdt_cell(struct pci_dev *dev)
>  	info = &lpc_chipset_info[priv->chipset];
>  
>  	pdata->version = info->iTCO_version;
> -	strlcpy(pdata->name, info->name, sizeof(pdata->name));
> +	pdata->name = info->name;
>  
>  	cell->platform_data = pdata;
>  	cell->pdata_size = sizeof(*pdata);
> diff --git a/include/linux/mfd/lpc_ich.h b/include/linux/mfd/lpc_ich.h
> index 39967a5ec..6dec7d992 100644
> --- a/include/linux/mfd/lpc_ich.h
> +++ b/include/linux/mfd/lpc_ich.h
> @@ -27,7 +27,7 @@ enum {
>  };
>  
>  struct lpc_ich_info {
> -	char name[32];
> +	const char *name;
>  	unsigned int iTCO_version;
>  	unsigned int gpio_version;
>  	enum intel_spi_type spi_type;
> diff --git a/include/linux/platform_data/itco_wdt.h b/include/linux/platform_data/itco_wdt.h
> index 45d860cac..c6941c089 100644
> --- a/include/linux/platform_data/itco_wdt.h
> +++ b/include/linux/platform_data/itco_wdt.h
> @@ -19,7 +19,7 @@
>   * @no_reboot_use_pmc: Use PMC BXT API to set and clear NO_REBOOT bit
>   */
>  struct itco_wdt_platform_data {
> -	char name[32];
> +	const char *name;
>  	unsigned int version;
>  	bool no_reboot_use_pmc;
>  };

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-29 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02  9:42 [PATCH] mfd: lpc_ich: convert name to const char* Heiner Kallweit
2021-12-29 13:16 ` Lee Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.