mtd: add 'const' qualifiers
Subsystems (4)
cover mtd: add 'const' qualifiers
This patch-set amends declarations of arrays of partition parser names, as well as declarations of few MTD functions which deal with such arrays.
The arrays are typically defined as 'const char **probes' or 'const char *probes[]'. The arrays basically "list" names of MTD partition parsers. To put it differently, they are arrays of pointers which point to strings.
The 'const' there means that the strings constant. IOW, probes points to a pointer which points to a constant character).
What we do in this series is we turn the declarations into
'const char * const * probes' or 'const char * const probes[]'. This means that not only the strings are constant, but the pointers pointing to them are also constant. IOW, probes points to a constant pointer which points to a constant character.
The motivation for this work is to make the code a bit stricter, less error prone, and potentially enable the compiler to do more optimizations.
Thanks,
Artem.
PATCH 1/9 mtd: add 'const' qualifier to a couple of register functions
From: Artem Bityutskiy <[email protected]>
'mtd_device_parse_register()' and 'parse_mtd_partitions()' functions accept a an array of character pointers. These functions modify neither the pointers nor the characters they point to. The characters are actually names of the MTD parsers.
At the moment, the argument type is 'const char **', which means that only the names of the parsers are constant. Let's turn the argument type into 'const char * const *', which means that both names and the pointers which point to them are constant.
--- drivers/mtd/mtdcore.c | 2 +- drivers/mtd/mtdcore.h | 3 ++- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-)
drivers/mtd/mtdcore.c +1 -1
@@ -492,7 +492,7 @@ out_error:* * Returns zero in case of success and a negative error code in case of failure. */ -int mtd_device_parse_register (struct mtd_info *mtd,const char **types, +int mtd_device_parse_register (struct mtd_info *mtd,const char *const *types,struct mtd_part_parser_data *parser_data,const struct mtd_partition *parts,int nr_parts)
drivers/mtd/mtdcore.h +2 -1
@@ -15,7 +15,8 @@ extern int del_mtd_device(struct mtd_info *mtd);extern int add_mtd_partitions (struct mtd_info *,const struct mtd_partition *,int );extern int del_mtd_partitions (struct mtd_info *); -extern int parse_mtd_partitions (struct mtd_info *master,const char **types, +extern int parse_mtd_partitions (struct mtd_info *master, +const char *const *types,struct mtd_partition **pparts,struct mtd_part_parser_data *data);
drivers/mtd/mtdpart.c +1 -1
@@ -720,7 +720,7 @@ static const char *default_mtd_part_types[] = {* o a positive number of found partitions, in which case on exit @pparts will * point to an array containing this number of &struct mtd_info objects. */ -int parse_mtd_partitions (struct mtd_info *master,const char **types, +int parse_mtd_partitions (struct mtd_info *master,const char *const *types,struct mtd_partition **pparts,struct mtd_part_parser_data *data) {
include/linux/mtd/mtd.h +4 -4
@@ -362,10 +362,10 @@ struct mtd_partition;struct mtd_part_parser_data ;extern int mtd_device_parse_register (struct mtd_info *mtd, -const char **part_probe_types, -struct mtd_part_parser_data *parser_data, -const struct mtd_partition *defparts, -int defnr_parts); +const char *const *part_probe_types, +struct mtd_part_parser_data *parser_data, +const struct mtd_partition *defparts, +int defnr_parts);#define mtd_device_register (master, parts, nr_parts) \ mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)extern int mtd_device_unregister (struct mtd_info *master);
Signature · 1 line
1.7.10.4
PATCH 2/9 mtd: plat-ram: add const quilifiers
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/maps/plat-ram.c | 2 +- include/linux/mtd/plat-ram.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/maps/plat-ram.c +1 -1
@@ -199,7 +199,7 @@ static int platram_probe(struct platform_device *pdev)* supplied by the platform_data struct */ if (pdata->map_probes) { -const char **map_probes = pdata->map_probes; +const char *const *map_probes = pdata->map_probes;for ( ; !info->mtd && *map_probes; map_probes++) info->mtd =do_map_probe (*map_probes , &info->map);
include/linux/mtd/plat-ram.h +2 -2
@@ -20,8 +20,8 @@struct platdata_mtd_ram {const char *mapname; -const char **map_probes; -const char **probes; +const char *const *map_probes; +const char *const *probes;struct mtd_partition *partitions;int nr_partitions;int bankwidth;
Signature · 1 line
1.7.10.4
PATCH 3/9 mtd: physmap: add const qualifiers
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/maps/physmap.c | 17 +++++++---------- include/linux/mtd/physmap.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-)
drivers/mtd/maps/physmap.c +7 -10
@@ -87,21 +87,18 @@ static void physmap_set_vpp(struct map_info *map, int state)spin_unlock_irqrestore (&info->vpp_lock, flags); } -static const char *rom_probe_types[] = { -"cfi_probe" , -"jedec_probe" , -"qinfo_probe" , -"map_rom" , -NULL }; -static const char *part_probe_types[] = {"cmdlinepart" ,"RedBoot" ,"afs" , -NULL }; +static const char *const rom_probe_types[] = { +"cfi_probe" ,"jedec_probe" ,"qinfo_probe" ,"map_rom" ,NULL }; + +static const char *const part_probe_types[] = { +"cmdlinepart" ,"RedBoot" ,"afs" ,NULL };static int physmap_flash_probe (struct platform_device *dev) {struct physmap_flash_data *physmap_data;struct physmap_flash_info *info; -const char **probe_type; -const char **part_types; +const char *const *probe_type; +const char *const *part_types;int err =0 ;int i;int devices_found =0 ;
include/linux/mtd/physmap.h +1 -1
@@ -30,7 +30,7 @@ struct physmap_flash_data {unsigned int pfow_base;char *probe_type;struct mtd_partition *parts; - const char **part_probe_types; + const char * const *part_probe_types; };#endif /* __LINUX_MTD_PHYSMAP__ */
Signature · 1 line
1.7.10.4
PATCH 4/9 bcma_mips: add a const qualifier
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/bcma/driver_mips.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bcma/driver_mips.c +1 -1
@@ -21,7 +21,7 @@#include <linux/serial_reg.h> #include <linux/time.h> -static const char *part_probes[] = {"bcm47xxpart" ,NULL }; +static const char *const part_probes[] = {"bcm47xxpart" ,NULL };static struct physmap_flash_data bcma_pflash_data = { .part_probe_types = part_probes,
Signature · 1 line
1.7.10.4
PATCH 5/9 ssb: driver_mipscore: add a const qualifier
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/ssb/driver_mipscore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ssb/driver_mipscore.c +1 -1
@@ -18,7 +18,7 @@#include "ssb_private.h" -static const char *part_probes[] = {"bcm47xxpart" ,NULL }; +static const char *const part_probes[] = {"bcm47xxpart" ,NULL };static struct physmap_flash_data ssb_pflash_data = { .part_probe_types = part_probes,
Signature · 1 line
1.7.10.4
PATCH 6/9 mtd: physmap_of: add const qualifiers
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/maps/physmap_of.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/mtd/maps/physmap_of.c +9 -7
@@ -71,6 +71,9 @@ static int of_flash_remove(struct platform_device *dev)return 0 ; } +static const char *const rom_probe_types[] = { +"cfi_probe" ,"jedec_probe" ,"map_rom" }; +/* Helper function to handle probing of the obsolete "direct-mapped" * compatible binding, which has an extra "probe-type" property * describing the type of flash probe necessary. */
@@ -80,8 +83,6 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev,struct device_node *dp = dev->dev.of_node;const char *of_probe;struct mtd_info *mtd; -static const char *rom_probe_types[] - = {"cfi_probe" ,"jedec_probe" ,"map_rom" };int i; dev_warn(&dev->dev, "Device tree uses obsolete \"direct-mapped\" "
@@ -111,9 +112,10 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev,specifies the list of partition probers to use. If none is given then the default is use. These take precedence over other device tree information. */ -static const char *part_probe_types_def[] = {"cmdlinepart" ,"RedBoot" , -"ofpart" ,"ofoldpart" ,NULL }; -static const char **of_get_probes (struct device_node *dp) +static const char *const part_probe_types_def[] = { +"cmdlinepart" ,"RedBoot" ,"ofpart" ,"ofoldpart" ,NULL }; + +static const char *const *of_get_probes (struct device_node *dp) {const char *cp;int cplen;
@@ -142,7 +144,7 @@ static const char **of_get_probes(struct device_node *dp)return res; } -static void of_free_probes (const char **probes) +static void of_free_probes (const char *const *probes) {if (probes != part_probe_types_def)kfree (probes);
@@ -151,7 +153,7 @@ static void of_free_probes(const char **probes)static struct of_device_id of_flash_match[];static int of_flash_probe (struct platform_device *dev) { -const char **part_probe_types; +const char *const *part_probe_types;const struct of_device_id *match;struct device_node *dp = dev->dev.of_node;struct resource res;
Signature · 1 line
1.7.10.4
PATCH 7/9 mtd: maps: add const qualifiers
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/maps/bfin-async-flash.c | 3 ++- drivers/mtd/maps/dc21285.c | 3 +-- drivers/mtd/maps/gpio-addr-flash.c | 3 ++- drivers/mtd/maps/impa7.c | 7 ++----- drivers/mtd/maps/intel_vr_nor.c | 4 ++-- drivers/mtd/maps/ixp4xx.c | 2 +- drivers/mtd/maps/lantiq-flash.c | 3 +-- drivers/mtd/maps/pci.c | 3 +-- drivers/mtd/maps/pxa2xx-flash.c | 4 +--- drivers/mtd/maps/rbtx4939-flash.c | 5 +++-- drivers/mtd/maps/sa1100-flash.c | 2 +- drivers/mtd/maps/solutionengine.c | 2 +- drivers/mtd/maps/tsunami_flash.c | 5 +++-- 13 files changed, 21 insertions(+), 25 deletions(-)
drivers/mtd/maps/bfin-async-flash.c +2 -1
@@ -122,7 +122,8 @@ static void bfin_flash_copy_to(struct map_info *map, unsigned long to, const voiswitch_back (state); } -static const char *part_probe_types[] = {"cmdlinepart" ,"RedBoot" ,NULL }; +static const char *const part_probe_types[] = { +"cmdlinepart" ,"RedBoot" ,NULL };static int bfin_flash_probe (struct platform_device *pdev) {
drivers/mtd/maps/dc21285.c +1 -2
@@ -143,9 +143,8 @@ static struct map_info dc21285_map = { .copy_from = dc21285_copy_from, }; -/* Partition stuff */ -static const char *probes[] = {"RedBoot" ,"cmdlinepart" ,NULL }; +static const char *const probes[] = {"RedBoot" ,"cmdlinepart" ,NULL };static int __init init_dc21285 (void ) {
drivers/mtd/maps/gpio-addr-flash.c +2 -1
@@ -157,7 +157,8 @@ static void gf_copy_to(struct map_info *map, unsigned long to,memcpy_toio (map->virt + (to % state->win_size), from, len); } -static const char *part_probe_types[] = {"cmdlinepart" ,"RedBoot" ,NULL }; +static const char *const part_probe_types[] = { +"cmdlinepart" ,"RedBoot" ,NULL };/** * gpio_flash_probe() - setup a mapping for a GPIO assisted flash
drivers/mtd/maps/impa7.c +2 -5
@@ -24,14 +24,12 @@#define NUM_FLASHBANKS 2#define BUSWIDTH 4 -/* can be { "cfi_probe", "jedec_probe", "map_rom", NULL } */ -#define PROBETYPES { "jedec_probe", NULL } -#define MSG_PREFIX "impA7:"/* prefix for our printk()'s */ #define MTDID "impa7-%d"/* for mtdparts= partitioning */ static struct mtd_info *impa7_mtd[NUM_FLASHBANKS ]; +static const char *const rom_probe_types[] = {"jedec_probe" ,NULL };static struct map_info impa7_map[NUM_FLASHBANKS ] = { {
@@ -60,8 +58,7 @@ static struct mtd_partition partitions[] =static int __init init_impa7 (void ) { -static const char *rom_probe_types[] =PROBETYPES ; -const char **type; +const char *const *type;int i;static struct {u_long addr;u_long size; } pt[NUM_FLASHBANKS ] = { {WINDOW_ADDR0 ,WINDOW_SIZE0 },
drivers/mtd/maps/intel_vr_nor.c +2 -2
@@ -82,9 +82,9 @@ static void vr_nor_destroy_mtd_setup(struct vr_nor_mtd *p)static int vr_nor_mtd_setup (struct vr_nor_mtd *p) { -static const char *probe_types[] = +static const char *const probe_types[] = {"cfi_probe" ,"jedec_probe" ,NULL }; -const char **type; +const char *const *type;for (type = probe_types; !p->info && *type; type++) p->info =do_map_probe (*type, &p->map);
drivers/mtd/maps/ixp4xx.c +1 -1
@@ -148,7 +148,7 @@ struct ixp4xx_flash_info {struct resource *res; }; -static const char *probes[] = {"RedBoot" ,"cmdlinepart" ,NULL }; +static const char *const probes[] = {"RedBoot" ,"cmdlinepart" ,NULL };static int ixp4xx_flash_remove (struct platform_device *dev) {
drivers/mtd/maps/lantiq-flash.c +1 -2
@@ -46,8 +46,7 @@ struct ltq_mtd { };static const char ltq_map_name[] ="ltq_nor" ; -static const char *ltq_probe_types[] = { -"cmdlinepart" ,"ofpart" ,NULL }; +static const char *const ltq_probe_types[] = {"cmdlinepart" ,"ofpart" ,NULL };static map_word ltq_read16 (struct map_info *map,unsigned long adr)
drivers/mtd/maps/pci.c +1 -2
@@ -283,8 +283,7 @@ static int mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)if (err) goto release; -/* tsk - do_map_probe should take const char * */ - mtd =do_map_probe ((char *)info->map_name, &map->map); + mtd =do_map_probe (info->map_name, &map->map); err = -ENODEV ;if (!mtd) goto release;
drivers/mtd/maps/pxa2xx-flash.c +1 -3
@@ -45,9 +45,7 @@ struct pxa2xx_flash_info {struct map_info map; }; - -static const char *probes[] = {"RedBoot" ,"cmdlinepart" ,NULL }; - +static const char *const probes[] = {"RedBoot" ,"cmdlinepart" ,NULL };static int pxa2xx_flash_probe (struct platform_device *pdev) {
drivers/mtd/maps/rbtx4939-flash.c +3 -2
@@ -45,14 +45,15 @@ static int rbtx4939_flash_remove(struct platform_device *dev)return 0 ; } -static const char *rom_probe_types[] = {"cfi_probe" ,"jedec_probe" ,NULL }; +static const char *const rom_probe_types[] = { +"cfi_probe" ,"jedec_probe" ,NULL };static int rbtx4939_flash_probe (struct platform_device *dev) {struct rbtx4939_flash_data *pdata;struct rbtx4939_flash_info *info;struct resource *res; -const char **probe_type; +const char *const *probe_type;int err =0 ;unsigned long size;
drivers/mtd/maps/sa1100-flash.c +1 -1
@@ -244,7 +244,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,return ERR_PTR (ret); } -static const char *part_probes[] = {"cmdlinepart" ,"RedBoot" ,NULL }; +static const char *const part_probes[] = {"cmdlinepart" ,"RedBoot" ,NULL };static int sa1100_mtd_probe (struct platform_device *pdev) {
drivers/mtd/maps/solutionengine.c +1 -1
@@ -31,7 +31,7 @@ struct map_info soleng_flash_map = { .bankwidth = 4, }; -static const char *probes[] = {"RedBoot" ,"cmdlinepart" ,NULL }; +static const char *const probes[] = {"RedBoot" ,"cmdlinepart" ,NULL };#ifdef CONFIG_MTD_SUPERH_RESERVE static struct mtd_partition superh_se_partitions[] = {
drivers/mtd/maps/tsunami_flash.c +3 -2
@@ -82,11 +82,12 @@ static void __exit cleanup_tsunami_flash(void) tsunami_flash_mtd =0 ; } +static const char *const rom_probe_types[] = { +"cfi_probe" ,"jedec_probe" ,"map_rom" ,NULL };static int __init init_tsunami_flash (void ) { -static const char *rom_probe_types[] = {"cfi_probe" ,"jedec_probe" ,"map_rom" ,NULL }; -char **type; +const char *const *type;tsunami_tig_writeb (FLASH_ENABLE_BYTE ,FLASH_ENABLE_PORT );
Signature · 1 line
1.7.10.4
PATCH 8/9 mtd: devices: add const qualifiers
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/devices/bcm47xxsflash.c | 2 +- drivers/mtd/devices/docg3.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/devices/bcm47xxsflash.c +1 -1
@@ -10,7 +10,7 @@MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Serial flash driver for BCMA bus" ); -static const char *probes[] = {"bcm47xxpart" ,NULL }; +static const char *const probes[] = {"bcm47xxpart" ,NULL };static int bcm47xxsflash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf)
drivers/mtd/devices/docg3.c +1 -1
@@ -123,7 +123,7 @@ static inline void doc_flash_address(struct docg3 *docg3, u8 addr)doc_writeb (docg3, addr,DOC_FLASHADDRESS ); } -static char const *part_probes[] = {"cmdlinepart" ,"saftlpart" ,NULL }; +static char const *const part_probes[] = {"cmdlinepart" ,"saftlpart" ,NULL };static int doc_register_readb (struct docg3 *docg3,int reg) {
Signature · 1 line
1.7.10.4
PATCH 9/9 mtd: mtdcore: use const qualifier
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Be a bit stricter and add few more 'const' qualifiers.
--- drivers/mtd/mtdpart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/mtdpart.c +1 -1
@@ -694,7 +694,7 @@ EXPORT_SYMBOL_GPL(deregister_mtd_parser);* Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you * are changing this array! */ -static const char *default_mtd_part_types[] = { +static const char *const default_mtd_part_types[] = {"cmdlinepart" ,"ofpart" ,NULL
Signature · 1 line
1.7.10.4
Artem Bityutskiy
AppliedQuoted 2 lines · Artem Bityutskiy
This patch-set amends declarations of arrays of partition parser names, as well as declarations of few MTD functions which deal with such arrays.
Pushed to l2-mtd.git.
Signature · 2 lines
Best Regards, Artem Bityutskiy