Skip to contentSkip to conversation

drivers/char: Constify static variables

PATCH In review Rikard Falkeborn 6 participants 12 messages Jul 1, 2020 – Jul 9, 2020

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover drivers/char: Constify static variables

Constify some static variables (mostly structs) that are not modified.

Rikard Falkeborn (5):
hwrng: bcm2835 - Constify bcm2835_rng_devtype[]
hwrng: nomadik - Constify nmk_rng_ids[]
hwrng: virtio - Constify id_table[]
ipmi: watchdog: Constify ident
virtio_console: Constify some static variables

 drivers/char/hw_random/bcm2835-rng.c | 2 +-
 drivers/char/hw_random/nomadik-rng.c | 2 +-
 drivers/char/hw_random/virtio-rng.c  | 2 +-
 drivers/char/ipmi/ipmi_watchdog.c    | 2 +-
 drivers/char/virtio_console.c        | 8 ++++----
 5 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/5 hwrng: bcm2835 - Constify bcm2835_rng_devtype[]

bcm2835_rng_devtype[] is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
2392 176 0 2568 a08 drivers/char/hw_random/bcm2835-rng.o

After:
text data bss dec hex filename
2464 104 0 2568 a08 drivers/char/hw_random/bcm2835-rng.o

---
 drivers/char/hw_random/bcm2835-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/bcm2835-rng.c +1 -1
index cbf5eaea662c..0839236a6d19 100644
@@ -188,7 +188,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
 
 MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match);
 
-static struct platform_device_id bcm2835_rng_devtype[] = {
+static const struct platform_device_id bcm2835_rng_devtype[] = {
 	{ .name = "bcm2835-rng" },
 	{ .name = "bcm63xx-rng" },
 	{ /* sentinel */ }
Signature · 1 line
2.27.0
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] hwrng: bcm2835 - Constify bcm2835_rng_devtype[]

Quoted 7 lines · Rikard Falkeborn

bcm2835_rng_devtype[] is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
2392 176 0 2568 a08 drivers/char/hw_random/bcm2835-rng.o

Quoted 5 lines

After:
text data bss dec hex filename
2464 104 0 2568 a08 drivers/char/hw_random/bcm2835-rng.o

Signature · 1 line
Florian
#3 lore raw

PATCH 2/5 hwrng: nomadik - Constify nmk_rng_ids[]

In reply to Rikard Falkeborn

nmk_rng_ids[] is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:

   text    data     bss     dec     hex filename
    652     216       4     872     368 drivers/char/hw_random/nomadik-rng.o

After:

   text    data     bss     dec     hex filename
    676     192       4     872     368 drivers/char/hw_random/nomadik-rng.o
---
 drivers/char/hw_random/nomadik-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/nomadik-rng.c +1 -1
index 74ed29f42e4f..b0ded41eb865 100644
@@ -76,7 +76,7 @@ static int nmk_rng_remove(struct amba_device *dev)
 	return 0;
 }
 
