Skip to contentSkip to conversation

EDAC, altera: remove useless casts

PATCH In review Arnd Bergmann 3 participants 5 messages Apr 16, 2016 – Apr 23, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 EDAC, altera: remove useless casts

The altera EDAC driver refers to its per-device data using a cast to '(void *)', which makes the pointer non-const, though both the source and destination are actually const.

Removing the annotation makes the reference (almost) fit into a single line for improved readability, and ensures that it is actually defined as const.

---
 drivers/edac/altera_edac.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/edac/altera_edac.c +6 -9
index 11775dc0b139..cc987b4ce908 100644
@@ -232,8 +232,8 @@ static unsigned long get_total_mem(void)
 }
 
 static const struct of_device_id altr_sdram_ctrl_of_match[] = {
-	{ .compatible = "altr,sdram-edac", .data = (void *)&c5_data},
-	{ .compatible = "altr,sdram-edac-a10", .data = (void *)&a10_data},
+	{ .compatible = "altr,sdram-edac", .data = &c5_data},
+	{ .compatible = "altr,sdram-edac-a10", .data = &a10_data},
 	{},
 };
 MODULE_DEVICE_TABLE(of, altr_sdram_ctrl_of_match);
@@ -705,15 +705,12 @@ static void altr_create_edacdev_dbgfs(struct edac_device_ctl_info *edac_dci,
 
 static const struct of_device_id altr_edac_device_of_match[] = {
 #ifdef CONFIG_EDAC_ALTERA_L2C
-	{ .compatible = "altr,socfpga-l2-ecc", .data = (void *)&l2ecc_data },
-	{ .compatible = "altr,socfpga-a10-l2-ecc",
-	  .data = (void *)&a10_l2ecc_data },
+	{ .compatible = "altr,socfpga-l2-ecc", .data = &l2ecc_data },
+	{ .compatible = "altr,socfpga-a10-l2-ecc", .data = &a10_l2ecc_data },
 #endif
 #ifdef CONFIG_EDAC_ALTERA_OCRAM
-	{ .compatible = "altr,socfpga-ocram-ecc",
-	  .data = (void *)&ocramecc_data },
-	{ .compatible = "altr,socfpga-a10-ocram-ecc",
-	  .data = (void *)&a10_ocramecc_data },
+	{ .compatible = "altr,socfpga-ocram-ecc", .data = &ocramecc_data },
+	{ .compatible = "altr,socfpga-a10-ocram-ecc", .data = &a10_ocramecc_data },
 #endif
 	{},
 };
Signature · 1 line
2.7.0
#1 lore raw

PATCH 2/2 EDAC, altera: avoid unused function warnings

The recently added Arria10 OCRAM ECC support caused some new harmless warnings about unused functions when it is disabled:

drivers/edac/altera_edac.c:1067:20: error: 'altr_edac_a10_ecc_irq' defined but not used [-Werror=unused-function] drivers/edac/altera_edac.c:658:12: error: 'altr_check_ecc_deps' defined but not used [-Werror=unused-function]

This rearranges the code slightly to have those two functions inside of the same #ifdef that hides their callers. It also manages to avoid a forward declaration of the IRQ handler in the process.

Fixes c7b4be8db8bc ("EDAC, altera: Add Arria10 OCRAM ECC support")
---
 drivers/edac/altera_edac.c | 78 ++++++++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 41 deletions(-)
drivers/edac/altera_edac.c +37 -41
index cc987b4ce908..5b4d223d6d68 100644
@@ -649,26 +649,6 @@ static ssize_t altr_edac_device_trig(struct file *file,
 	return count;
 }
 
-/*
- *  Test for memory's ECC dependencies upon entry because platform specific
- *  startup should have initialized the memory and enabled the ECC.
- *  Can't turn on ECC here because accessing un-initialized memory will
- *  cause CE/UE errors possibly causing an ABORT.
- */
-static int altr_check_ecc_deps(struct altr_edac_device_dev *device)
-{
-	void __iomem  *base = device->base;
-	const struct edac_device_prv_data *prv = device->data;
-
-	if (readl(base + prv->ecc_en_ofst) & prv->ecc_enable_mask)
-		return 0;
-
-	edac_printk(KERN_ERR, EDAC_DEVICE,
-		    "%s: No ECC present or ECC disabled.\n",
-		    device->edac_dev_name);
-	return -ENODEV;
-}
-
 static const struct file_operations altr_edac_device_inject_fops = {
 	.open = simple_open,
 	.write = altr_edac_device_trig,
@@ -848,6 +828,25 @@ module_platform_driver(altr_edac_device_driver);
 /*********************** OCRAM EDAC Device Functions *********************/
 
 #ifdef CONFIG_EDAC_ALTERA_OCRAM
+/*
+ *  Test for memory's ECC dependencies upon entry because platform specific
+ *  startup should have initialized the memory and enabled the ECC.
+ *  Can't turn on ECC here because accessing un-initialized memory will
+ *  cause CE/UE errors possibly causing an ABORT.
+ */
+static int altr_check_ecc_deps(struct altr_edac_device_dev *device)
+{
+	void __iomem  *base = device->base;
+	const struct edac_device_prv_data *prv = device->data;
+
+	if (readl(base + prv->ecc_en_ofst) & prv->ecc_enable_mask)
+		return 0;
+
+	edac_printk(KERN_ERR, EDAC_DEVICE,
+		    "%s: No ECC present or ECC disabled.\n",
+		    device->edac_dev_name);
+	return -ENODEV;
+}
 
 static void *ocram_alloc_mem(size_t size, void **other)
 {
@@ -883,6 +882,24 @@ static void ocram_free_mem(void *p, size_t size, void *other)
 	gen_pool_free((struct gen_pool *)other, (u32)p, size);
 }
 
+static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
+					 bool sberr)
+{
+	void __iomem  *base = dci->base;
+
+	if (sberr) {
+		writel(ALTR_A10_ECC_SERRPENA,
+		       base + ALTR_A10_ECC_INTSTAT_OFST);
+		edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
+	} else {
+		writel(ALTR_A10_ECC_DERRPENA,
+		       base + ALTR_A10_ECC_INTSTAT_OFST);
+		edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
+		panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
+	}
+	return IRQ_HANDLED;
+}
+
 const struct edac_device_prv_data ocramecc_data = {
 	.setup = altr_check_ecc_deps,
 	.ce_clear_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_SERR),
@@ -899,9 +916,6 @@ const struct edac_device_prv_data ocramecc_data = {
 	.inject_fops = &altr_edac_device_inject_fops,
 };
 
-static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
-					 bool sberr);
-
 const struct edac_device_prv_data a10_ocramecc_data = {
 	.setup = altr_check_ecc_deps,
 	.ce_clear_mask = ALTR_A10_ECC_SERRPENA,
@@ -1061,24 +1075,6 @@ static ssize_t altr_edac_a10_device_trig(struct file *file,
 	return count;
 }
 
-static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
-					 bool sberr)
-{
-	void __iomem  *base = dci->base;
-
-	if (sberr) {
-		writel(ALTR_A10_ECC_SERRPENA,
-		       base + ALTR_A10_ECC_INTSTAT_OFST);
-		edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
-	} else {
-		writel(ALTR_A10_ECC_DERRPENA,
-		       base + ALTR_A10_ECC_INTSTAT_OFST);
-		edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
-		panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
-	}
-	return IRQ_HANDLED;
-}
-
 static irqreturn_t altr_edac_a10_irq_handler(int irq, void *dev_id)
 {
 	irqreturn_t rc = IRQ_NONE;
Signature · 1 line
2.7.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] EDAC, altera: avoid unused function warnings

