Lots of char arrays could be set as const since they contain only literal
char arrays.
We could in the same time make const some struct members who are pointer
to those const char arrays.
Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/char/ipmi/ipmi_msghandler.c | 7 ++++---
drivers/char/ipmi/ipmi_si_intf.c | 29 +++++++++++++++++------------
2 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e3536da..94fb407 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -472,9 +472,10 @@ static DEFINE_MUTEX(smi_watchers_mutex);
#define ipmi_get_stat(intf, stat) \
((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
-static char *addr_src_to_str[] = { "invalid", "hotmod", "hardcoded", "SPMI",
- "ACPI", "SMBIOS", "PCI",
- "device-tree", "default" };
+static const char * const addr_src_to_str[] = {
+ "invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI",
+ "device-tree", "default"
+};
const char *ipmi_addr_src_to_str(enum ipmi_addr_src src)
{
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 654f6f3..cc37fba 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -105,7 +105,8 @@ enum si_intf_state {
enum si_type {
SI_KCS, SI_SMIC, SI_BT
};
-static char *si_to_str[] = { "kcs", "smic", "bt" };
+
+static const char * const si_to_str[] = { "kcs", "smic", "bt" };
#define DEVICE_NAME "ipmi_si"
@@ -1319,7 +1320,7 @@ static unsigned int num_slave_addrs;
#define IPMI_IO_ADDR_SPACE 0
#define IPMI_MEM_ADDR_SPACE 1
-static char *addr_space_to_str[] = { "i/o", "mem" };
+static const char * const addr_space_to_str[] = { "i/o", "mem" };
static int hotmod_handler(const char *val, struct kernel_param *kp);
@@ -1701,27 +1702,31 @@ static int mem_setup(struct smi_info *info)
*/
enum hotmod_op { HM_ADD, HM_REMOVE };
struct hotmod_vals {
- char *name;
- int val;
+ const char *name;
+ const int val;
};
-static struct hotmod_vals hotmod_ops[] = {
+
+static const struct hotmod_vals hotmod_ops[] = {
{ "add", HM_ADD },
{ "remove", HM_REMOVE },
{ NULL }
};
-static struct hotmod_vals hotmod_si[] = {
+
+static const struct hotmod_vals hotmod_si[] = {
{ "kcs", SI_KCS },
{ "smic", SI_SMIC },
{ "bt", SI_BT },
{ NULL }
};
-static struct hotmod_vals hotmod_as[] = {
+
+static const struct hotmod_vals hotmod_as[] = {
{ "mem", IPMI_MEM_ADDR_SPACE },
{ "i/o", IPMI_IO_ADDR_SPACE },
{ NULL }
};
-static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
+static int parse_str(const struct hotmod_vals *v, int *val, char *name,
+ char **curr)
{
char *s;
int i;
@@ -2848,12 +2853,12 @@ static int ipmi_parisc_remove(struct parisc_device *dev)
return 0;
}
-static struct parisc_device_id ipmi_parisc_tbl[] = {
+static const struct parisc_device_id ipmi_parisc_tbl[] = {
{ HPHW_MC, HVERSION_REV_ANY_ID, 0x004, 0xC0 },
{ 0, }
};
-static struct parisc_driver ipmi_parisc_driver = {
+static const struct parisc_driver ipmi_parisc_driver = {
.name = "ipmi",
.id_table = ipmi_parisc_tbl,
.probe = ipmi_parisc_probe,
@@ -3422,8 +3427,8 @@ static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
static const struct ipmi_default_vals
{
- int type;
- int port;
+ const int type;
+ const int port;
} ipmi_defaults[] =
{
{ .type = SI_KCS, .port = 0xca2 },
--
2.4.10
Hi LABBE,
[auto build test WARNING on: char-misc/char-misc-next]
[also build test WARNING on: v4.3 next-20151105]
url: https://github.com/0day-ci/linux/commits/LABBE-Corentin/ipmi-constify-some-struct-and-char-arrays/20151105-173339
config: parisc-generic-64bit_defconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=parisc
All warnings (new ones prefixed by >>):
drivers/char/ipmi/ipmi_si_intf.c: In function 'init_ipmi_si':
>> drivers/char/ipmi/ipmi_si_intf.c:3809:2: warning: passing argument 1 of 'register_parisc_driver' discards 'const' qualifier from pointer target type
register_parisc_driver(&ipmi_parisc_driver);
^
In file included from arch/parisc/include/asm/processor.h:15:0,
from arch/parisc/include/asm/spinlock.h:6,
from arch/parisc/include/asm/atomic.h:21,
from include/linux/atomic.h:4,
from arch/parisc/include/asm/bitops.h:12,
from include/linux/bitops.h:36,
from include/linux/kernel.h:10,
from include/linux/list.h:8,
from include/linux/module.h:9,
from drivers/char/ipmi/ipmi_si_intf.c:42:
arch/parisc/include/asm/hardware.h:110:12: note: expected 'struct parisc_driver *' but argument is of type 'const struct parisc_driver *'
extern int register_parisc_driver(struct parisc_driver *driver);
^
drivers/char/ipmi/ipmi_si_intf.c: In function 'cleanup_ipmi_si':
>> drivers/char/ipmi/ipmi_si_intf.c:3951:3: warning: passing argument 1 of 'unregister_parisc_driver' discards 'const' qualifier from pointer target type
unregister_parisc_driver(&ipmi_parisc_driver);
^
In file included from arch/parisc/include/asm/processor.h:15:0,
from arch/parisc/include/asm/spinlock.h:6,
from arch/parisc/include/asm/atomic.h:21,
from include/linux/atomic.h:4,
from arch/parisc/include/asm/bitops.h:12,
from include/linux/bitops.h:36,
from include/linux/kernel.h:10,
from include/linux/list.h:8,
from include/linux/module.h:9,
from drivers/char/ipmi/ipmi_si_intf.c:42:
arch/parisc/include/asm/hardware.h:112:12: note: expected 'struct parisc_driver *' but argument is of type 'const struct parisc_driver *'
extern int unregister_parisc_driver(struct parisc_driver *driver);
^
vim +3809 drivers/char/ipmi/ipmi_si_intf.c
754d45318 Matthew Garrett 2010-05-26 3803 #ifdef CONFIG_ACPI
d941aeae4 Corey Minyard 2013-02-27 3804 if (si_tryacpi)
754d45318 Matthew Garrett 2010-05-26 3805 spmi_find_bmc();
754d45318 Matthew Garrett 2010-05-26 3806 #endif
754d45318 Matthew Garrett 2010-05-26 3807
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3808 #ifdef CONFIG_PARISC
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 @3809 register_parisc_driver(&ipmi_parisc_driver);
7aefac26f Corey Minyard 2014-04-14 3810 parisc_registered = true;
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3811 /* poking PC IO addresses will crash machine, don't do it */
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3812 si_trydefaults = 0;
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3813 #endif
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3814
06ee45940 Matthew Garrett 2010-05-26 3815 /* We prefer devices with interrupts, but in the case of a machine
06ee45940 Matthew Garrett 2010-05-26 3816 with multiple BMCs we assume that there will be several instances
06ee45940 Matthew Garrett 2010-05-26 3817 of a given type so if we succeed in registering a type then also
06ee45940 Matthew Garrett 2010-05-26 3818 try to register everything else of the same type */
d8cc5267b Matthew Garrett 2010-05-26 3819
2407d77a1 Matthew Garrett 2010-05-26 3820 mutex_lock(&smi_infos_lock);
2407d77a1 Matthew Garrett 2010-05-26 3821 list_for_each_entry(e, &smi_infos, link) {
06ee45940 Matthew Garrett 2010-05-26 3822 /* Try to register a device if it has an IRQ and we either
06ee45940 Matthew Garrett 2010-05-26 3823 haven't successfully registered a device yet or this
06ee45940 Matthew Garrett 2010-05-26 3824 device has the same type as one we successfully registered */
06ee45940 Matthew Garrett 2010-05-26 3825 if (e->irq && (!type || e->addr_source == type)) {
d8cc5267b Matthew Garrett 2010-05-26 3826 if (!try_smi_init(e)) {
06ee45940 Matthew Garrett 2010-05-26 3827 type = e->addr_source;
06ee45940 Matthew Garrett 2010-05-26 3828 }
d8cc5267b Matthew Garrett 2010-05-26 3829 }
d8cc5267b Matthew Garrett 2010-05-26 3830 }
06ee45940 Matthew Garrett 2010-05-26 3831
06ee45940 Matthew Garrett 2010-05-26 3832 /* type will only have been set if we successfully registered an si */
06ee45940 Matthew Garrett 2010-05-26 3833 if (type) {
06ee45940 Matthew Garrett 2010-05-26 3834 mutex_unlock(&smi_infos_lock);
06ee45940 Matthew Garrett 2010-05-26 3835 return 0;
d8cc5267b Matthew Garrett 2010-05-26 3836 }
d8cc5267b Matthew Garrett 2010-05-26 3837
d8cc5267b Matthew Garrett 2010-05-26 3838 /* Fall back to the preferred device */
d8cc5267b Matthew Garrett 2010-05-26 3839
d8cc5267b Matthew Garrett 2010-05-26 3840 list_for_each_entry(e, &smi_infos, link) {
06ee45940 Matthew Garrett 2010-05-26 3841 if (!e->irq && (!type || e->addr_source == type)) {
d8cc5267b Matthew Garrett 2010-05-26 3842 if (!try_smi_init(e)) {
06ee45940 Matthew Garrett 2010-05-26 3843 type = e->addr_source;
d8cc5267b Matthew Garrett 2010-05-26 3844 }
d8cc5267b Matthew Garrett 2010-05-26 3845 }
2407d77a1 Matthew Garrett 2010-05-26 3846 }
2407d77a1 Matthew Garrett 2010-05-26 3847 mutex_unlock(&smi_infos_lock);
2407d77a1 Matthew Garrett 2010-05-26 3848
06ee45940 Matthew Garrett 2010-05-26 3849 if (type)
06ee45940 Matthew Garrett 2010-05-26 3850 return 0;
06ee45940 Matthew Garrett 2010-05-26 3851
b0defcdbd Corey Minyard 2006-03-26 3852 if (si_trydefaults) {
d6dfd1310 Corey Minyard 2006-03-31 3853 mutex_lock(&smi_infos_lock);
b0defcdbd Corey Minyard 2006-03-26 3854 if (list_empty(&smi_infos)) {
b0defcdbd Corey Minyard 2006-03-26 3855 /* No BMC was found, try defaults. */
d6dfd1310 Corey Minyard 2006-03-31 3856 mutex_unlock(&smi_infos_lock);
b0defcdbd Corey Minyard 2006-03-26 3857 default_find_bmc();
2407d77a1 Matthew Garrett 2010-05-26 3858 } else
d6dfd1310 Corey Minyard 2006-03-31 3859 mutex_unlock(&smi_infos_lock);
b0defcdbd Corey Minyard 2006-03-26 3860 }
^1da177e4 Linus Torvalds 2005-04-16 3861
d6dfd1310 Corey Minyard 2006-03-31 3862 mutex_lock(&smi_infos_lock);
b361e27bb Corey Minyard 2006-12-06 3863 if (unload_when_empty && list_empty(&smi_infos)) {
d6dfd1310 Corey Minyard 2006-03-31 3864 mutex_unlock(&smi_infos_lock);
d2478521a Corey Minyard 2011-02-10 3865 cleanup_ipmi_si();
279fbd0c5 Myron Stowe 2010-05-26 3866 printk(KERN_WARNING PFX
279fbd0c5 Myron Stowe 2010-05-26 3867 "Unable to find any System Interface(s)\n");
^1da177e4 Linus Torvalds 2005-04-16 3868 return -ENODEV;
b0defcdbd Corey Minyard 2006-03-26 3869 } else {
d6dfd1310 Corey Minyard 2006-03-31 3870 mutex_unlock(&smi_infos_lock);
^1da177e4 Linus Torvalds 2005-04-16 3871 return 0;
^1da177e4 Linus Torvalds 2005-04-16 3872 }
b0defcdbd Corey Minyard 2006-03-26 3873 }
^1da177e4 Linus Torvalds 2005-04-16 3874 module_init(init_ipmi_si);
^1da177e4 Linus Torvalds 2005-04-16 3875
b361e27bb Corey Minyard 2006-12-06 3876 static void cleanup_one_si(struct smi_info *to_clean)
^1da177e4 Linus Torvalds 2005-04-16 3877 {
2407d77a1 Matthew Garrett 2010-05-26 3878 int rv = 0;
^1da177e4 Linus Torvalds 2005-04-16 3879
^1da177e4 Linus Torvalds 2005-04-16 3880 if (!to_clean)
^1da177e4 Linus Torvalds 2005-04-16 3881 return;
^1da177e4 Linus Torvalds 2005-04-16 3882
b874b985c Corey Minyard 2014-11-06 3883 if (to_clean->intf) {
b874b985c Corey Minyard 2014-11-06 3884 ipmi_smi_t intf = to_clean->intf;
b874b985c Corey Minyard 2014-11-06 3885
b874b985c Corey Minyard 2014-11-06 3886 to_clean->intf = NULL;
b874b985c Corey Minyard 2014-11-06 3887 rv = ipmi_unregister_smi(intf);
b874b985c Corey Minyard 2014-11-06 3888 if (rv) {
b874b985c Corey Minyard 2014-11-06 3889 pr_err(PFX "Unable to unregister device: errno=%d\n",
b874b985c Corey Minyard 2014-11-06 3890 rv);
b874b985c Corey Minyard 2014-11-06 3891 }
b874b985c Corey Minyard 2014-11-06 3892 }
b874b985c Corey Minyard 2014-11-06 3893
567eded96 Takao Indoh 2014-10-06 3894 if (to_clean->dev)
567eded96 Takao Indoh 2014-10-06 3895 dev_set_drvdata(to_clean->dev, NULL);
567eded96 Takao Indoh 2014-10-06 3896
b0defcdbd Corey Minyard 2006-03-26 3897 list_del(&to_clean->link);
b0defcdbd Corey Minyard 2006-03-26 3898
c305e3d38 Corey Minyard 2008-04-29 3899 /*
b874b985c Corey Minyard 2014-11-06 3900 * Make sure that interrupts, the timer and the thread are
b874b985c Corey Minyard 2014-11-06 3901 * stopped and will not run again.
c305e3d38 Corey Minyard 2008-04-29 3902 */
b874b985c Corey Minyard 2014-11-06 3903 if (to_clean->irq_cleanup)
b874b985c Corey Minyard 2014-11-06 3904 to_clean->irq_cleanup(to_clean);
a9a2c44ff Corey Minyard 2005-11-07 3905 wait_for_timer_and_thread(to_clean);
^1da177e4 Linus Torvalds 2005-04-16 3906
c305e3d38 Corey Minyard 2008-04-29 3907 /*
c305e3d38 Corey Minyard 2008-04-29 3908 * Timeouts are stopped, now make sure the interrupts are off
b874b985c Corey Minyard 2014-11-06 3909 * in the BMC. Note that timers and CPU interrupts are off,
b874b985c Corey Minyard 2014-11-06 3910 * so no need for locks.
c305e3d38 Corey Minyard 2008-04-29 3911 */
ee6cd5f8f Corey Minyard 2007-05-08 3912 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
ee6cd5f8f Corey Minyard 2007-05-08 3913 poll(to_clean);
ee6cd5f8f Corey Minyard 2007-05-08 3914 schedule_timeout_uninterruptible(1);
ee6cd5f8f Corey Minyard 2007-05-08 3915 }
ee6cd5f8f Corey Minyard 2007-05-08 3916 disable_si_irq(to_clean);
e8b336173 Corey Minyard 2005-09-06 3917 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
^1da177e4 Linus Torvalds 2005-04-16 3918 poll(to_clean);
da4cd8dfe Nishanth Aravamudan 2005-09-10 3919 schedule_timeout_uninterruptible(1);
^1da177e4 Linus Torvalds 2005-04-16 3920 }
^1da177e4 Linus Torvalds 2005-04-16 3921
2407d77a1 Matthew Garrett 2010-05-26 3922 if (to_clean->handlers)
^1da177e4 Linus Torvalds 2005-04-16 3923 to_clean->handlers->cleanup(to_clean->si_sm);
^1da177e4 Linus Torvalds 2005-04-16 3924
^1da177e4 Linus Torvalds 2005-04-16 3925 kfree(to_clean->si_sm);
^1da177e4 Linus Torvalds 2005-04-16 3926
b0defcdbd Corey Minyard 2006-03-26 3927 if (to_clean->addr_source_cleanup)
b0defcdbd Corey Minyard 2006-03-26 3928 to_clean->addr_source_cleanup(to_clean);
7767e126c Paolo Galtieri 2005-12-15 3929 if (to_clean->io_cleanup)
^1da177e4 Linus Torvalds 2005-04-16 3930 to_clean->io_cleanup(to_clean);
50c812b2b Corey Minyard 2006-03-26 3931
50c812b2b Corey Minyard 2006-03-26 3932 if (to_clean->dev_registered)
50c812b2b Corey Minyard 2006-03-26 3933 platform_device_unregister(to_clean->pdev);
50c812b2b Corey Minyard 2006-03-26 3934
50c812b2b Corey Minyard 2006-03-26 3935 kfree(to_clean);
^1da177e4 Linus Torvalds 2005-04-16 3936 }
^1da177e4 Linus Torvalds 2005-04-16 3937
0dcf334c4 Sergey Senozhatsky 2011-03-23 3938 static void cleanup_ipmi_si(void)
^1da177e4 Linus Torvalds 2005-04-16 3939 {
b0defcdbd Corey Minyard 2006-03-26 3940 struct smi_info *e, *tmp_e;
^1da177e4 Linus Torvalds 2005-04-16 3941
^1da177e4 Linus Torvalds 2005-04-16 3942 if (!initialized)
^1da177e4 Linus Torvalds 2005-04-16 3943 return;
^1da177e4 Linus Torvalds 2005-04-16 3944
b0defcdbd Corey Minyard 2006-03-26 3945 #ifdef CONFIG_PCI
56480287f Matthew Garrett 2010-06-29 3946 if (pci_registered)
b0defcdbd Corey Minyard 2006-03-26 3947 pci_unregister_driver(&ipmi_pci_driver);
b0defcdbd Corey Minyard 2006-03-26 3948 #endif
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3949 #ifdef CONFIG_PARISC
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3950 if (parisc_registered)
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 @3951 unregister_parisc_driver(&ipmi_parisc_driver);
fdbeb7de7 Thomas Bogendoerfer 2013-09-05 3952 #endif
b0defcdbd Corey Minyard 2006-03-26 3953
a1e9c9dd3 Rob Herring 2011-02-23 3954 platform_driver_unregister(&ipmi_driver);
:::::: The code at line 3809 was first introduced by commit
:::::: fdbeb7de700a3c8fc85d7e595a6bf1c92a27c0a1 BMC support for PARISC machines
:::::: TO: Thomas Bogendoerfer <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation