[U-Boot] [PATCH 2/3] mmc: Convert mmc struct's name array to a pointer

Pantelis Antoniou panto at antoniou-consulting.com
Wed Mar 12 11:24:26 CET 2014


Using an array is pointless; even more pointless (and scary) is using
sprintf to fill it without a format string.

Signed-off-by: Pantelis Antoniou <panto at antoniou-consulting.com>
---
 drivers/mmc/arm_pl180_mmci.c | 2 +-
 drivers/mmc/bfin_sdh.c       | 2 +-
 drivers/mmc/davinci_mmc.c    | 2 +-
 drivers/mmc/dw_mmc.c         | 2 +-
 drivers/mmc/fsl_esdhc.c      | 2 +-
 drivers/mmc/ftsdc010_mci.c   | 2 +-
 drivers/mmc/gen_atmel_mci.c  | 2 +-
 drivers/mmc/mmc_spi.c        | 2 +-
 drivers/mmc/mxcmmc.c         | 2 +-
 drivers/mmc/mxsmmc.c         | 2 +-
 drivers/mmc/omap_hsmmc.c     | 2 +-
 drivers/mmc/pxa_mmc_gen.c    | 2 +-
 drivers/mmc/sdhci.c          | 2 +-
 drivers/mmc/sh_mmcif.c       | 2 +-
 drivers/mmc/tegra_mmc.c      | 2 +-
 include/mmc.h                | 2 +-
 16 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/arm_pl180_mmci.c b/drivers/mmc/arm_pl180_mmci.c
index 4490e97..5a30590 100644
--- a/drivers/mmc/arm_pl180_mmci.c
+++ b/drivers/mmc/arm_pl180_mmci.c
@@ -365,7 +365,7 @@ int arm_pl180_mmci_init(struct pl180_mmc_host *host)
 	/* Disable mmc interrupts */
 	sdi_u32 = readl(&host->base->mask0) & ~SDI_MASK0_MASK;
 	writel(sdi_u32, &host->base->mask0);
-	strncpy(dev->name, host->name, sizeof(dev->name));
+	dev->name = host->name;
 	dev->ops = &arm_pl180_mmci_ops;
 	dev->host_caps = host->caps;
 	dev->voltages = host->voltages;
diff --git a/drivers/mmc/bfin_sdh.c b/drivers/mmc/bfin_sdh.c
index f0871ec..5f6145b 100644
--- a/drivers/mmc/bfin_sdh.c
+++ b/drivers/mmc/bfin_sdh.c
@@ -288,7 +288,7 @@ int bfin_mmc_init(bd_t *bis)
 
 	if (!mmc)
 		return -ENOMEM;
-	sprintf(mmc->name, "Blackfin SDH");
+	mmc->name = "Blackfin SDH";
 	mmc->ops = &bfin_mmc_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
diff --git a/drivers/mmc/davinci_mmc.c b/drivers/mmc/davinci_mmc.c
index 29ca4a6..cae972a 100644
--- a/drivers/mmc/davinci_mmc.c
+++ b/drivers/mmc/davinci_mmc.c
@@ -379,7 +379,7 @@ int davinci_mmc_init(bd_t *bis, struct davinci_mmc *host)
 	mmc = malloc(sizeof(struct mmc));
 	memset(mmc, 0, sizeof(struct mmc));
 
-	sprintf(mmc->name, "davinci");
+	mmc->name = "davinci";
 	mmc->priv = host;
 	mmc->ops = &dmmc_ops;
 	mmc->f_min = 200000;
diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 2e6576e..011efb1 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -363,7 +363,7 @@ int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
 	mmc->priv = host;
 	host->mmc = mmc;
 
-	sprintf(mmc->name, "%s", host->name);
+	mmc->name = host->name;
 	mmc->ops = &dwmci_ops;
 	mmc->f_min = min_clk;
 	mmc->f_max = max_clk;
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index 861f536..f66513e 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -545,7 +545,7 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 		return -ENOMEM;
 
 	memset(mmc, 0, sizeof(struct mmc));
-	sprintf(mmc->name, "FSL_SDHC");
+	mmc->name = "FSL_SDHC";
 	regs = (struct fsl_esdhc *)cfg->esdhc_base;
 
 	/* First reset the eSDHC controller */
diff --git a/drivers/mmc/ftsdc010_mci.c b/drivers/mmc/ftsdc010_mci.c
index ce43ae1..b1673fc 100644
--- a/drivers/mmc/ftsdc010_mci.c
+++ b/drivers/mmc/ftsdc010_mci.c
@@ -352,7 +352,7 @@ int ftsdc010_mmc_init(int devid)
 	chip->regs = regs;
 	mmc->priv  = chip;
 