-static struct amba_id nmk_rng_ids[] = {
+static const struct amba_id nmk_rng_ids[] = {
 	{
 		.id	= 0x000805e1,
 		.mask	= 0x000fffff, /* top bits are rev and cfg: accept all */
Signature · 1 line
2.27.0
maintainer Acked-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] hwrng: nomadik - Constify nmk_rng_ids[]

Quoted 11 lines · Rikard Falkeborn

nmk_rng_ids[] is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:

   text    data     bss     dec     hex filename
    652     216       4     872     368 drivers/char/hw_random/nomadik-rng.o

After:

   text    data     bss     dec     hex filename
    676     192       4     872     368 drivers/char/hw_random/nomadik-rng.o

Moving 24 bytes into the .rodata section is probably not a worth the change, but the patch is correct and I agree this should be .rodata anway.

Quoted 1 line
Quoted 20 lines
---
 drivers/char/hw_random/nomadik-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/nomadik-rng.c +1 -2
index 74ed29f42e4f..b0ded41eb865 100644
@@ -76,7 +76,7 @@ static int nmk_rng_remove(struct amba_device *dev)
        return 0;
 }
 
-static struct amba_id nmk_rng_ids[] = {
+static const struct amba_id nmk_rng_ids[] = {
        {
                .id     = 0x000805e1,
                .mask   = 0x000fffff, /* top bits are rev and cfg: accept all */
--

2.27.0

#5 lore raw

PATCH 3/5 hwrng: virtio - Constify id_table[]

In reply to Rikard Falkeborn

id_table[] is not modified and an be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
1746 192 8 1946 79a drivers/char/hw_random/virtio-rng.o

After:
text data bss dec hex filename
1762 176 8 1946 79a drivers/char/hw_random/virtio-rng.o

---
 drivers/char/hw_random/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/virtio-rng.c +1 -1
index 79a6e47b5fbc..a90001e02bf7 100644
@@ -195,7 +195,7 @@ static int virtrng_restore(struct virtio_device *vdev)
 }
 #endif
 
-static struct virtio_device_id id_table[] = {
+static const struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_RNG, VIRTIO_DEV_ANY_ID },
 	{ 0 },
 };
Signature · 1 line
2.27.0
#6 lore raw

PATCH 4/5 ipmi: watchdog: Constify ident

In reply to Rikard Falkeborn

ident is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
14067 3188 64 17319 43a7 drivers/char/ipmi/ipmi_watchdog.o

After:
text data bss dec hex filename
14115 3148 64 17327 43af drivers/char/ipmi/ipmi_watchdog.o

---
 drivers/char/ipmi/ipmi_watchdog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_watchdog.c +1 -1
index 55986e10a124..3df13c3da5f9 100644
@@ -654,7 +654,7 @@ static int ipmi_heartbeat(void)
 	return rv;
 }
 
-static struct watchdog_info ident = {
+static const struct watchdog_info ident = {
 	.options	= 0,	/* WDIOF_SETTIMEOUT, */
 	.firmware_version = 1,
 	.identity	= "IPMI"
Signature · 1 line
2.27.0
#7 lore raw

PATCH 5/5 virtio_console: Constify some static variables

In reply to Rikard Falkeborn

The id_table and feature_table pointers in struct virtio_driver are pointers to const. Mark the corresponding static variables const to allow the compiler to put them in read-only memory.

Before:
text data bss dec hex filename
25447 713 76 26236 667c drivers/char/virtio_console.o

After:
text data bss dec hex filename
25488 673 76 26237 667d drivers/char/virtio_console.o

---
 drivers/char/virtio_console.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/char/virtio_console.c +4 -4
index 00c5e3acee46..896f0ba9ba3c 100644
@@ -2112,24 +2112,24 @@ static int virtcons_probe(struct virtio_device *vdev)
 	return err;
 }
 
-static struct virtio_device_id id_table[] = {
+static const struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
 	{ 0 },
 };
 
-static unsigned int features[] = {
+static const unsigned int features[] = {
 	VIRTIO_CONSOLE_F_SIZE,
 	VIRTIO_CONSOLE_F_MULTIPORT,
 };
 
-static struct virtio_device_id rproc_serial_id_table[] = {
+static const struct virtio_device_id rproc_serial_id_table[] = {
 #if IS_ENABLED(CONFIG_REMOTEPROC)
 	{ VIRTIO_ID_RPROC_SERIAL, VIRTIO_DEV_ANY_ID },
 #endif
 	{ 0 },
 };
 
-static unsigned int rproc_serial_features[] = {
+static const unsigned int rproc_serial_features[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.27.0
Reviewed-by on v1 5/5
#8 lore raw

Re: [PATCH 5/5] virtio_console: Constify some static variables

Quoted 8 lines · Rikard Falkeborn

The id_table and feature_table pointers in struct virtio_driver are pointers to const. Mark the corresponding static variables const to allow the compiler to put them in read-only memory.

Before:
text data bss dec hex filename
25447 713 76 26236 667c drivers/char/virtio_console.o

Quoted 5 lines

After:
text data bss dec hex filename
25488 673 76 26237 667d drivers/char/virtio_console.o

Please CC me on the entire series instead of individual patches in the future.

Thanks,

Amit

Signature · 1 line
http://amitshah.net/
#9 lore raw

Re: [PATCH 5/5] virtio_console: Constify some static variables

Quoted 13 lines · Amit Shah
Quoted 12 lines · Rikard Falkeborn

The id_table and feature_table pointers in struct virtio_driver are pointers to const. Mark the corresponding static variables const to allow the compiler to put them in read-only memory.

Before:
text data bss dec hex filename
25447 713 76 26236 667c drivers/char/virtio_console.o

After:
text data bss dec hex filename
25488 673 76 26237 667d drivers/char/virtio_console.o

Quoted 6 lines
Quoted 1 line

Please CC me on the entire series instead of individual patches in the future.

CC'ing individual maintainers on entire patch sets that span multiple subsystems doesn't scale.

Given that lore.kernel.org now stores all emails sent to lkml, it's a reasonable thing to add a reference to the cover letter below the --- line to make it easier for individual recipients of patches in a series to find the entire patch set.

i.e. Send emails with something like:

Subject: [PATCH N/M] foo: bar

commit message

---

[patch]

A trivial script to insert these links if all patches in a series are stored in a separate directory:

$ bash insert_cover_letter_link.bash <patch_directory>

---

$ cat insert_cover_letter_link.bash
#!/bin/bash
find $@ -name "*.patch" | sort | \
    while read file ; do

	echo "File: <$file>"
	if [[ $(basename $file) =~ ^0000- ]] ; then
	    message_id=$(grep '^Message-Id: <' $file)
	    if [ $? -ne 0 ] ; then
		echo "Message_Id not found"
		exit 1
	    fi
	    message_id=$(echo $message_id | \
			     sed -r -e 's/^Message-Id:\s*<//' -e 's/>\s*$//')
	    separator="-- "
	    echo "Message_Id: <$message_id>"
	else
	    separator="---"
	fi
	
	if [[ "$message_id" == "" ]] ; then
	    echo "Patch series cover letter Message_Id not found"
	    exit 1
	fi

	perl -n -i -e "if (\$_ =~ /^$separator$/) { print; print \"\\n\"; print \"Link: https://lore.kernel.org/r/\" . '$message_id' . \"\\n\"; print \"\\n\"; } else { print; }" $file

    done

exit 0

maintainer Acked-by on the v1 series
#10 lore raw
In reply to Rikard Falkeborn
Quoted 9 lines · Rikard Falkeborn

Constify some static variables (mostly structs) that are not modified.

Rikard Falkeborn (5):
hwrng: bcm2835 - Constify bcm2835_rng_devtype[]
hwrng: nomadik - Constify nmk_rng_ids[]
hwrng: virtio - Constify id_table[]
ipmi: watchdog: Constify ident
virtio_console: Constify some static variables

I just realized it was a series rather than a single patch I received. They all look correct, so

but if you do more of those, I would suggest not including the 'size' output for the small variables as that is not the main point here.

maintainer
#11 lore raw
In reply to Rikard Falkeborn
Quoted 9 lines · Rikard Falkeborn

Constify some static variables (mostly structs) that are not modified.

Rikard Falkeborn (5):
hwrng: bcm2835 - Constify bcm2835_rng_devtype[]
hwrng: nomadik - Constify nmk_rng_ids[]
hwrng: virtio - Constify id_table[]
ipmi: watchdog: Constify ident
virtio_console: Constify some static variables

Quoted 6 lines
 drivers/char/hw_random/bcm2835-rng.c | 2 +-
 drivers/char/hw_random/nomadik-rng.c | 2 +-
 drivers/char/hw_random/virtio-rng.c  | 2 +-
 drivers/char/ipmi/ipmi_watchdog.c    | 2 +-
 drivers/char/virtio_console.c        | 8 ++++----
 5 files changed, 8 insertions(+), 8 deletions(-)

Patches 1-3 applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt