diff mbox series

memstick: Constify struct memstick_device_id

Message ID 6509d6f6ed64193f04e747a98ccea7492c976ca8.1727540434.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series memstick: Constify struct memstick_device_id | expand

Commit Message

Christophe JAILLET Sept. 28, 2024, 4:20 p.m. UTC
'struct memstick_device_id' are not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increases overall security.

Update memstick_dev_match(), memstick_bus_match() and struct
memstick_driver accordingly.

On a x86_64, with allmodconfig, as an example:
Before:
======
   text	   data	    bss	    dec	    hex	filename
  74055	   3455	     88	  77598	  12f1e	drivers/memstick/core/ms_block.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
  74087	   3423	     88	  77598	  12f1e	drivers/memstick/core/ms_block.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/memstick/core/memstick.c    | 4 ++--
 drivers/memstick/core/ms_block.c    | 2 +-
 drivers/memstick/core/mspro_block.c | 2 +-
 include/linux/memstick.h            | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

Comments

Ulf Hansson Oct. 8, 2024, 2:35 p.m. UTC | #1
On Sat, 28 Sept 2024 at 18:21, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 'struct memstick_device_id' are not modified in these drivers.
>
> Constifying this structure moves some data to a read-only section, so
> increases overall security.
>
> Update memstick_dev_match(), memstick_bus_match() and struct
> memstick_driver accordingly.
>
> On a x86_64, with allmodconfig, as an example:
> Before:
> ======
>    text    data     bss     dec     hex filename
>   74055    3455      88   77598   12f1e drivers/memstick/core/ms_block.o
>
> After:
> =====
>    text    data     bss     dec     hex filename
>   74087    3423      88   77598   12f1e drivers/memstick/core/ms_block.o
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied for next, thanks!

Kind regards
Uffe


> ---
> Compile tested only
> ---
>  drivers/memstick/core/memstick.c    | 4 ++--
>  drivers/memstick/core/ms_block.c    | 2 +-
>  drivers/memstick/core/mspro_block.c | 2 +-
>  include/linux/memstick.h            | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
> index 9a3a784054cc..ae4e8b8e6eb7 100644
> --- a/drivers/memstick/core/memstick.c
> +++ b/drivers/memstick/core/memstick.c
> @@ -26,7 +26,7 @@ static DEFINE_IDR(memstick_host_idr);
>  static DEFINE_SPINLOCK(memstick_host_lock);
>
>  static int memstick_dev_match(struct memstick_dev *card,
> -                             struct memstick_device_id *id)
> +                             const struct memstick_device_id *id)
>  {
>         if (id->match_flags & MEMSTICK_MATCH_ALL) {
>                 if ((id->type == card->id.type)
> @@ -44,7 +44,7 @@ static int memstick_bus_match(struct device *dev, const struct device_driver *dr
>                                                  dev);
>         const struct memstick_driver *ms_drv = container_of_const(drv, struct memstick_driver,
>                                                                   driver);
> -       struct memstick_device_id *ids = ms_drv->id_table;
> +       const struct memstick_device_id *ids = ms_drv->id_table;
>
>         if (ids) {
>                 while (ids->match_flags) {
> diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> index 47a314a4eb6f..c572f870fcf1 100644
> --- a/drivers/memstick/core/ms_block.c
> +++ b/drivers/memstick/core/ms_block.c
> @@ -2279,7 +2279,7 @@ static int msb_resume(struct memstick_dev *card)
>
>  #endif /* CONFIG_PM */
>
> -static struct memstick_device_id msb_id_tbl[] = {
> +static const struct memstick_device_id msb_id_tbl[] = {
>         {MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_LEGACY, MEMSTICK_CATEGORY_STORAGE,
>          MEMSTICK_CLASS_FLASH},
>
> diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
> index 49accfdc89d6..13b317c56069 100644
> --- a/drivers/memstick/core/mspro_block.c
> +++ b/drivers/memstick/core/mspro_block.c
> @@ -1349,7 +1349,7 @@ static int mspro_block_resume(struct memstick_dev *card)
>
>  #endif /* CONFIG_PM */
>
> -static struct memstick_device_id mspro_block_id_tbl[] = {
> +static const struct memstick_device_id mspro_block_id_tbl[] = {
>         {MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_PRO, MEMSTICK_CATEGORY_STORAGE_DUO,
>          MEMSTICK_CLASS_DUO},
>         {}
> diff --git a/include/linux/memstick.h b/include/linux/memstick.h
> index ebf73d4ee969..107bdcbedf79 100644
> --- a/include/linux/memstick.h
> +++ b/include/linux/memstick.h
> @@ -293,7 +293,7 @@ struct memstick_host {
>  };
>
>  struct memstick_driver {
> -       struct memstick_device_id *id_table;
> +       const struct memstick_device_id *id_table;
>         int                       (*probe)(struct memstick_dev *card);
>         void                      (*remove)(struct memstick_dev *card);
>         int                       (*suspend)(struct memstick_dev *card,
> --
> 2.46.2
>
diff mbox series

Patch

diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 9a3a784054cc..ae4e8b8e6eb7 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -26,7 +26,7 @@  static DEFINE_IDR(memstick_host_idr);
 static DEFINE_SPINLOCK(memstick_host_lock);
 
 static int memstick_dev_match(struct memstick_dev *card,
-			      struct memstick_device_id *id)
+			      const struct memstick_device_id *id)
 {
 	if (id->match_flags & MEMSTICK_MATCH_ALL) {
 		if ((id->type == card->id.type)
@@ -44,7 +44,7 @@  static int memstick_bus_match(struct device *dev, const struct device_driver *dr
 						 dev);
 	const struct memstick_driver *ms_drv = container_of_const(drv, struct memstick_driver,
 								  driver);
-	struct memstick_device_id *ids = ms_drv->id_table;
+	const struct memstick_device_id *ids = ms_drv->id_table;
 
 	if (ids) {
 		while (ids->match_flags) {
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 47a314a4eb6f..c572f870fcf1 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -2279,7 +2279,7 @@  static int msb_resume(struct memstick_dev *card)
 
 #endif /* CONFIG_PM */
 
-static struct memstick_device_id msb_id_tbl[] = {
+static const struct memstick_device_id msb_id_tbl[] = {
 	{MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_LEGACY, MEMSTICK_CATEGORY_STORAGE,
 	 MEMSTICK_CLASS_FLASH},
 
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 49accfdc89d6..13b317c56069 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -1349,7 +1349,7 @@  static int mspro_block_resume(struct memstick_dev *card)
 
 #endif /* CONFIG_PM */
 
-static struct memstick_device_id mspro_block_id_tbl[] = {
+static const struct memstick_device_id mspro_block_id_tbl[] = {
 	{MEMSTICK_MATCH_ALL, MEMSTICK_TYPE_PRO, MEMSTICK_CATEGORY_STORAGE_DUO,
 	 MEMSTICK_CLASS_DUO},
 	{}
diff --git a/include/linux/memstick.h b/include/linux/memstick.h
index ebf73d4ee969..107bdcbedf79 100644
--- a/include/linux/memstick.h
+++ b/include/linux/memstick.h
@@ -293,7 +293,7 @@  struct memstick_host {
 };
 
 struct memstick_driver {
-	struct memstick_device_id *id_table;
+	const struct memstick_device_id *id_table;
 	int                       (*probe)(struct memstick_dev *card);
 	void                      (*remove)(struct memstick_dev *card);
 	int                       (*suspend)(struct memstick_dev *card,