Quoted 124 lines · Arnd Bergmann

The recently added Arria10 OCRAM ECC support caused some new harmless warnings about unused functions when it is disabled:

drivers/edac/altera_edac.c:1067:20: error: 'altr_edac_a10_ecc_irq' defined but not used [-Werror=unused-function] drivers/edac/altera_edac.c:658:12: error: 'altr_check_ecc_deps' defined but not used [-Werror=unused-function]

This rearranges the code slightly to have those two functions inside of the same #ifdef that hides their callers. It also manages to avoid a forward declaration of the IRQ handler in the process.

Fixes c7b4be8db8bc ("EDAC, altera: Add Arria10 OCRAM ECC support")
---
  drivers/edac/altera_edac.c | 78 ++++++++++++++++++++++------------------------
  1 file changed, 37 insertions(+), 41 deletions(-)
drivers/edac/altera_edac.c +37 -34
index cc987b4ce908..5b4d223d6d68 100644
@@ -649,26 +649,6 @@ static ssize_t altr_edac_device_trig(struct file *file,
  	return count;
  }
 
-/*
- *  Test for memory's ECC dependencies upon entry because platform specific
- *  startup should have initialized the memory and enabled the ECC.
- *  Can't turn on ECC here because accessing un-initialized memory will
- *  cause CE/UE errors possibly causing an ABORT.
- */
-static int altr_check_ecc_deps(struct altr_edac_device_dev *device)
-{
-	void __iomem  *base = device->base;
-	const struct edac_device_prv_data *prv = device->data;
-
-	if (readl(base + prv->ecc_en_ofst) & prv->ecc_enable_mask)
-		return 0;
-
-	edac_printk(KERN_ERR, EDAC_DEVICE,
-		    "%s: No ECC present or ECC disabled.\n",
-		    device->edac_dev_name);
-	return -ENODEV;
-}
-
  static const struct file_operations altr_edac_device_inject_fops = {
  	.open = simple_open,
  	.write = altr_edac_device_trig,
@@ -848,6 +828,25 @@ module_platform_driver(altr_edac_device_driver);
  /*********************** OCRAM EDAC Device Functions *********************/
 
  #ifdef CONFIG_EDAC_ALTERA_OCRAM
+/*
+ *  Test for memory's ECC dependencies upon entry because platform specific
+ *  startup should have initialized the memory and enabled the ECC.
+ *  Can't turn on ECC here because accessing un-initialized memory will
+ *  cause CE/UE errors possibly causing an ABORT.
+ */
+static int altr_check_ecc_deps(struct altr_edac_device_dev *device)
+{
+	void __iomem  *base = device->base;
+	const struct edac_device_prv_data *prv = device->data;
+
+	if (readl(base + prv->ecc_en_ofst) & prv->ecc_enable_mask)
+		return 0;
+
+	edac_printk(KERN_ERR, EDAC_DEVICE,
+		    "%s: No ECC present or ECC disabled.\n",
+		    device->edac_dev_name);
+	return -ENODEV;
+}
 
  static void *ocram_alloc_mem(size_t size, void **other)
  {
@@ -883,6 +882,24 @@ static void ocram_free_mem(void *p, size_t size, void *other)
  	gen_pool_free((struct gen_pool *)other, (u32)p, size);
  }
 
+static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
+					 bool sberr)
+{
+	void __iomem  *base = dci->base;
+
+	if (sberr) {
+		writel(ALTR_A10_ECC_SERRPENA,
+		       base + ALTR_A10_ECC_INTSTAT_OFST);
+		edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
+	} else {
+		writel(ALTR_A10_ECC_DERRPENA,
+		       base + ALTR_A10_ECC_INTSTAT_OFST);
+		edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
+		panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
+	}
+	return IRQ_HANDLED;
+}
+
  const struct edac_device_prv_data ocramecc_data = {
  	.setup = altr_check_ecc_deps,
  	.ce_clear_mask = (ALTR_OCR_ECC_EN | ALTR_OCR_ECC_SERR),
@@ -899,9 +916,6 @@ const struct edac_device_prv_data ocramecc_data = {
  	.inject_fops = &altr_edac_device_inject_fops,
  };
 
-static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
-					 bool sberr);
-
  const struct edac_device_prv_data a10_ocramecc_data = {
  	.setup = altr_check_ecc_deps,
  	.ce_clear_mask = ALTR_A10_ECC_SERRPENA,
@@ -1061,24 +1075,6 @@ static ssize_t altr_edac_a10_device_trig(struct file *file,
  	return count;
  }
 
-static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
-					 bool sberr)
-{
-	void __iomem  *base = dci->base;
-
-	if (sberr) {
-		writel(ALTR_A10_ECC_SERRPENA,
-		       base + ALTR_A10_ECC_INTSTAT_OFST);
-		edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
-	} else {
-		writel(ALTR_A10_ECC_DERRPENA,

drivers/edac/altera_edac.c static ssize_t altr_edac_a10_device_trig(struct file *file, · line 1080

Quoted 10 lines
drivers/edac/altera_edac.c +0 -7
-		       base + ALTR_A10_ECC_INTSTAT_OFST);
-		edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
-		panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
-	}
-	return IRQ_HANDLED;
-}
-
  static irqreturn_t altr_edac_a10_irq_handler(int irq, void *dev_id)
  {
  	irqreturn_t rc = IRQ_NONE;
Acked-by on v1 1/2
#3 lore raw
In reply to Arnd Bergmann
Quoted 40 lines · Arnd Bergmann

The altera EDAC driver refers to its per-device data using a cast to '(void *)', which makes the pointer non-const, though both the source and destination are actually const.

Removing the annotation makes the reference (almost) fit into a single line for improved readability, and ensures that it is actually defined as const.

---
  drivers/edac/altera_edac.c | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
drivers/edac/altera_edac.c +4 -5
index 11775dc0b139..cc987b4ce908 100644
@@ -232,8 +232,8 @@ static unsigned long get_total_mem(void)
  }
 
  static const struct of_device_id altr_sdram_ctrl_of_match[] = {
-	{ .compatible = "altr,sdram-edac", .data = (void *)&c5_data},
-	{ .compatible = "altr,sdram-edac-a10", .data = (void *)&a10_data},
+	{ .compatible = "altr,sdram-edac", .data = &c5_data},
+	{ .compatible = "altr,sdram-edac-a10", .data = &a10_data},
  	{},
  };
  MODULE_DEVICE_TABLE(of, altr_sdram_ctrl_of_match);
@@ -705,15 +705,12 @@ static void altr_create_edacdev_dbgfs(struct edac_device_ctl_info *edac_dci,
 
  static const struct of_device_id altr_edac_device_of_match[] = {
  #ifdef CONFIG_EDAC_ALTERA_L2C
-	{ .compatible = "altr,socfpga-l2-ecc", .data = (void *)&l2ecc_data },
-	{ .compatible = "altr,socfpga-a10-l2-ecc",
-	  .data = (void *)&a10_l2ecc_data },
+	{ .compatible = "altr,socfpga-l2-ecc", .data = &l2ecc_data },
+	{ .compatible = "altr,socfpga-a10-l2-ecc", .data = &a10_l2ecc_data },
  #endif

drivers/edac/altera_edac.c static void altr_create_edacdev_dbgfs(struct edac_device_ctl_info *edac_dci, · line 716

Quoted 10 lines
drivers/edac/altera_edac.c +2 -4
  #ifdef CONFIG_EDAC_ALTERA_OCRAM
-	{ .compatible = "altr,socfpga-ocram-ecc",
-	  .data = (void *)&ocramecc_data },
-	{ .compatible = "altr,socfpga-a10-ocram-ecc",
-	  .data = (void *)&a10_ocramecc_data },
+	{ .compatible = "altr,socfpga-ocram-ecc", .data = &ocramecc_data },
+	{ .compatible = "altr,socfpga-a10-ocram-ecc", .data = &a10_ocramecc_data },
  #endif
  	{},
  };
maintainer
#4 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

The altera EDAC driver refers to its per-device data using a cast to '(void *)', which makes the pointer non-const, though both the source and destination are actually const.

Quoted 8 lines

Removing the annotation makes the reference (almost) fit into a single line for improved readability, and ensures that it is actually defined as const.

---
 drivers/edac/altera_edac.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Both applied, thanks.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.