Skip to contentSkip to conversation

mtd: lpddr: Fix bad logic in print_drs_error

RFC PATCH In review Joe Perches 3 participants 4 messages Mar 30, 2020 – Apr 27, 2020 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 mtd: lpddr: Fix bad logic in print_drs_error

Update logic for broken test.
Use a more common logging style.

Miscellanea:

o Coalesce formats

---

Found by inspection of include files using printk.

It appears the logic in this function is broken for the consecutive tests of

	if (prog_status & 0x3)
		...
	else if (prog_status & 0x2)
		...
	else (prog_status & 0x1)
		...

Likely the first test should be

	if ((prog_status & 0x3) == 0x3)

And this function is only used in drivers/mtd/lpddr/lpddr_cmds.c perhaps it should be moved there.

 include/linux/mtd/pfow.h | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
include/linux/mtd/pfow.h +14 -17
index 122f343..1c08e75 100644
@@ -127,31 +127,28 @@ static inline void print_drs_error(unsigned dsr)
 	int prog_status = (dsr & DSR_RPS) >> 8;
 
 	if (!(dsr & DSR_AVAILABLE))
-		printk(KERN_NOTICE"DSR.15: (0) Device not Available\n");
-	if (prog_status & 0x03)
-		printk(KERN_NOTICE"DSR.9,8: (11) Attempt to program invalid "
-						"half with 41h command\n");
+		pr_notice("DSR.15: (0) Device not Available\n");
+
+	if ((prog_status & 0x03) == 0x03)
+		pr_notice("DSR.9,8: (11) Attempt to program invalid half with 41h command\n");
 	else if (prog_status & 0x02)
-		printk(KERN_NOTICE"DSR.9,8: (10) Object Mode Program attempt "
-					"in region with Control Mode data\n");
+		pr_notice("DSR.9,8: (10) Object Mode Program attempt in region with Control Mode data\n");
 	else if (prog_status &  0x01)
-		printk(KERN_NOTICE"DSR.9,8: (01) Program attempt in region "
-						"with Object Mode data\n");
+		pr_notice("DSR.9,8: (01) Program attempt in region with Object Mode data\n");
+
 	if (!(dsr & DSR_READY_STATUS))
-		printk(KERN_NOTICE"DSR.7: (0) Device is Busy\n");
+		pr_notice("DSR.7: (0) Device is Busy\n");
 	if (dsr & DSR_ESS)
-		printk(KERN_NOTICE"DSR.6: (1) Erase Suspended\n");
+		pr_notice("DSR.6: (1) Erase Suspended\n");
 	if (dsr & DSR_ERASE_STATUS)
-		printk(KERN_NOTICE"DSR.5: (1) Erase/Blank check error\n");
+		pr_notice("DSR.5: (1) Erase/Blank check error\n");
 	if (dsr & DSR_PROGRAM_STATUS)
-		printk(KERN_NOTICE"DSR.4: (1) Program Error\n");
+		pr_notice("DSR.4: (1) Program Error\n");
 	if (dsr & DSR_VPPS)
-		printk(KERN_NOTICE"DSR.3: (1) Vpp low detect, operation "
-					"aborted\n");
+		pr_notice("DSR.3: (1) Vpp low detect, operation aborted\n");
 	if (dsr & DSR_PSS)
-		printk(KERN_NOTICE"DSR.2: (1) Program suspended\n");
+		pr_notice("DSR.2: (1) Program suspended\n");
 	if (dsr & DSR_DPS)
-		printk(KERN_NOTICE"DSR.1: (1) Aborted Erase/Program attempt "
-					"on locked block\n");
+		pr_notice("DSR.1: (1) Aborted Erase/Program attempt on locked block\n");
 }
 #endif /* __LINUX_MTD_PFOW_H */
maintainer
#1 lore raw

Hi Joe,

Joe Perches <[email protected]> wrote on Mon, 30 Mar 2020 12:56:59 -0700:

Quoted 22 lines

Update logic for broken test.
Use a more common logging style.

Miscellanea:

o Coalesce formats

---

Found by inspection of include files using printk.

It appears the logic in this function is broken for the consecutive tests of

	if (prog_status & 0x3)
		...
	else if (prog_status & 0x2)
		...
	else (prog_status & 0x1)
		...
Quoted 3 lines

