Skip to contentSkip to conversation

nvdimm/btt: add endian conversion in dev_err in btt_log_read

PATCH In review Ben Dooks 3 participants 4 messages Jun 22 – Jun 24

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/1 nvdimm/btt: add endian conversion in dev_err in btt_log_read

The dev_err() call in btt_log_read() is passing a seq value into dev_err() which is a __le32 without any conversion.

Fix the following (prototype) sparse warnings:
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 5 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 6 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq

---
 drivers/nvdimm/btt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvdimm/btt.c +3 -2
index 7e1112960d7f..e9d548442884 100644
@@ -341,8 +341,9 @@ static int btt_log_read(struct arena_info *arena, u32 lane,
 	if (old_ent < 0 || old_ent > 1) {
 		dev_err(to_dev(arena),
 				"log corruption (%d): lane %d seq [%d, %d]\n",
-				old_ent, lane, log.ent[arena->log_index[0]].seq,
-				log.ent[arena->log_index[1]].seq);
+				old_ent, lane,
+				le32_to_cpu(log.ent[arena->log_index[0]].seq),
+				le32_to_cpu(log.ent[arena->log_index[1]].seq));
 		/* TODO set error state? */
 		return -EIO;
 	}
Signature · 1 line
2.37.2.352.g3c44437643
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ben Dooks

The dev_err() call in btt_log_read() is passing a seq value into dev_err() which is a __le32 without any conversion.

Fix the following (prototype) sparse warnings:
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 5 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 6 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq

Quoted 1 line
Quoted 20 lines
---
 drivers/nvdimm/btt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvdimm/btt.c +3 -2
index 7e1112960d7f..e9d548442884 100644
@@ -341,8 +341,9 @@ static int btt_log_read(struct arena_info *arena, u32 lane,
 	if (old_ent < 0 || old_ent > 1) {
 		dev_err(to_dev(arena),
 				"log corruption (%d): lane %d seq [%d, %d]\n",
-				old_ent, lane, log.ent[arena->log_index[0]].seq,
-				log.ent[arena->log_index[1]].seq);
+				old_ent, lane,
+				le32_to_cpu(log.ent[arena->log_index[0]].seq),
+				le32_to_cpu(log.ent[arena->log_index[1]].seq));
 		/* TODO set error state? */
 		return -EIO;
 	}
maintainer
#2 lore raw
In reply to Ben Dooks
Quoted 10 lines · Ben Dooks

The dev_err() call in btt_log_read() is passing a seq value into dev_err() which is a __le32 without any conversion.

Fix the following (prototype) sparse warnings:
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 5 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 6 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq

Hi Ben,

Please revise the commit log.

The commit log is a message to all future readers, not a place to paste static analysis warnings and leave the user visible impact assumed, or as an exercise for the reader.

Prefer something like this:

When BTT log corruption is detected, btt_log_read() reports the sequence numbers of the two log entries. Those values are stored little-endian, so printing them without conversion can report byte-swapped sequence numbers on big-endian systems.

Convert the sequence numbers to CPU endianness before passing them to dev_err().

Issue reported by sparse.

(There is no need for the sparse pastings.)

-- Alison

Quoted 25 lines
---
 drivers/nvdimm/btt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvdimm/btt.c +3 -2
index 7e1112960d7f..e9d548442884 100644
@@ -341,8 +341,9 @@ static int btt_log_read(struct arena_info *arena, u32 lane,
 	if (old_ent < 0 || old_ent > 1) {
 		dev_err(to_dev(arena),
 				"log corruption (%d): lane %d seq [%d, %d]\n",
-				old_ent, lane, log.ent[arena->log_index[0]].seq,
-				log.ent[arena->log_index[1]].seq);
+				old_ent, lane,
+				le32_to_cpu(log.ent[arena->log_index[0]].seq),
+				le32_to_cpu(log.ent[arena->log_index[1]].seq));
 		/* TODO set error state? */
 		return -EIO;
 	}
Signature · 1 line
2.37.2.352.g3c44437643
author
#3 lore raw
Quoted 27 lines · Alison Schofield
Quoted 10 lines · Ben Dooks

The dev_err() call in btt_log_read() is passing a seq value into dev_err() which is a __le32 without any conversion.

Fix the following (prototype) sparse warnings:
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 5 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq
drivers/nvdimm/btt.c:342:17: warning: incorrect type in argument 6 (different base types)
drivers/nvdimm/btt.c:342:17: expected int
drivers/nvdimm/btt.c:342:17: got restricted __le32 [usertype] seq

Hi Ben,

Please revise the commit log.

The commit log is a message to all future readers, not a place to paste static analysis warnings and leave the user visible impact assumed, or as an exercise for the reader.

Prefer something like this:

When BTT log corruption is detected, btt_log_read() reports the sequence numbers of the two log entries. Those values are stored little-endian, so printing them without conversion can report byte-swapped sequence numbers on big-endian systems.

Quoted 7 lines

Convert the sequence numbers to CPU endianness before passing them to dev_err().

Issue reported by sparse.

(There is no need for the sparse pastings.)

Thanks, I've posted a v2, with a reworded patch commit log.

The only comment is that I like the sparse warnings as it makes it easier to search if there is a patch in flight for this.

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html