-	sprintf(mmc->name, "ftsdc010");
+	mmc->name = "ftsdc010";
 	mmc->ops = &ftsdc010_ops;
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz;
 	switch (readl(&regs->bwr) & FTSDC010_BWR_CAPS_MASK) {
diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
index 456f8bf..ce799f3 100644
--- a/drivers/mmc/gen_atmel_mci.c
+++ b/drivers/mmc/gen_atmel_mci.c
@@ -364,7 +364,7 @@ int atmel_mci_init(void *regs)
 	if (!mmc)
 		return -1;
 
-	strcpy(mmc->name, "mci");
+	mmc->name = "mci";
 	mmc->priv = regs;
 	mmc->ops = &atmel_mci_ops;
 
diff --git a/drivers/mmc/mmc_spi.c b/drivers/mmc/mmc_spi.c
index 0a0f894..e94de37 100644
--- a/drivers/mmc/mmc_spi.c
+++ b/drivers/mmc/mmc_spi.c
@@ -274,7 +274,7 @@ struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 		free(mmc);
 		return NULL;
 	}
-	sprintf(mmc->name, "MMC_SPI");
+	mmc->name = "MMC_SPI";
 	mmc->ops = &mmc_spi_ops;
 	mmc->host_caps = MMC_MODE_SPI;
 
diff --git a/drivers/mmc/mxcmmc.c b/drivers/mmc/mxcmmc.c
index f3e1eed..3357559 100644
--- a/drivers/mmc/mxcmmc.c
+++ b/drivers/mmc/mxcmmc.c
@@ -500,7 +500,7 @@ static int mxcmci_initialize(bd_t *bis)
 	if (!mmc)
 		return -ENOMEM;
 
-	sprintf(mmc->name, "MXC MCI");
+	mmc->name = "MXC MCI";
 	mmc->ops = &mxcmci_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c
index 97c9ee8..3512a99 100644
--- a/drivers/mmc/mxsmmc.c
+++ b/drivers/mmc/mxsmmc.c
@@ -405,7 +405,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	priv->id = id;
 	priv->regs = mxs_ssp_regs_by_bus(id);
 
-	sprintf(mmc->name, "MXS MMC");
+	mmc->name = "MXS MMC";
 	mmc->ops = &mxsmmc_ops;
 	mmc->priv = priv;
 
diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c
index 6bf602f..fecac56 100644
--- a/drivers/mmc/omap_hsmmc.c
+++ b/drivers/mmc/omap_hsmmc.c
@@ -641,7 +641,7 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
 	uint host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS |
 			     MMC_MODE_HC;
 
-	sprintf(mmc->name, "OMAP SD/MMC");
+	mmc->name = "OMAP SD/MMC";
 	mmc->ops = &omap_hsmmc_ops;
 	mmc->priv = priv_data;
 
diff --git a/drivers/mmc/pxa_mmc_gen.c b/drivers/mmc/pxa_mmc_gen.c
index 4694c8f..188e1d4 100644
--- a/drivers/mmc/pxa_mmc_gen.c
+++ b/drivers/mmc/pxa_mmc_gen.c
@@ -402,7 +402,7 @@ int pxa_mmc_register(int card_index)
 
 	mmc->priv = priv;
 
-	sprintf(mmc->name, "PXA MMC");
+	mmc->name = "PXA MMC";
 	mmc->ops = &pxa_mmc_ops;
 
 	mmc->voltages	= MMC_VDD_32_33 | MMC_VDD_33_34;
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index c3425a6..dc6f4e4 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -451,7 +451,7 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
 	mmc->priv = host;
 	host->mmc = mmc;
 
-	sprintf(mmc->name, "%s", host->name);
+	mmc->name = host->name;
 	mmc->ops = &sdhci_ops;
 
 	caps = sdhci_readl(host, SDHCI_CAPABILITIES);
diff --git a/drivers/mmc/sh_mmcif.c b/drivers/mmc/sh_mmcif.c
index 6a4860b..008617d 100644
--- a/drivers/mmc/sh_mmcif.c
+++ b/drivers/mmc/sh_mmcif.c
@@ -600,7 +600,7 @@ int mmcif_mmc_init(void)
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT |
 			 MMC_MODE_8BIT | MMC_MODE_HC;
-	memcpy(mmc->name, DRIVER_NAME, sizeof(DRIVER_NAME));
+	mmc->name = DRIVER_NAME;
 	mmc->ops = &sh_mmcif_ops;
 	host->regs = (struct sh_mmcif_regs *)CONFIG_SH_MMCIF_ADDR;
 	host->clk = CONFIG_SH_MMCIF_CLK;
diff --git a/drivers/mmc/tegra_mmc.c b/drivers/mmc/tegra_mmc.c
index 5f7b590..e8fbb63 100644
--- a/drivers/mmc/tegra_mmc.c
+++ b/drivers/mmc/tegra_mmc.c
@@ -563,7 +563,7 @@ static int do_mmc_init(int dev_index)
 
 	mmc = &mmc_dev[dev_index];
 
-	sprintf(mmc->name, "Tegra SD/MMC");
+	mmc->name = "Tegra SD/MMC";
 	mmc->priv = host;
 	mmc->ops = &tegra_mmc_ops;
 
diff --git a/include/mmc.h b/include/mmc.h
index 3d53ce1..6b08c62 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -264,7 +264,7 @@ struct mmc_ops {
 
 struct mmc {
 	struct list_head link;
-	char name[32];
+	const char *name;	/* no need for this to be an array */
 	void *priv;
 	uint voltages;
 	uint version;
-- 
1.7.12



More information about the U-Boot mailing list