Likely the first test should be

	if ((prog_status & 0x3) == 0x3)

I had a hard time understanding the patch just with the commit log, I think the above text is as important.

In fact, would you mind doing the printk->pr_notice in a first patch, and fix the wrong condition in a separate change?

Quoted 3 lines

And this function is only used in drivers/mtd/lpddr/lpddr_cmds.c perhaps it should be moved there.

Agreed, do not hesitate to move the function as suggested in a third patch.

Quoted 46 lines
 include/linux/mtd/pfow.h | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
include/linux/mtd/pfow.h +11 -14
index 122f343..1c08e75 100644
@@ -127,31 +127,28 @@ static inline void print_drs_error(unsigned dsr)
 	int prog_status = (dsr & DSR_RPS) >> 8;
 
 	if (!(dsr & DSR_AVAILABLE))
-		printk(KERN_NOTICE"DSR.15: (0) Device not Available\n");
-	if (prog_status & 0x03)
-		printk(KERN_NOTICE"DSR.9,8: (11) Attempt to program invalid "
-						"half with 41h command\n");
+		pr_notice("DSR.15: (0) Device not Available\n");
+
+	if ((prog_status & 0x03) == 0x03)
+		pr_notice("DSR.9,8: (11) Attempt to program invalid half with 41h command\n");
 	else if (prog_status & 0x02)
-		printk(KERN_NOTICE"DSR.9,8: (10) Object Mode Program attempt "
-					"in region with Control Mode data\n");
+		pr_notice("DSR.9,8: (10) Object Mode Program attempt in region with Control Mode data\n");
 	else if (prog_status &  0x01)
-		printk(KERN_NOTICE"DSR.9,8: (01) Program attempt in region "
-						"with Object Mode data\n");
+		pr_notice("DSR.9,8: (01) Program attempt in region with Object Mode data\n");
+
 	if (!(dsr & DSR_READY_STATUS))
-		printk(KERN_NOTICE"DSR.7: (0) Device is Busy\n");
+		pr_notice("DSR.7: (0) Device is Busy\n");
 	if (dsr & DSR_ESS)
-		printk(KERN_NOTICE"DSR.6: (1) Erase Suspended\n");
+		pr_notice("DSR.6: (1) Erase Suspended\n");
 	if (dsr & DSR_ERASE_STATUS)
-		printk(KERN_NOTICE"DSR.5: (1) Erase/Blank check error\n");
+		pr_notice("DSR.5: (1) Erase/Blank check error\n");
 	if (dsr & DSR_PROGRAM_STATUS)
-		printk(KERN_NOTICE"DSR.4: (1) Program Error\n");
+		pr_notice("DSR.4: (1) Program Error\n");
 	if (dsr & DSR_VPPS)
-		printk(KERN_NOTICE"DSR.3: (1) Vpp low detect, operation "
-					"aborted\n");

include/linux/mtd/pfow.h static inline void print_drs_error(unsigned dsr) · line 154

Quoted 10 lines
include/linux/mtd/pfow.h +3 -3
+		pr_notice("DSR.3: (1) Vpp low detect, operation aborted\n");
 	if (dsr & DSR_PSS)
-		printk(KERN_NOTICE"DSR.2: (1) Program suspended\n");
+		pr_notice("DSR.2: (1) Program suspended\n");
 	if (dsr & DSR_DPS)
-		printk(KERN_NOTICE"DSR.1: (1) Aborted Erase/Program attempt "
-					"on locked block\n");
+		pr_notice("DSR.1: (1) Aborted Erase/Program attempt on locked block\n");
 }
 #endif /* __LINUX_MTD_PFOW_H */

Thanks,
Miquèl

#2 lore raw
Quoted 1 line · Miquel Raynal

Hi Joe,

Hello Miquel.

Quoted 31 lines

Joe Perches <[email protected]> wrote on Mon, 30 Mar 2020 12:56:59 -0700:

Quoted 22 lines

Update logic for broken test.
Use a more common logging style.

Miscellanea:

o Coalesce formats

---

Found by inspection of include files using printk.

It appears the logic in this function is broken for the consecutive tests of

	if (prog_status & 0x3)
		...
	else if (prog_status & 0x2)
		...
	else (prog_status & 0x1)
		...
Quoted 3 lines

Likely the first test should be

	if ((prog_status & 0x3) == 0x3)

