2020-07-01 21:48:39

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 0/5] 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(-)

--
2.27.0


2020-07-01 21:48:51

by Rikard Falkeborn

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

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

Signed-off-by: Rikard Falkeborn <[email protected]>
---
drivers/char/hw_random/virtio-rng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 79a6e47b5fbc..a90001e02bf7 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -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 },
};
--
2.27.0

2020-07-01 21:49:04

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 5/5] virtio_console: Constify some static variables

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

Signed-off-by: Rikard Falkeborn <[email protected]>
---
drivers/char/virtio_console.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 00c5e3acee46..896f0ba9ba3c 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -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
--
2.27.0

2020-07-01 21:49:33

by Rikard Falkeborn

[permalink] [raw]
Subject: [PATCH 4/5] ipmi: watchdog: Constify ident

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

Signed-off-by: Rikard Falkeborn <[email protected]>
---
drivers/char/ipmi/ipmi_watchdog.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 55986e10a124..3df13c3da5f9 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -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"
--
2.27.0

2020-07-01 21:51:38

by Rikard Falkeborn

[permalink] [raw]
Subject: [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

Signed-off-by: Rikard Falkeborn <[email protected]>
---
drivers/char/hw_random/bcm2835-rng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index cbf5eaea662c..0839236a6d19 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -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 */ }
--
2.27.0

2020-07-05 18:31:40

by Amit Shah

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

On (Wed) 01 Jul 2020 [22:09:50], Rikard Falkeborn wrote:
> 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
>
> Signed-off-by: Rikard Falkeborn <[email protected]>

Reviewed-by: Amit Shah <[email protected]>

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

Thanks,

Amit
--
http://amitshah.net/

2020-07-05 20:51:48

by Joe Perches

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

On Sun, 2020-07-05 at 20:30 +0200, Amit Shah wrote:
> On (Wed) 01 Jul 2020 [22:09:50], Rikard Falkeborn wrote:
> > 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
> >
> > Signed-off-by: Rikard Falkeborn <[email protected]>
>
> Reviewed-by: Amit Shah <[email protected]>
>
> 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

Signed-off-by: J. Random Developer <[email protected]>
---

Link: https://lore.kernel.org/r/<message_id_of_cover_letter>

[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


2020-07-09 12:58:22

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 0/5] drivers/char: Constify static variables

On Wed, Jul 01, 2020 at 10:09:45PM +0200, Rikard Falkeborn wrote:
> 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(-)

Patches 1-3 applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt