Skip to contentSkip to conversation

MTD: make panic_write() conditional to CONFIG_MTD_OOPS

PATCH Superseded Florian Fainelli 2 participants 4 messages Jan 10, 2012 1 message not in the archive

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

PATCH 1/1 MTD: make panic_write() conditional to CONFIG_MTD_OOPS

In reply to a message not in the archive

The mtdoops driver is the only user of the panic_write callback make all panic_write related code conditionnal to CONFIG_MTD_OOPS so we can save some code. Since CONFIG_MTD_OOPS can be a module use the newly introduced IS_ENABLED() macro to cope with that.

It is safe to define the panic_write callback as NULL when CONFIG_MTD_OOPS is disabled since the mtdoops drivers check for the callback being non-NULL and returns an error if this the case.

---
 drivers/mtd/mtdpart.c              |    5 +++++
 drivers/mtd/nand/nand_base.c       |    7 +++++++
 drivers/mtd/onenand/onenand_base.c |    5 +++++
 3 files changed, 17 insertions(+), 0 deletions(-)
drivers/mtd/mtdpart.c +5 -0
index a3d44c3..0322388 100644
@@ -189,6 +189,7 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_write(part->master, to + part->offset, len, retlen, buf);
 }
 
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
@@ -202,6 +203,10 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_panic_write(part->master, to + part->offset, len, retlen,
 			       buf);
 }
+#else
+#define part_panic_write	NULL
+#endif
+
 
 static int part_write_oob(struct mtd_info *mtd, loff_t to,
 		struct mtd_oob_ops *ops)