I had a hard time understanding the patch just with the commit log, I think the above text is as important.

Quoted 8 lines

In fact, would you mind doing the printk->pr_notice in a first patch, and fix the wrong condition in a separate change?

Quoted 2 lines

And this function is only used in drivers/mtd/lpddr/lpddr_cmds.c perhaps it should be moved there.

Agreed, do not hesitate to move the function as suggested in a third patch.

You are the maintainer here no?

I think you (or perhaps the author Alexey Korolev but he hasn't been active in a decade) should be doing all this.

I just identified the logic defect.

Quoted 58 lines
Quoted 45 lines
 include/linux/mtd/pfow.h | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
include/linux/mtd/pfow.h +11 -14
index 122f343..1c08e75 100644
@@ -127,31 +127,28 @@ static inline void print_drs_error(unsigned dsr)
 	int prog_status = (dsr & DSR_RPS) >> 8;
 
 	if (!(dsr & DSR_AVAILABLE))
-		printk(KERN_NOTICE"DSR.15: (0) Device not Available\n");
-	if (prog_status & 0x03)
-		printk(KERN_NOTICE"DSR.9,8: (11) Attempt to program invalid "
-						"half with 41h command\n");
+		pr_notice("DSR.15: (0) Device not Available\n");
+
+	if ((prog_status & 0x03) == 0x03)
+		pr_notice("DSR.9,8: (11) Attempt to program invalid half with 41h command\n");
 	else if (prog_status & 0x02)
-		printk(KERN_NOTICE"DSR.9,8: (10) Object Mode Program attempt "
-					"in region with Control Mode data\n");
+		pr_notice("DSR.9,8: (10) Object Mode Program attempt in region with Control Mode data\n");
 	else if (prog_status &  0x01)
-		printk(KERN_NOTICE"DSR.9,8: (01) Program attempt in region "
-						"with Object Mode data\n");
+		pr_notice("DSR.9,8: (01) Program attempt in region with Object Mode data\n");
+
 	if (!(dsr & DSR_READY_STATUS))
-		printk(KERN_NOTICE"DSR.7: (0) Device is Busy\n");
+		pr_notice("DSR.7: (0) Device is Busy\n");
 	if (dsr & DSR_ESS)
-		printk(KERN_NOTICE"DSR.6: (1) Erase Suspended\n");
+		pr_notice("DSR.6: (1) Erase Suspended\n");
 	if (dsr & DSR_ERASE_STATUS)
-		printk(KERN_NOTICE"DSR.5: (1) Erase/Blank check error\n");
+		pr_notice("DSR.5: (1) Erase/Blank check error\n");
 	if (dsr & DSR_PROGRAM_STATUS)
-		printk(KERN_NOTICE"DSR.4: (1) Program Error\n");
+		pr_notice("DSR.4: (1) Program Error\n");
 	if (dsr & DSR_VPPS)
-		printk(KERN_NOTICE"DSR.3: (1) Vpp low detect, operation "
-					"aborted\n");

include/linux/mtd/pfow.h static inline void print_drs_error(unsigned dsr) · line 154

Quoted 10 lines
include/linux/mtd/pfow.h +3 -3
+		pr_notice("DSR.3: (1) Vpp low detect, operation aborted\n");
 	if (dsr & DSR_PSS)
-		printk(KERN_NOTICE"DSR.2: (1) Program suspended\n");
+		pr_notice("DSR.2: (1) Program suspended\n");
 	if (dsr & DSR_DPS)
-		printk(KERN_NOTICE"DSR.1: (1) Aborted Erase/Program attempt "
-					"on locked block\n");
+		pr_notice("DSR.1: (1) Aborted Erase/Program attempt on locked block\n");
 }
 #endif /* __LINUX_MTD_PFOW_H */

Thanks,
Miquèl

#3 lore raw

Hi,

It seems that this fix should be tagged for -stable.

I can create a three-patch series for this (as Miquel suggested), starting with the patch that fix the wrong condition, so it can be ported to -stable, separately.

I'll include you Reported-by, Joe.

Thanks
--
Gustavo

Quoted 45 lines · Joe Perches
Quoted 1 line · Miquel Raynal

Hi Joe,

Hello Miquel.

Quoted 31 lines

