Skip to contentSkip to conversation

cxl/mbox: Code readability improvement

PATCH In review Quanquan Cao 2 participants 3 messages Jan 30, 2024 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl/mbox: Code readability improvement

"send_cmd->id == 0" indicates an invalid command, so replace 0 to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.

---
 drivers/cxl/core/mbox.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cxl/core/mbox.c +2 -1
index 27166a411705..2e5ee05011d6 100644
@@ -485,7 +485,8 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
 	struct cxl_mem_command mem_cmd;
 	int rc;
 
-	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)
+	if (send_cmd->id == CXL_MEM_COMMAND_ID_INVALID ||
+	    send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)
 		return -ENOTTY;
 
 	/*
Signature · 1 line
2.43.0
#1 lore raw
Quoted 13 lines · Quanquan Cao

"send_cmd->id == 0" indicates an invalid command, so replace 0 to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.

---
 drivers/cxl/core/mbox.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cxl/core/mbox.c +0 -0
index 27166a411705..2e5ee05011d6 100644

drivers/cxl/core/mbox.c static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd, · line 488

Quoted 4 lines
drivers/cxl/core/mbox.c +0 -1
@@ -485,7 +485,8 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
 	struct cxl_mem_command mem_cmd;
 	int rc;
 
-	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)

"non-zero" is readable to me, and less characters to parse means current code is literally easier to read.

#2 lore raw
Quoted 18 lines
Quoted 16 lines · Quanquan Cao

"send_cmd->id == 0" indicates an invalid command, so replace 0 to CXL_MEM_COMMAND_ID_INVALID to make it easy for reading/understanding.

---
  drivers/cxl/core/mbox.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cxl/core/mbox.c +0 -0
index 27166a411705..2e5ee05011d6 100644
@@ -485,7 +485,8 @@ static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd,
  	struct cxl_mem_command mem_cmd;
  	int rc;
 
Quoted 4 lines

drivers/cxl/core/mbox.c static int cxl_validate_cmd_from_user(struct cxl_mbox_cmd *mbox_cmd, · line 488

Quoted 1 line
drivers/cxl/core/mbox.c +0 -1
-	if (send_cmd->id == 0 || send_cmd->id >= CXL_MEM_COMMAND_ID_MAX)

"non-zero" is readable to me, and less characters to parse means current code is literally easier to read.

Thanks, I got.