]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
format-security: move static strings to const
authorKees Cook <keescook@chromium.org>
Mon, 8 May 2017 22:59:05 +0000 (15:59 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 May 2017 00:15:14 +0000 (17:15 -0700)
While examining output from trial builds with -Wformat-security enabled,
many strings were found that should be defined as "const", or as a char
array instead of char pointer.  This makes some static analysis easier,
by producing fewer false positives.

As these are all trivial changes, it seemed best to put them all in a
single patch rather than chopping them up per maintainer.

Link: http://lkml.kernel.org/r/20170405214711.GA5711@beast
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Jes Sorensen <jes@trained-monkey.org> [runner.c]
Cc: Tony Lindgren <tony@atomide.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Sean Paul <seanpaul@chromium.org>
Cc: David Airlie <airlied@linux.ie>
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Matt Redfearn <matt.redfearn@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Mugunthan V N <mugunthanvnm@ti.com>
Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Jarod Wilson <jarod@redhat.com>
Cc: Florian Westphal <fw@strlen.de>
Cc: Antonio Quartulli <a@unstable.cc>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Kejian Yan <yankejian@huawei.com>
Cc: Daode Huang <huangdaode@hisilicon.com>
Cc: Qianqian Xie <xieqianqian@huawei.com>
Cc: Philippe Reynes <tremyfr@gmail.com>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Christian Gromm <christian.gromm@microchip.com>
Cc: Andrey Shvetsov <andrey.shvetsov@k2l.de>
Cc: Jason Litzinger <jlitzingerdev@gmail.com>
Cc: WANG Cong <xiyou.wangcong@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
19 files changed:
arch/arm/mach-omap2/board-n8x0.c
arch/mips/dec/prom/init.c
arch/mips/kernel/traps.c
drivers/char/dsp56k.c
drivers/cpufreq/powernow-k8.c
drivers/gpu/drm/drm_fb_helper.c
drivers/net/ethernet/amd/atarilance.c
drivers/net/ethernet/amd/declance.c
drivers/net/ethernet/amd/sun3lance.c
drivers/net/ethernet/cirrus/mac89x0.c
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
drivers/net/ethernet/natsemi/sonic.h
drivers/net/ethernet/toshiba/tc35815.c
drivers/net/fddi/defxx.c
drivers/net/hippi/rrunner.c
drivers/staging/most/mostcore/core.c
drivers/tty/n_hdlc.c
drivers/tty/serial/st-asc.c
net/decnet/af_decnet.c

index 6b6fda65fb3b599f6b18704e3648020199aac493..91272db09fa3c26ca9fbbbcfed146e1ce1f5050a 100644 (file)
@@ -117,7 +117,7 @@ static struct musb_hdrc_platform_data tusb_data = {
 static void __init n8x0_usb_init(void)
 {
        int ret = 0;
-       static char     announce[] __initdata = KERN_INFO "TUSB 6010\n";
+       static const char announce[] __initconst = KERN_INFO "TUSB 6010\n";
 
        /* PM companion chip power control pin */
        ret = gpio_request_one(TUSB6010_GPIO_ENABLE, GPIOF_OUT_INIT_LOW,
index 4e1761e0a09af73a8e9477e09e0ce34e7a981a0e..d88eb7a6662b35f118e2e71cfb46e0cbe0953aa8 100644 (file)
@@ -88,7 +88,7 @@ void __init which_prom(s32 magic, s32 *prom_vec)
 void __init prom_init(void)
 {
        extern void dec_machine_halt(void);
-       static char cpu_msg[] __initdata =
+       static const char cpu_msg[] __initconst =
                "Sorry, this kernel is compiled for a wrong CPU type!\n";
        s32 argc = fw_arg0;
        s32 *argv = (void *)fw_arg1;
@@ -111,7 +111,7 @@ void __init prom_init(void)
 #if defined(CONFIG_CPU_R3000)
        if ((current_cpu_type() == CPU_R4000SC) ||
            (current_cpu_type() == CPU_R4400SC)) {
-               static char r4k_msg[] __initdata =
+               static const char r4k_msg[] __initconst =
                        "Please recompile with \"CONFIG_CPU_R4x00 = y\".\n";
                printk(cpu_msg);
                printk(r4k_msg);
@@ -122,7 +122,7 @@ void __init prom_init(void)
 #if defined(CONFIG_CPU_R4X00)
        if ((current_cpu_type() == CPU_R3000) ||
            (current_cpu_type() == CPU_R3000A)) {
-               static char r3k_msg[] __initdata =
+               static const char r3k_msg[] __initconst =
                        "Please recompile with \"CONFIG_CPU_R3000 = y\".\n";
                printk(cpu_msg);
                printk(r3k_msg);
index b49e7bf9f95023fe5837b7d7ed317693ef8ac0a2..9681b5877140112393f414356f110ea74a53a6a1 100644 (file)
@@ -2256,8 +2256,8 @@ void set_handler(unsigned long offset, void *addr, unsigned long size)
        local_flush_icache_range(ebase + offset, ebase + offset + size);
 }
 
-static char panic_null_cerr[] =
-       "Trying to set NULL cache error exception handler";
+static const char panic_null_cerr[] =
+       "Trying to set NULL cache error exception handler\n";
 
 /*
  * Install uncached CPU exception handler.
index 50aa9ba91f255c6a99f1b385ecd065cbc5541d24..0d7b577e0ff0ee5d654b22e3d3bd78644395301b 100644 (file)
@@ -489,7 +489,7 @@ static const struct file_operations dsp56k_fops = {
 
 /****** Init and module functions ******/
 
-static char banner[] __initdata = KERN_INFO "DSP56k driver installed\n";
+static const char banner[] __initconst = KERN_INFO "DSP56k driver installed\n";
 
 static int __init dsp56k_init_driver(void)
 {
index 0b5bf135b0907491a226353f2127cc51c9c13cde..062d71434e470eeb452edcc10417aae7e4d809cc 100644 (file)
@@ -1171,7 +1171,8 @@ static struct cpufreq_driver cpufreq_amd64_driver = {
 
 static void __request_acpi_cpufreq(void)
 {
-       const char *cur_drv, *drv = "acpi-cpufreq";
+       const char drv[] = "acpi-cpufreq";
+       const char *cur_drv;
 
        cur_drv = cpufreq_get_current_driver();
        if (!cur_drv)
index a0ea3241c65117ad056a67c8d3be17af317d80c5..1f178b878e42f01ce667067098cba6b93a6a22e3 100644 (file)
@@ -2446,7 +2446,7 @@ EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
 int __init drm_fb_helper_modinit(void)
 {
 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
-       const char *name = "fbcon";
+       const char name[] = "fbcon";
        struct module *fbcon;
 
        mutex_lock(&module_mutex);
index 796c37a5bbde0d6ba693eddf7b7099884de8ebcc..c5b81268c2849491ba22d26181f4c1b8332526c9 100644 (file)
@@ -42,8 +42,8 @@
 
 */
 
-static char version[] = "atarilance.c: v1.3 04/04/96 "
-                                          "Roman.Hodek@informatik.uni-erlangen.de\n";
+static const char version[] = "atarilance.c: v1.3 04/04/96 "
+                             "Roman.Hodek@informatik.uni-erlangen.de\n";
 
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
index 6c98901f1b8970ae4a41b02a292179262ad38eba..82cc81385033009a0147c8d647808a706a0ddfc3 100644 (file)
@@ -72,7 +72,7 @@
 #include <asm/dec/machtype.h>
 #include <asm/dec/system.h>
 
-static char version[] =
+static const char version[] =
 "declance.c: v0.011 by Linux MIPS DECstation task force\n";
 
 MODULE_AUTHOR("Linux MIPS DECstation task force");
index 12bb4f1489fc0560ff76dbaa5009a35c80a87362..77b1db2677309e639f52c75ecbc96e9e451a7bbb 100644 (file)
@@ -21,7 +21,8 @@
 
 */
 
-static char *version = "sun3lance.c: v1.2 1/12/2001  Sam Creasey (sammy@sammy.net)\n";
+static const char version[] =
+"sun3lance.c: v1.2 1/12/2001  Sam Creasey (sammy@sammy.net)\n";
 
 #include <linux/module.h>
 #include <linux/stddef.h>
index b600fbbbf679885231e7d4cd5a9628a5deb70382..f910f0f386d6321f3c80d0360376d7ea466a2710 100644 (file)
@@ -56,7 +56,7 @@
   local_irq_{dis,en}able()
 */
 
-static char *version =
+static const char version[] =
 "cs89x0.c:v1.02 11/26/96 Russell Nelson <nelson@crynwr.com>\n";
 
 /* ======================= configure the driver here ======================= */
index 24dfba53a0f216c5ce55850b4a5703a1a02772e5..bbc0a98e7ca3260c7f8b1b8cb7f7f203860bfdce 100644 (file)
@@ -405,7 +405,7 @@ struct mac_driver {
 };
 
 struct mac_stats_string {
-       char desc[ETH_GSTRING_LEN];
+       const char desc[ETH_GSTRING_LEN];
        unsigned long offset;
 };
 
index 07091dd27e5df2969592a3faa54f30fdad4a4844..7b0a8db57af93b8d06feec622ff94c36e9183d54 100644 (file)
@@ -444,7 +444,7 @@ static inline __u16 sonic_rra_get(struct net_device* dev, int entry,
                             (entry * SIZEOF_SONIC_RR) + offset);
 }
 
-static const char *version =
+static const char version[] =
     "sonic.c:v0.92 20.9.98 tsbogend@alpha.franken.de\n";
 
 #endif /* SONIC_H */
index 3dadee1080b9e2e541d4b1a335671eb40d8c8205..d9db8a06afd26ef901aa0e5cf559559657ea3179 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #define DRV_VERSION    "1.39"
-static const char *version = "tc35815.c:v" DRV_VERSION "\n";
+static const char version[] = "tc35815.c:v" DRV_VERSION "\n";
 #define MODNAME                        "tc35815"
 
 #include <linux/module.h>
index b0de8ecd7fe8ed8ab030e22da50aef82e283e4b2..f4a816cf012a1b14de57b0da23db07157ce9e927 100644 (file)
 #define DRV_VERSION "v1.11"
 #define DRV_RELDATE "2014/07/01"
 
-static char version[] =
+static const char version[] =
        DRV_NAME ": " DRV_VERSION " " DRV_RELDATE
        "  Lawrence V. Stefani and others\n";
 
index dd7fc6659ad40222f48d29bee637479ebc475322..9b0d6148e994e82e476f1ef315eb7e4a731ddffe 100644 (file)
@@ -60,7 +60,8 @@ MODULE_AUTHOR("Jes Sorensen <jes@wildopensource.com>");
 MODULE_DESCRIPTION("Essential RoadRunner HIPPI driver");
 MODULE_LICENSE("GPL");
 
-static char version[] = "rrunner.c: v0.50 11/11/2002  Jes Sorensen (jes@wildopensource.com)\n";
+static const char version[] =
+"rrunner.c: v0.50 11/11/2002  Jes Sorensen (jes@wildopensource.com)\n";
 
 
 static const struct net_device_ops rr_netdev_ops = {
index 675b2a9e66c1725ba081c9753ff17dd4e234d53b..069269db394ce5104bc7ba263b7181bca9265a71 100644 (file)
@@ -82,7 +82,7 @@ struct most_inst_obj {
 
 static const struct {
        int most_ch_data_type;
-       char *name;
+       const char *name;
 } ch_data_type[] = {
        { MOST_CH_CONTROL, "control\n" },
        { MOST_CH_ASYNC, "async\n" },
index e94aea8c0d0535cbc05933bb02067263e62e8292..7b2a466616d6ef7acb2bc3ce8d773be9e4446375 100644 (file)
@@ -939,11 +939,11 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list)
        return buf;
 }      /* end of n_hdlc_buf_get() */
 
-static char hdlc_banner[] __initdata =
+static const char hdlc_banner[] __initconst =
        KERN_INFO "HDLC line discipline maxframe=%u\n";
-static char hdlc_register_ok[] __initdata =
+static const char hdlc_register_ok[] __initconst =
        KERN_INFO "N_HDLC line discipline registered.\n";
-static char hdlc_register_fail[] __initdata =
+static const char hdlc_register_fail[] __initconst =
        KERN_ERR "error registering line discipline: %d\n";
 
 static int __init n_hdlc_init(void)
@@ -968,9 +968,9 @@ static int __init n_hdlc_init(void)
        
 }      /* end of init_module() */
 
-static char hdlc_unregister_ok[] __exitdata =
+static const char hdlc_unregister_ok[] __exitdata =
        KERN_INFO "N_HDLC: line discipline unregistered\n";
-static char hdlc_unregister_fail[] __exitdata =
+static const char hdlc_unregister_fail[] __exitdata =
        KERN_ERR "N_HDLC: can't unregister line discipline (err = %d)\n";
 
 static void __exit n_hdlc_exit(void)
index c334bcc59c649eedc2933ac29c4dc1ef45ae21d2..a93a3167a9c6f913d434462468a2327a25255d93 100644 (file)
@@ -986,7 +986,7 @@ static struct platform_driver asc_serial_driver = {
 static int __init asc_init(void)
 {
        int ret;
-       static char banner[] __initdata =
+       static const char banner[] __initconst =
                KERN_INFO "STMicroelectronics ASC driver initialized\n";
 
        printk(banner);
index 9afa2a5030b2570c89de8decc3b20aad3a224e5c..405483a07efc7ac2efcfe86e285a7673547c9691 100644 (file)
@@ -2361,7 +2361,8 @@ MODULE_AUTHOR("Linux DECnet Project Team");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_NETPROTO(PF_DECnet);
 
-static char banner[] __initdata = KERN_INFO "NET4: DECnet for Linux: V.2.5.68s (C) 1995-2003 Linux DECnet Project Team\n";
+static const char banner[] __initconst = KERN_INFO
+"NET4: DECnet for Linux: V.2.5.68s (C) 1995-2003 Linux DECnet Project Team\n";
 
 static int __init decnet_init(void)
 {