drivers/mtd/nand/nand_base.c +7 -0
index 8a393f9..da8d4a6 100644
@@ -753,6 +753,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
  *
  * Used when in panic, no locks are taken.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static void panic_nand_get_device(struct nand_chip *chip,
 		      struct mtd_info *mtd, int new_state)
 {
@@ -760,6 +761,7 @@ static void panic_nand_get_device(struct nand_chip *chip,
 	chip->controller->active = chip;
 	chip->state = new_state;
 }
+#endif
 
 /**
  * nand_get_device - [GENERIC] Get chip for selected access
@@ -2286,6 +2288,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
  * NAND write with ECC. Used when performing writes in interrupt context, this
  * may for example be called by mtdoops when writing an oops while in panic.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 			    size_t *retlen, const uint8_t *buf)
 {
@@ -2315,6 +2318,10 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = ops.retlen;
 	return ret;
 }
+#else
+#define panic_nand_write	NULL
+#endif
+
 
 /**
  * nand_write - [MTD Interface] NAND write with ECC
drivers/mtd/onenand/onenand_base.c +5 -0
index a061bc1..9f6a2a9 100644
@@ -1736,6 +1736,7 @@ static void onenand_panic_wait(struct mtd_info *mtd)
  *
  * Write with ECC
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 			 size_t *retlen, const u_char *buf)
 {
@@ -1819,6 +1820,10 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = written;
 	return ret;
 }
+#else
+#define onenand_panic_write	NULL
+#endif
+
 
 /**
  * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
Signature · 1 line
1.7.5.4
#2 lore raw
Quoted 83 lines · Florian Fainelli

The mtdoops driver is the only user of the panic_write callback make all panic_write related code conditionnal to CONFIG_MTD_OOPS so we can save some code. Since CONFIG_MTD_OOPS can be a module use the newly introduced IS_ENABLED() macro to cope with that.

It is safe to define the panic_write callback as NULL when CONFIG_MTD_OOPS is disabled since the mtdoops drivers check for the callback being non-NULL and returns an error if this the case.

---
 drivers/mtd/mtdpart.c              |    5 +++++
 drivers/mtd/nand/nand_base.c       |    7 +++++++
 drivers/mtd/onenand/onenand_base.c |    5 +++++
 3 files changed, 17 insertions(+), 0 deletions(-)
drivers/mtd/mtdpart.c +5 -0
index a3d44c3..0322388 100644
@@ -189,6 +189,7 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_write(part->master, to + part->offset, len, retlen, buf);
 }
 
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
@@ -202,6 +203,10 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_panic_write(part->master, to + part->offset, len, retlen,
 			       buf);
 }
+#else
+#define part_panic_write	NULL
+#endif
+
 
 static int part_write_oob(struct mtd_info *mtd, loff_t to,
 		struct mtd_oob_ops *ops)
drivers/mtd/nand/nand_base.c +7 -0
index 8a393f9..da8d4a6 100644
@@ -753,6 +753,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
  *
  * Used when in panic, no locks are taken.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static void panic_nand_get_device(struct nand_chip *chip,
 		      struct mtd_info *mtd, int new_state)
 {
@@ -760,6 +761,7 @@ static void panic_nand_get_device(struct nand_chip *chip,
 	chip->controller->active = chip;
 	chip->state = new_state;
 }
+#endif
 
 /**
  * nand_get_device - [GENERIC] Get chip for selected access
@@ -2286,6 +2288,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
  * NAND write with ECC. Used when performing writes in interrupt context, this
  * may for example be called by mtdoops when writing an oops while in panic.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 			    size_t *retlen, const uint8_t *buf)
 {
@@ -2315,6 +2318,10 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = ops.retlen;
 	return ret;
 }
+#else
+#define panic_nand_write	NULL
+#endif
+
 
 /**
  * nand_write - [MTD Interface] NAND write with ECC
drivers/mtd/onenand/onenand_base.c +0 -0
index a061bc1..9f6a2a9 100644

drivers/mtd/onenand/onenand_base.c static void onenand_panic_wait(struct mtd_info *mtd) · line 1739

Quoted 4 lines
drivers/mtd/onenand/onenand_base.c +1 -0
@@ -1736,6 +1736,7 @@ static void onenand_panic_wait(struct mtd_info *mtd)
  *
  * Write with ECC
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)

This #if should be moved up above onenand_panic_wait() which is only used from onenand_panic_write().

Other than that, the patch looks good to me.

Ira

Quoted 17 lines
drivers/mtd/onenand/onenand_base.c +4 -0
 static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 			 size_t *retlen, const u_char *buf)
 {
@@ -1819,6 +1820,10 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = written;
 	return ret;
 }
+#else
+#define onenand_panic_write	NULL
+#endif
+
 
 /**
  * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
Signature · 1 line
1.7.5.4
#3 lore raw

Hello Ira,

Quoted 12 lines · ----- "Ira W. Snyder
Quoted 11 lines · Florian Fainelli

The mtdoops driver is the only user of the panic_write callback make all panic_write related code conditionnal to CONFIG_MTD_OOPS so we can save some code. Since CONFIG_MTD_OOPS can be a module use the newly introduced IS_ENABLED() macro to cope with that.

It is safe to define the panic_write callback as NULL when CONFIG_MTD_OOPS is disabled since the mtdoops drivers check for the callback being non-NULL and returns an error if this the case.

---

[snip]

Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/mtd/onenand/onenand_base.c

drivers/mtd/onenand/onenand_base.c static void onenand_panic_wait(struct mtd_info

Quoted 4 lines

index a061bc1..9f6a2a9 100644

drivers/mtd/onenand/onenand_base.c +0 -0
@@ -1736,6 +1736,7 @@ static void onenand_panic_wait(struct mtd_info

*mtd)

Quoted 7 lines

drivers/mtd/onenand/onenand_base.c static void onenand_panic_wait(struct mtd_info *mtd) · line 1739

Quoted 4 lines
drivers/mtd/onenand/onenand_base.c +1 -0
  *
  * Write with ECC
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)

This #if should be moved up above onenand_panic_wait() which is only used from onenand_panic_write().

Indeed, thanks for spotting this.

Quoted 2 lines

Other than that, the patch looks good to me.

Thanks.
--
Florian

Quoted 22 lines

Ira

drivers/mtd/onenand/onenand_base.c static void onenand_panic_wait(struct mtd_info · line 1740

Quoted 1 line
drivers/mtd/onenand/onenand_base.c +0 -0
 static int onenand_panic_write(struct mtd_info *mtd, loff_t to,

size_t len,

drivers/mtd/onenand/onenand_base.c static int onenand_panic_write(struct

Quoted 3 lines
drivers/mtd/onenand/onenand_base.c +0 -0
 			 size_t *retlen, const u_char *buf)
 {
@@ -1819,6 +1820,10 @@ static int onenand_panic_write(struct

mtd_info *mtd, loff_t to, size_t len,

Quoted 13 lines
drivers/mtd/onenand/onenand_base.c +4 -0
 	*retlen = written;
 	return ret;
 }
+#else
+#define onenand_panic_write	NULL
+#endif
+
 
 /**
  * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 1/1 MTD: make panic_write() conditionnal to CONFIG_MTD_OOPS

In reply to Florian Fainelli

The mtdoops driver is the only user of the panic_write callback make all panic_write related code conditionnal to CONFIG_MTD_OOPS.

It is safe to define the panic_write callback as NULL when CONFIG_MTD_OOPS is enabled since the mtdoops drivers check for the callback being non-NULL and returns an error if this the case.

---
Changes since v1:
- fixed commit message second paragraph: disabled -> enabled
- moved #if IS_ENABLE() above onenand_panic_wait which was

 drivers/mtd/mtdpart.c              |    5 +++++
 drivers/mtd/nand/nand_base.c       |    7 +++++++
 drivers/mtd/onenand/onenand_base.c |    5 +++++
 3 files changed, 17 insertions(+), 0 deletions(-)
drivers/mtd/mtdpart.c +5 -0
index a3d44c3..0322388 100644
@@ -189,6 +189,7 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_write(part->master, to + part->offset, len, retlen, buf);
 }
 
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 		size_t *retlen, const u_char *buf)
 {
@@ -202,6 +203,10 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return mtd_panic_write(part->master, to + part->offset, len, retlen,
 			       buf);
 }
+#else
+#define part_panic_write	NULL
+#endif
+
 
 static int part_write_oob(struct mtd_info *mtd, loff_t to,
 		struct mtd_oob_ops *ops)
drivers/mtd/nand/nand_base.c +7 -0
index 8a393f9..da8d4a6 100644
@@ -753,6 +753,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
  *
  * Used when in panic, no locks are taken.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static void panic_nand_get_device(struct nand_chip *chip,
 		      struct mtd_info *mtd, int new_state)
 {
@@ -760,6 +761,7 @@ static void panic_nand_get_device(struct nand_chip *chip,
 	chip->controller->active = chip;
 	chip->state = new_state;
 }
+#endif
 
 /**
  * nand_get_device - [GENERIC] Get chip for selected access
@@ -2286,6 +2288,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
  * NAND write with ECC. Used when performing writes in interrupt context, this
  * may for example be called by mtdoops when writing an oops while in panic.
  */
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 			    size_t *retlen, const uint8_t *buf)
 {
@@ -2315,6 +2318,10 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = ops.retlen;
 	return ret;
 }
+#else
+#define panic_nand_write	NULL
+#endif
+
 
 /**
  * nand_write - [MTD Interface] NAND write with ECC
drivers/mtd/onenand/onenand_base.c +5 -0
index a061bc1..fc0787d 100644
@@ -1712,6 +1712,7 @@ static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr,
 
 #define NOTALIGNED(x)	((x & (this->subpagesize - 1)) != 0)
 
+#if IS_ENABLED(CONFIG_MTD_OOPS)
 static void onenand_panic_wait(struct mtd_info *mtd)
 {
 	struct onenand_chip *this = mtd->priv;
@@ -1819,6 +1820,10 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 	*retlen = written;
 	return ret;
 }
+#else
+#define onenand_panic_write	NULL
+#endif
+
 
 /**
  * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
Signature · 1 line
1.7.5.4