Joe Perches <[email protected]> wrote on Mon, 30 Mar 2020 12:56:59 -0700:

Quoted 22 lines

Update logic for broken test.
Use a more common logging style.

Miscellanea:

o Coalesce formats

---

Found by inspection of include files using printk.

It appears the logic in this function is broken for the consecutive tests of

	if (prog_status & 0x3)
		...
	else if (prog_status & 0x2)
		...
	else (prog_status & 0x1)
		...
Quoted 3 lines

Likely the first test should be

	if ((prog_status & 0x3) == 0x3)

I had a hard time understanding the patch just with the commit log, I think the above text is as important.

Quoted 8 lines

In fact, would you mind doing the printk->pr_notice in a first patch, and fix the wrong condition in a separate change?

Quoted 2 lines

And this function is only used in drivers/mtd/lpddr/lpddr_cmds.c perhaps it should be moved there.

Agreed, do not hesitate to move the function as suggested in a third patch.

Quoted 66 lines

You are the maintainer here no?

I think you (or perhaps the author Alexey Korolev but he hasn't been active in a decade) should be doing all this.

I just identified the logic defect.

Quoted 58 lines
Quoted 45 lines
 include/linux/mtd/pfow.h | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
include/linux/mtd/pfow.h +11 -14
index 122f343..1c08e75 100644
@@ -127,31 +127,28 @@ static inline void print_drs_error(unsigned dsr)
 	int prog_status = (dsr & DSR_RPS) >> 8;
 
 	if (!(dsr & DSR_AVAILABLE))
-		printk(KERN_NOTICE"DSR.15: (0) Device not Available\n");
-	if (prog_status & 0x03)
-		printk(KERN_NOTICE"DSR.9,8: (11) Attempt to program invalid "
-						"half with 41h command\n");
+		pr_notice("DSR.15: (0) Device not Available\n");
+
+	if ((prog_status & 0x03) == 0x03)
+		pr_notice("DSR.9,8: (11) Attempt to program invalid half with 41h command\n");
 	else if (prog_status & 0x02)
-		printk(KERN_NOTICE"DSR.9,8: (10) Object Mode Program attempt "
-					"in region with Control Mode data\n");
+		pr_notice("DSR.9,8: (10) Object Mode Program attempt in region with Control Mode data\n");
 	else if (prog_status &  0x01)
-		printk(KERN_NOTICE"DSR.9,8: (01) Program attempt in region "
-						"with Object Mode data\n");
+		pr_notice("DSR.9,8: (01) Program attempt in region with Object Mode data\n");
+
 	if (!(dsr & DSR_READY_STATUS))
-		printk(KERN_NOTICE"DSR.7: (0) Device is Busy\n");
+		pr_notice("DSR.7: (0) Device is Busy\n");
 	if (dsr & DSR_ESS)
-		printk(KERN_NOTICE"DSR.6: (1) Erase Suspended\n");
+		pr_notice("DSR.6: (1) Erase Suspended\n");
 	if (dsr & DSR_ERASE_STATUS)
-		printk(KERN_NOTICE"DSR.5: (1) Erase/Blank check error\n");
+		pr_notice("DSR.5: (1) Erase/Blank check error\n");
 	if (dsr & DSR_PROGRAM_STATUS)
-		printk(KERN_NOTICE"DSR.4: (1) Program Error\n");
+		pr_notice("DSR.4: (1) Program Error\n");
 	if (dsr & DSR_VPPS)
-		printk(KERN_NOTICE"DSR.3: (1) Vpp low detect, operation "
-					"aborted\n");

include/linux/mtd/pfow.h static inline void print_drs_error(unsigned dsr) · line 154

Quoted 10 lines
include/linux/mtd/pfow.h +3 -3
+		pr_notice("DSR.3: (1) Vpp low detect, operation aborted\n");
 	if (dsr & DSR_PSS)
-		printk(KERN_NOTICE"DSR.2: (1) Program suspended\n");
+		pr_notice("DSR.2: (1) Program suspended\n");
 	if (dsr & DSR_DPS)
-		printk(KERN_NOTICE"DSR.1: (1) Aborted Erase/Program attempt "
-					"on locked block\n");
+		pr_notice("DSR.1: (1) Aborted Erase/Program attempt on locked block\n");
 }
 #endif /* __LINUX_MTD_PFOW_H */

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/